/* ============================================================
   Sourcing Trip — Team Tracker  ·  Design System
   Mobile-first PWA · dark + light theme · pure CSS animations
   ============================================================ */

:root {
  --font: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Brand */
  --brand: #0d9488;
  --brand-strong: #0f766e;
  --brand-soft: #ccfbf1;
  --brand-ink: #115e59;

  /* Light theme surfaces */
  --bg: #f5f7fb;
  --bg-grad-1: #eef4f3;
  --bg-grad-2: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e6eaf0;
  --border-strong: #d3dae4;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px -12px rgba(16,24,40,.18);
  --shadow-lg: 0 24px 60px -20px rgba(16,24,40,.35);
  --ring: rgba(13,148,136,.35);
}

html.dark {
  --bg: #0b1220;
  --bg-grad-1: #0c1526;
  --bg-grad-2: #0a0f1c;
  --surface: #111a2b;
  --surface-2: #16223a;
  --surface-3: #1c2a45;
  --border: #23324e;
  --border-strong: #30425f;
  --ink: #eef2f8;
  --ink-2: #a8b6cc;
  --ink-3: #6b7c98;
  --brand-soft: #0c3b37;
  --brand-ink: #5eead4;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 30px -14px rgba(0,0,0,.7);
  --shadow-lg: 0 30px 70px -20px rgba(0,0,0,.75);
  --ring: rgba(45,212,191,.4);
}

* { -webkit-tap-highlight-color: transparent; }

html, body { background: var(--bg); }

body {
  font-family: var(--font);
  color: var(--ink);
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 15% -10%, var(--bg-grad-1), transparent 55%),
    radial-gradient(1000px 600px at 110% 0%, var(--bg-grad-1), transparent 45%),
    var(--bg-grad-2);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

