/* ============================================================
   Uppal CMS — Brand Layer + Accessibility + Animations
   Loaded AFTER Tailwind Play CDN so utilities compose freely.
   ============================================================ */

/* ---------- Brand Tokens ---------- */
:root {
  --uppal-primary:   #162040;
  --uppal-secondary: #0d1733;
  --uppal-accent:    #EFEFEF;
  --uppal-gold:      #B8923A;
  --uppal-danger:    #B91C1C;
  --uppal-success:   #15803D;
  --uppal-warning:   #B45309;
  --font-base: 18px;
  --font-scale: 1;
  --touch-min: 48px;
}

/* ---------- Font-Size Scaling ---------- */
html[data-font="sm"]   { --font-scale: 0.9;  --font-base: 16px; }
html[data-font="base"] { --font-scale: 1;    --font-base: 18px; }
html[data-font="lg"]   { --font-scale: 1.1;  --font-base: 20px; }
html[data-font="xl"]   { --font-scale: 1.25; --font-base: 22px; }

html, body {
  font-family: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  font-size: var(--font-base);
  line-height: 1.6;
  background: linear-gradient(180deg, #fafbfc 0%, #f1f4f8 100%);
  color: #1f2937;
}

/* ---------- High Contrast Mode ---------- */
html.high-contrast {
  --uppal-primary: #000;
  --uppal-secondary: #000d1a;
  --uppal-gold: #c98f00;
  --uppal-danger: #cc0000;
  --uppal-success: #006622;
}
html.high-contrast body {
  background: #fff !important;
  color: #000 !important;
}
html.high-contrast .uppal-card {
  border: 2px solid #000 !important;
  box-shadow: none !important;
}
html.high-contrast .uppal-bg-hero {
  background: #000 !important;
}
html.high-contrast .nav-link {
  color: #fff !important;
  border: 1px solid rgba(255,255,255,0.3);
  margin-bottom: 2px;
}
html.high-contrast .nav-link.active {
  background: #c98f00 !important;
  color: #000 !important;
}
html.high-contrast .uppal-input {
  border: 2px solid #000 !important;
}
html.high-contrast .uppal-btn {
  border: 2px solid #000 !important;
}
html.high-contrast .text-slate-300,
html.high-contrast .text-slate-400,
html.high-contrast .text-slate-500 {
  color: #333 !important;
}

/* ---------- Preloader ---------- */
#uppal-preloader {
  position: fixed; inset: 0; z-index: 99999;
  background:
    radial-gradient(900px 500px at 50% 20%, rgba(184,146,58,0.18), transparent 60%),
    linear-gradient(135deg, #0d1733 0%, #162040 100%);
  display: flex; align-items: center; justify-content: center;
  opacity: 1; transition: opacity .55s ease, visibility .55s ease;
}
#uppal-preloader.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.uppal-preloader-inner {
  text-align: center; color: white;
  animation: fadeIn .5s ease;
}
.uppal-preloader-logo {
  width: 96px; height: 96px;
  background: white; padding: 10px; border-radius: 18px;
  object-fit: contain;
  box-shadow: 0 0 0 1px rgba(184,146,58,0.4), 0 12px 40px rgba(0,0,0,0.35);
  animation: floaty 2.4s ease-in-out infinite, glow 2.8s ease-in-out infinite;
}
.uppal-preloader-spinner {
  width: 56px; height: 56px; margin: 22px auto 0;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--uppal-gold);
  border-radius: 50%;
  animation: spinSlow 1s linear infinite;
}
.uppal-preloader-text {
  margin-top: 18px;
  letter-spacing: .35em; font-weight: 600; font-size: 13px;
  color: rgba(255,255,255,0.85);
}
@keyframes spinSlow { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .uppal-preloader-logo, .uppal-preloader-spinner { animation: none; }
}

/* ---------- Logo ---------- */
.uppal-logo {
  display: block;
  object-fit: contain;
  background: white;
  padding: 4px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(4,44,75,0.15), 0 0 0 1px rgba(184,146,58,0.25);
}
.uppal-logo-sm { width: 48px;  height: 48px; padding: 5px; }
.uppal-logo-md { width: 68px;  height: 68px; padding: 8px; border-radius: 14px; }
.uppal-logo-lg { width: 110px; height: 110px; padding: 10px; border-radius: 18px; }

/* ---------- Hero ---------- */
.uppal-bg-hero {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.04'/%3E%3C/svg%3E"),
    radial-gradient(1200px 600px at 85% -10%, rgba(184,146,58,0.14), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(22,32,64,0.25), transparent 60%),
    radial-gradient(600px 400px at 50% 50%, rgba(30,40,90,0.15), transparent 70%),
    linear-gradient(135deg, #162040 0%, #0d1733 40%, #111b3d 100%);
}

/* ---------- Cards ---------- */
.uppal-card {
  background: white;
  border: 1px solid rgba(37,56,69,0.08);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(4,44,75,0.04), 0 8px 24px -12px rgba(4,44,75,0.12);
  transition: transform .25s ease, box-shadow .25s ease;
}
.uppal-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(4,44,75,0.06), 0 20px 40px -16px rgba(4,44,75,0.2);
}

/* ---------- Buttons (min 48px touch) ---------- */
.uppal-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .5rem; font-weight: 600; letter-spacing: .01em;
  padding: .75rem 1.5rem; border-radius: 10px;
  font-size: calc(1rem * var(--font-scale));
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  transition: all .2s ease; position: relative; overflow: hidden;
  cursor: pointer; text-decoration: none;
}
.uppal-btn-primary { background: var(--uppal-primary); color: white; }
.uppal-btn-primary:hover { background: var(--uppal-secondary); transform: translateY(-1px); }
.uppal-btn-gold { background: var(--uppal-gold); color: white; }
.uppal-btn-gold:hover { filter: brightness(1.08); transform: translateY(-1px); }
.uppal-btn-ghost { background: transparent; color: var(--uppal-primary); border: 1px solid rgba(37,56,69,0.2); }
.uppal-btn-ghost:hover { background: rgba(37,56,69,0.06); }
.uppal-btn-danger { background: var(--uppal-danger); color: white; }
.uppal-btn-danger:hover { filter: brightness(1.1); transform: translateY(-1px); }
.uppal-btn-success { background: var(--uppal-success); color: white; }
.uppal-btn-success:hover { filter: brightness(1.1); transform: translateY(-1px); }
.uppal-btn-lg {
  padding: 1rem 2rem;
  font-size: calc(1.125rem * var(--font-scale));
  min-height: 56px;
  border-radius: 12px;
}

.uppal-btn::after {
  content:""; position:absolute; inset:0;
  background: radial-gradient(circle at var(--x,50%) var(--y,50%), rgba(255,255,255,.35), transparent 40%);
  opacity:0; transition: opacity .4s ease; pointer-events:none;
}
.uppal-btn:active::after { opacity: 1; transition: none; }
.uppal-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ---------- Inputs (min 48px touch) ---------- */
.uppal-input {
  width: 100%; padding: .75rem 1rem; border-radius: 10px;
  border: 1px solid #d5dbe2; background: white;
  font-size: calc(1rem * var(--font-scale));
  min-height: var(--touch-min);
  transition: border-color .2s, box-shadow .2s;
}
.uppal-input:focus {
  outline: none; border-color: var(--uppal-secondary);
  box-shadow: 0 0 0 4px rgba(4,44,75,0.12);
}

.uppal-chip {
  display:inline-flex; align-items:center; gap:.35rem; padding:.3rem .7rem;
  border-radius:999px; font-size:.8rem; background:#eef2f7; color:#1f2937;
}

/* ---------- 3-Step Status Tracker ---------- */
.tracker-3step {
  display: flex; align-items: center; gap: 0;
  width: 100%; max-width: 400px;
}
.tracker-step {
  flex: 1; text-align: center; position: relative;
  padding: .5rem 0;
}
.tracker-step-dot {
  width: 32px; height: 32px; border-radius: 50%;
  background: #e2e8f0; color: #94a3b8;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
  transition: all .3s ease;
}
.tracker-step.active .tracker-step-dot {
  background: var(--uppal-gold);
  color: white;
  box-shadow: 0 0 0 4px rgba(184,146,58,0.2);
}
.tracker-step.done .tracker-step-dot {
  background: var(--uppal-success);
  color: white;
}
.tracker-step-label {
  display: block; font-size: .75rem; margin-top: .3rem;
  color: #94a3b8; font-weight: 500;
}
.tracker-step.active .tracker-step-label,
.tracker-step.done .tracker-step-label {
  color: #1f2937; font-weight: 600;
}
.tracker-line {
  flex: 0 0 40px; height: 3px; background: #e2e8f0;
  position: relative; top: -8px;
}
.tracker-line.done { background: var(--uppal-success); }