/* Respect iOS safe areas */
.safe-top { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

/* ---------------- Surfaces ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.card-hover:active { transform: translateY(0); }

.surface-2 { background: var(--surface-2); }
.surface-3 { background: var(--surface-3); }
.bordered { border: 1px solid var(--border); }
.hairline { border-color: var(--border) !important; }

.muted  { color: var(--ink-2); }
.muted2 { color: var(--ink-3); }

/* Glass header */
.glass {
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

/* ---------------- Badges & chips ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .01em;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.chip {
  display:inline-flex; align-items:center; gap:6px;
  font-size:12px; font-weight:600; padding:6px 12px; border-radius:999px;
  border:1px solid var(--border); background:var(--surface-2); color:var(--ink-2);
  transition: all .15s ease; cursor:pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--ink); }
.chip.active { background: var(--brand); border-color: var(--brand); color:#fff; box-shadow: 0 6px 16px -6px var(--ring); }

/* status/phase palettes that work on both themes via translucency */
.tone-slate  { background: color-mix(in srgb, #94a3b8 16%, transparent); color:#64748b; }
.tone-blue   { background: color-mix(in srgb, #3b82f6 18%, transparent); color:#3b82f6; }
.tone-cyan   { background: color-mix(in srgb, #06b6d4 18%, transparent); color:#0891b2; }
.tone-violet { background: color-mix(in srgb, #8b5cf6 18%, transparent); color:#8b5cf6; }
.tone-amber  { background: color-mix(in srgb, #f59e0b 20%, transparent); color:#d97706; }
.tone-orange { background: color-mix(in srgb, #f97316 20%, transparent); color:#ea580c; }
.tone-emerald{ background: color-mix(in srgb, #10b981 18%, transparent); color:#059669; }
.tone-red    { background: color-mix(in srgb, #ef4444 18%, transparent); color:#ef4444; }
.tone-teal   { background: color-mix(in srgb, #14b8a6 18%, transparent); color:#0d9488; }
.tone-sky    { background: color-mix(in srgb, #0ea5e9 18%, transparent); color:#0284c7; }
.tone-rose   { background: color-mix(in srgb, #f43f5e 18%, transparent); color:#e11d48; }
html.dark .tone-slate  { color:#cbd5e1; }
html.dark .tone-blue   { color:#93c5fd; }
html.dark .tone-cyan   { color:#67e8f9; }
html.dark .tone-violet { color:#c4b5fd; }
html.dark .tone-amber  { color:#fcd34d; }
html.dark .tone-orange { color:#fdba74; }
html.dark .tone-emerald{ color:#6ee7b7; }
html.dark .tone-red    { color:#fca5a5; }
html.dark .tone-teal   { color:#5eead4; }
html.dark .tone-sky    { color:#7dd3fc; }
html.dark .tone-rose   { color:#fda4af; }

/* ---------------- Buttons ---------------- */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  font-weight:700; font-size:14px; border-radius:14px; padding:11px 18px;
  border:1px solid transparent; cursor:pointer; transition: all .16s ease;
  line-height:1;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(180deg, var(--brand), var(--brand-strong)); color:#fff; box-shadow: 0 10px 22px -10px var(--ring); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--border-strong); }
.btn-danger { background: color-mix(in srgb,#ef4444 14%, transparent); color:#ef4444; border-color: color-mix(in srgb,#ef4444 34%, transparent); }
.btn-danger:hover { background: color-mix(in srgb,#ef4444 22%, transparent); }
.icon-btn {
  width:40px; height:40px; border-radius:999px; display:inline-flex; align-items:center; justify-content:center;
  background: var(--surface-2); color: var(--ink-2); border:1px solid var(--border); transition: all .15s ease; cursor:pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); transform: translateY(-1px); }

/* ---------------- Inputs ---------------- */
.field {
  width:100%; background: var(--surface-2); color: var(--ink);
  border:1px solid var(--border); border-radius:12px; padding:11px 13px; font-size:14px;
  transition: border-color .15s ease, box-shadow .15s ease; font-family: var(--font);
}
.field::placeholder { color: var(--ink-3); }
.field:focus { outline:none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); background: var(--surface); }
select.field { appearance:none; -webkit-appearance:none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position: right 12px center; padding-right: 34px; }
.lbl { display:block; font-size:11px; font-weight:800; letter-spacing:.06em; text-transform:uppercase; color: var(--ink-3); margin-bottom:6px; }

/* ---------------- Nav ---------------- */
.tab {
  position:relative; padding:14px 4px; font-size:13.5px; font-weight:600; white-space:nowrap;
  color: var(--ink-3); transition: color .15s ease; background:none; border:none; cursor:pointer;
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--brand); }
.tab.active::after {
  content:''; position:absolute; left:0; right:0; bottom:-1px; height:3px; border-radius:3px 3px 0 0;
  background: linear-gradient(90deg, var(--brand), #22d3ee);
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: scaleX(.2); opacity:0; } to { transform: scaleX(1); opacity:1; } }

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; bottom: 0; left:0; right:0; z-index: 45;
  display:flex; justify-content:space-around; align-items:stretch;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bn-item {
  flex:1; display:flex; flex-direction:column; align-items:center; gap:3px;
  padding:9px 2px 8px; font-size:10px; font-weight:600; color: var(--ink-3);
  background:none; border:none; cursor:pointer; transition: color .15s ease; position:relative;
}
.bn-item i { font-size:17px; transition: transform .18s ease; }
.bn-item.active { color: var(--brand); }
.bn-item.active i { transform: translateY(-2px); }
.bn-item.active::before {
  content:''; position:absolute; top:2px; width:26px; height:3px; border-radius:3px;
  background: linear-gradient(90deg, var(--brand), #22d3ee);
}

/* ---------------- Avatars ---------------- */
.av {
  display:inline-flex; align-items:center; justify-content:center; flex-shrink:0;
  border-radius:999px; color:#fff; font-weight:800; letter-spacing:.02em;
  background: linear-gradient(135deg, var(--a1,#0d9488), var(--a2,#0f766e));
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.14);
}

/* ---------------- Progress rings & bars ---------------- */
.ring {
  --p: 0; --sz: 62px;
  width: var(--sz); height: var(--sz); border-radius:50%; display:grid; place-items:center; flex-shrink:0;
  background:
    radial-gradient(closest-side, var(--surface) 73%, transparent 74% 100%),
    conic-gradient(var(--brand) calc(var(--p)*1%), var(--surface-3) 0);
  transition: background .5s ease;
}
.ring.rc { background:
    radial-gradient(closest-side, var(--surface) 73%, transparent 74% 100%),
    conic-gradient(#22d3ee calc(var(--p)*1%), var(--surface-3) 0); }
.ring.ra { background:
    radial-gradient(closest-side, var(--surface) 73%, transparent 74% 100%),
    conic-gradient(#8b5cf6 calc(var(--p)*1%), var(--surface-3) 0); }

.bar { height:8px; border-radius:999px; background: var(--surface-3); overflow:hidden; }
.bar > i { display:block; height:100%; border-radius:999px; background: linear-gradient(90deg, var(--brand), #22d3ee);
  transform-origin:left; animation: growBar .7s cubic-bezier(.2,.8,.2,1) both; }
@keyframes growBar { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------------- Phase timeline ---------------- */
.phase-card { position:relative; overflow:hidden; }
.phase-card::before {
  content:''; position:absolute; inset:0 auto 0 0; width:5px;
  background: var(--pc, var(--brand));
}
.phase-dot { width:14px; height:14px; border-radius:999px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc,#0d9488) 22%, transparent); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--surface);
  padding: 11px 18px; border-radius: 14px; font-size: 13.5px; font-weight:600;
  box-shadow: var(--shadow-lg); z-index: 200; opacity:0; pointer-events:none;
  transition: opacity .25s ease, transform .25s ease; max-width: 90vw;
}
html.dark .toast { background:#e6edf7; color:#0b1220; }
.toast.show { opacity:1; transform: translateX(-50%) translateY(0); }
@media (min-width: 640px){ .toast { bottom: 28px; } }

/* ---------------- Modal ---------------- */
.modal-scrim {
  position: fixed; inset:0; z-index:120; display:flex; justify-content:center;
  align-items:flex-end; background: rgba(6,10,20,.5); backdrop-filter: blur(4px);
  animation: fadeScrim .2s ease; padding: 0;
}
@media (min-width:640px){ .modal-scrim { align-items:center; padding:20px; } }
@keyframes fadeScrim { from { opacity:0; } to { opacity:1; } }
.modal {
  width:100%; max-width: 560px; max-height: 92dvh; overflow-y:auto;
  background: var(--surface); border:1px solid var(--border);
  border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  animation: sheetUp .3s cubic-bezier(.2,.9,.2,1);
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
}
@media (min-width:640px){ .modal { border-radius:24px; animation: popIn .24s cubic-bezier(.2,.9,.2,1); } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0);} }
@keyframes popIn { from { transform: scale(.94); opacity:0;} to { transform: scale(1); opacity:1;} }
.modal-grab { width:40px; height:5px; border-radius:999px; background: var(--border-strong); margin:0 auto 14px; }
@media (min-width:640px){ .modal-grab { display:none; } }

/* ---------------- Animations ---------------- */
.fade-in { animation: fadeIn .3s ease both; }
@keyframes fadeIn { from { opacity:0; transform: translateY(8px);} to { opacity:1; transform:none;} }
.stagger > * { animation: fadeIn .4s ease both; }
.stagger > *:nth-child(1){animation-delay:.02s}
.stagger > *:nth-child(2){animation-delay:.06s}
.stagger > *:nth-child(3){animation-delay:.10s}
.stagger > *:nth-child(4){animation-delay:.14s}
.stagger > *:nth-child(5){animation-delay:.18s}
.stagger > *:nth-child(6){animation-delay:.22s}
.stagger > *:nth-child(7){animation-delay:.26s}
.stagger > *:nth-child(8){animation-delay:.30s}

.pop { animation: popIn .25s cubic-bezier(.2,.9,.2,1) both; }
.count-up { animation: countUp .5s ease both; }
@keyframes countUp { from { opacity:0; transform: translateY(6px) scale(.96);} to { opacity:1; transform:none;} }

.pulse-dot { animation: pulseDot 1.6s ease-in-out infinite; }
@keyframes pulseDot { 0%,100%{ opacity:1; transform:scale(1);} 50%{ opacity:.3; transform:scale(.6);} }

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg);} }

.shimmer {
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius:12px;
}
@keyframes shimmer { from { background-position: 200% 0;} to { background-position: -200% 0;} }

.float-btn { animation: floatUp .4s cubic-bezier(.2,.9,.2,1) both; }
@keyframes floatUp { from { transform: translateY(20px) scale(.8); opacity:0;} to { transform:none; opacity:1;} }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.001ms !important; transition-duration:.001ms !important; }
}

/* ---------------- Misc ---------------- */
a { color: inherit; }
.link { color: var(--brand); font-weight:600; }
.link:hover { text-decoration: underline; }
.divider { border-top:1px solid var(--border); }
.no-scrollbar::-webkit-scrollbar { display:none; }
.no-scrollbar { -ms-overflow-style:none; scrollbar-width:none; }
::-webkit-scrollbar { width:9px; height:9px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius:9px; }
::-webkit-scrollbar-track { background: transparent; }

.stars { color:#f59e0b; letter-spacing:1px; }
.stars .off { color: var(--surface-3); }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 44;
  width: 58px; height: 58px; border-radius: 20px; border:none; cursor:pointer;
  background: linear-gradient(160deg, var(--brand), var(--brand-strong)); color:#fff;
  font-size: 22px; box-shadow: 0 16px 32px -10px var(--ring), 0 4px 10px rgba(0,0,0,.2);
  display:flex; align-items:center; justify-content:center; transition: transform .18s ease;
}
.fab:hover { transform: translateY(-3px) rotate(90deg); }
.fab:active { transform: scale(.92); }
@media (min-width:640px){ .fab { bottom: 26px; right: 26px; } }

/* content bottom padding so bottom-nav / fab never cover content */
.app-main { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
@media (min-width:640px){ .app-main { padding-bottom: 40px; } }