/* ---------- Status Stamps ---------- */
.status-stamp {
  display: inline-block; padding: .4rem 1rem;
  border-radius: 8px; font-weight: 700;
  font-size: calc(1rem * var(--font-scale));
  letter-spacing: .05em; text-transform: uppercase;
}
.status-stamp-open { background: #fef3c7; color: #92400e; border: 2px solid #f59e0b; }
.status-stamp-working { background: #dbeafe; color: #1e40af; border: 2px solid #3b82f6; }
.status-stamp-done { background: #d1fae5; color: #065f46; border: 2px solid #10b981; }

/* ---------- Star Rating ---------- */
.star-rating { display: inline-flex; gap: 4px; }
.star-rating-btn {
  background: none; border: none; cursor: pointer;
  padding: 4px; min-width: var(--touch-min); min-height: var(--touch-min);
  display: inline-flex; align-items: center; justify-content: center;
}
.star-rating-btn svg { width: 28px; height: 28px; }
.star-rating-btn .star-empty { color: #d1d5db; }
.star-rating-btn .star-filled { color: var(--uppal-gold); }
.star-rating-btn:hover .star-empty { color: var(--uppal-gold); opacity: 0.5; }

/* ---------- Signature Canvas ---------- */
.signature-pad {
  border: 2px dashed #d1d5db; border-radius: 12px;
  background: #fafbfc; cursor: crosshair;
  touch-action: none;
}
.signature-pad.signing { border-color: var(--uppal-gold); }

/* ---------- Emergency Banner ---------- */
.emergency-banner {
  background: linear-gradient(90deg, #B91C1C, #7f1d1d);
  color: white; border-left: 4px solid #fde68a;
  animation: pulseSoft 2s ease-in-out infinite;
  padding: .75rem 1rem; border-radius: 10px;
  font-size: calc(1rem * var(--font-scale));
}

/* ---------- Urgent Dashboard ---------- */
.urgent-theme {
  background: linear-gradient(135deg, #1c0a0a 0%, #2d0a0a 50%, #1a0505 100%) !important;
}
.urgent-card {
  background: rgba(185,28,28,0.1);
  border: 1px solid rgba(185,28,28,0.3);
  border-radius: 14px;
}

/* ---------- SLA Timer ---------- */
.sla-ok { color: var(--uppal-success); }
.sla-warn { color: var(--uppal-warning); }
.sla-breach { color: var(--uppal-danger); font-weight: 700; }

/* ---------- Sidebar Nav ---------- */
.nav-link {
  display:flex; align-items:center; gap:.8rem;
  padding:.8rem 1rem; border-radius:10px; color:#cbd5e1; font-weight:500;
  transition: background .2s, color .2s, transform .2s;
  min-height: var(--touch-min);
  font-size: calc(1rem * var(--font-scale));
  text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: white; transform: translateX(2px); }
.nav-link.active { background: rgba(184,146,58,0.18); color: #fde7b3; }
.nav-divider { height: 1px; background: rgba(255,255,255,0.08); margin: .5rem 0; }
.nav-section-title {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .12em;
  color: rgba(255,255,255,0.4); padding: .6rem 1rem; margin-top: .6rem;
}

/* ---------- Mobile Sidebar ---------- */
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 40; display: none;
}
.sidebar-overlay.open { display: block; }
@media (max-width: 767px) {
  .sidebar-desktop { display: none !important; }
  .sidebar-mobile {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: 280px; z-index: 50;
    transform: translateX(-100%);
    transition: transform .3s ease;
  }
  .sidebar-mobile.open { transform: translateX(0); }
}
@media (min-width: 768px) {
  .sidebar-mobile { display: none !important; }
  .sidebar-overlay { display: none !important; }
  .mobile-menu-btn { display: none !important; }
}
.mobile-menu-btn {
  position: fixed; top: 12px; left: 12px; z-index: 35;
  width: var(--touch-min); height: var(--touch-min);
  border-radius: 10px; background: var(--uppal-primary); color: white;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ---------- Offline Indicator ---------- */
.offline-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: #92400e; color: white; text-align: center;
  padding: .4rem; font-size: .85rem; font-weight: 600;
  display: none;
}
.offline-bar.show { display: block; }

/* ---------- A11y Toolbar ---------- */
#a11y-toolbar {
  position: fixed; top: 12px; right: 12px; z-index: 100;
  display: flex; gap: 4px;
  background: rgba(37,56,69,0.9); backdrop-filter: blur(8px);
  padding: 4px 8px; border-radius: 10px;
}
#a11y-toolbar button {
  min-width: 40px; min-height: 40px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15); background: transparent;
  color: white; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
  transition: background .2s;
}
#a11y-toolbar button:hover { background: rgba(255,255,255,0.15); }
#a11y-toolbar button.active { background: var(--uppal-gold); color: #000; }

/* ---------- Tabs ---------- */
.tab-bar {
  display: flex; gap: 2px; background: #e2e8f0; border-radius: 10px; padding: 3px;
}
.tab-btn {
  flex: 1; padding: .6rem .8rem; border-radius: 8px; text-align: center;
  font-weight: 600; font-size: calc(.85rem * var(--font-scale));
  color: #64748b; background: transparent;
  cursor: pointer; border: none; min-height: var(--touch-min);
  transition: all .2s ease;
}
.tab-btn.active { background: white; color: var(--uppal-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity:0; transform: translateY(6px);} to { opacity:1; transform:none;} }
@keyframes slideUp { from { opacity:0; transform: translateY(16px);} to { opacity:1; transform:none;} }
@keyframes slideDown { from { opacity:0; transform: translateY(-10px);} to { opacity:1; transform:none;} }
@keyframes fadeOut { to { opacity:0; transform: translateY(-6px);} }
@keyframes pulseSoft { 0%,100% { box-shadow: 0 0 0 0 rgba(185,28,28,0.6); } 50% { box-shadow: 0 0 0 8px rgba(185,28,28,0); } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
@keyframes spinSlow { to { transform: rotate(360deg); } }
@keyframes scaleIn { from { opacity:0; transform: scale(.96);} to { opacity:1; transform: scale(1);} }
@keyframes drawBar { from { width: 0; } }
@keyframes glow { 0%,100% { filter: drop-shadow(0 0 2px rgba(184,146,58,.5)); } 50% { filter: drop-shadow(0 0 12px rgba(184,146,58,.9)); } }

.animate-fade-in    { animation: fadeIn .45s ease both; }
.animate-slide-up   { animation: slideUp .5s cubic-bezier(.2,.7,.2,1) both; }
.animate-slide-down { animation: slideDown .35s ease both; }
.animate-fade-out   { animation: fadeOut .35s ease forwards; }
.animate-pulse-soft { animation: pulseSoft 1.6s ease-in-out infinite; }
.animate-floaty     { animation: floaty 4s ease-in-out infinite; }
.animate-spin-slow  { animation: spinSlow 6s linear infinite; }
.animate-scale-in   { animation: scaleIn .35s cubic-bezier(.2,.7,.2,1) both; }
.animate-glow       { animation: glow 2.4s ease-in-out infinite; }

.shimmer {
  background: linear-gradient(90deg, #eef2f7 0%, #f7f9fc 50%, #eef2f7 100%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}

.stagger > * { opacity: 0; animation: slideUp .5s ease forwards; }
.stagger > *:nth-child(1){ animation-delay: .05s; }
.stagger > *:nth-child(2){ animation-delay: .10s; }
.stagger > *:nth-child(3){ animation-delay: .15s; }
.stagger > *:nth-child(4){ animation-delay: .20s; }
.stagger > *:nth-child(5){ animation-delay: .25s; }
.stagger > *:nth-child(6){ animation-delay: .30s; }
.stagger > *:nth-child(7){ animation-delay: .35s; }
.stagger > *:nth-child(8){ animation-delay: .40s; }

/* ---------- Skeleton ---------- */
.skel { height: 12px; border-radius: 6px; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width:10px; height:10px; }
::-webkit-scrollbar-thumb { background: #c5cdd6; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #9aa5b1; }

/* ---------- Print Styles ---------- */
@media print {
  body { background: white !important; color: black !important; font-size: 12pt !important; }
  .uppal-card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .no-print, #a11y-toolbar, .sidebar-desktop, .sidebar-mobile, .sidebar-overlay,
  .mobile-menu-btn, .uppal-btn, nav, aside, .nav-link { display: none !important; }
  .print-only { display: block !important; }
  .tracker-step-dot { border: 2px solid #333 !important; }
  @page { margin: 1.5cm; }
}
.print-only { display: none; }

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Heatmap Cell ---------- */
.heatmap-cell {
  border-radius: 6px; padding: .3rem .5rem; text-align: center;
  font-size: .8rem; font-weight: 600; min-width: 40px;
}
.heatmap-0 { background: #f1f5f9; color: #94a3b8; }
.heatmap-1 { background: #fef9c3; color: #854d0e; }
.heatmap-2 { background: #fed7aa; color: #9a3412; }
.heatmap-3 { background: #fca5a5; color: #991b1b; }
.heatmap-4 { background: #ef4444; color: white; }

/* ---------- Keyboard Shortcut Hint ---------- */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 4px; border: 1px solid #d1d5db;
  background: #f9fafb; font-size: .7rem; font-weight: 600;
  font-family: monospace; color: #6b7280;
}
