@layer reset, tokens, base, layout, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { min-height: 100dvh; }
  svg { display: block; }
  a { color: inherit; text-decoration: none; }
  input { font: inherit; color: inherit; }
}

@layer tokens {
  :root {
    color-scheme: dark light;
    --bg: light-dark(oklch(0.985 0.004 260), oklch(0.16 0.012 265));
    --bg-2: light-dark(oklch(0.96 0.01 260), oklch(0.19 0.016 268));
    --surface: light-dark(oklch(1 0 0 / 0.75), oklch(0.23 0.018 268 / 0.62));
    --surface-hi: light-dark(oklch(1 0 0), oklch(0.27 0.02 268 / 0.8));
    --line: light-dark(oklch(0.2 0.02 265 / 0.09), oklch(1 0 0 / 0.08));
    --text: light-dark(oklch(0.22 0.02 265), oklch(0.96 0.006 265));
    --muted: light-dark(oklch(0.5 0.02 265), oklch(0.72 0.02 265));
    --dim: light-dark(oklch(0.6 0.015 265), oklch(0.58 0.02 265));
    --accent: oklch(0.72 0.17 255);
    --accent-2: oklch(0.68 0.21 295);
    --ok: oklch(0.78 0.17 155);
    --warn: oklch(0.82 0.15 80);
    --bad: oklch(0.68 0.2 25);
    --radius: 18px;
    --shadow: 0 1px 0 oklch(1 0 0 / 0.04) inset, 0 20px 40px -24px oklch(0 0 0 / 0.5);
    --font: "Inter var", "InterVariable", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  }
}

@layer base {
  body {
    font-family: var(--font);
    font-feature-settings: "cv11", "ss01", "tnum";
    background:
      radial-gradient(60rem 40rem at 10% -10%, oklch(0.55 0.2 270 / 0.22), transparent 60%),
      radial-gradient(50rem 30rem at 100% 0%, oklch(0.6 0.16 210 / 0.16), transparent 60%),
      var(--bg);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
  }
  ::selection { background: oklch(0.7 0.17 260 / 0.35); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
  .muted { color: var(--muted); }
  .mono { font-family: var(--mono); font-size: 0.86em; }
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: 180ms; }
}

@layer layout {
  .topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
    padding-top: max(0.9rem, env(safe-area-inset-top));
    backdrop-filter: blur(18px) saturate(1.4);
    background: color-mix(in oklch, var(--bg) 70%, transparent);
    border-bottom: 1px solid var(--line);
  }
  .wrap {
    width: min(1280px, 100%);
    margin-inline: auto;
    padding: clamp(1rem, 3vw, 2.25rem) clamp(1rem, 4vw, 2.5rem) 1rem;
    display: grid; gap: clamp(1rem, 2vw, 1.5rem);
  }
  #fleet { display: grid; gap: clamp(1rem, 2vw, 1.5rem); }
  .foot {
    width: min(1280px, 100%); margin: 0 auto;
    padding: 0.5rem clamp(1rem, 4vw, 2.5rem) max(2rem, env(safe-area-inset-bottom));
    color: var(--dim); font-size: 0.78rem;
  }
}

@layer components {
  .brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 650; letter-spacing: -0.01em; font-size: 1.05rem; }
  .logo { width: 30px; height: 30px; filter: drop-shadow(0 6px 14px oklch(0.6 0.2 270 / 0.45)); }
  .chip {
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
    padding: 0.2rem 0.5rem; border-radius: 999px; color: var(--muted);
    border: 1px solid var(--line); background: var(--surface);
  }
  .top-right { display: flex; align-items: center; gap: 0.75rem; }
  .live { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .pulse {
    width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
    box-shadow: 0 0 0 0 oklch(0.78 0.17 155 / 0.6);
    animation: pulse 2.4s infinite;
  }
  @keyframes pulse { 70% { box-shadow: 0 0 0 8px oklch(0.78 0.17 155 / 0); } 100% { box-shadow: 0 0 0 0 oklch(0.78 0.17 155 / 0); } }
  .user {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
    font-weight: 650; font-size: 0.85rem; color: white;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
  }
  .ghost-btn {
    font-size: 0.82rem; padding: 0.45rem 0.8rem; border-radius: 10px;
    border: 1px solid var(--line); background: var(--surface); color: var(--muted);
    transition: color 0.15s, background 0.15s;
  }
  .ghost-btn:hover { color: var(--text); background: var(--surface-hi); }

  /* metrics */
  .metrics { display: grid; gap: clamp(0.75rem, 1.5vw, 1rem); grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric {
    position: relative; overflow: hidden;
    display: grid; gap: 0.35rem; align-content: start;
    padding: clamp(1rem, 2vw, 1.4rem);
    border-radius: var(--radius); border: 1px solid var(--line);
    background: var(--surface); box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    transition: transform 0.25s cubic-bezier(.2,.8,.2,1), border-color 0.25s;
  }
  .metric:hover { transform: translateY(-2px); border-color: oklch(0.72 0.17 255 / 0.35); }
  .metric .label { font-size: 0.76rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
  .metric .value { font-size: clamp(1.7rem, 3vw, 2.3rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.1; font-variant-numeric: tabular-nums; }
  .metric .value small { font-size: 0.5em; font-weight: 600; color: var(--muted); letter-spacing: 0; }
  .metric .sub { font-size: 0.8rem; color: var(--dim); }
  .metric.hero {
    background:
      radial-gradient(120% 140% at 0% 0%, oklch(0.62 0.2 265 / 0.55), transparent 60%),
      radial-gradient(120% 140% at 100% 100%, oklch(0.6 0.2 300 / 0.45), transparent 55%),
      oklch(0.28 0.06 275);
    border-color: oklch(0.75 0.15 270 / 0.35);
    color: white;
  }
  .metric.hero .label, .metric.hero .sub { color: oklch(0.92 0.03 270 / 0.82); }
  .metric.hero .value { font-size: clamp(2rem, 3.6vw, 2.8rem); }
  .metric.hero::after {
    content: ""; position: absolute; inset: -40% -10% auto auto; width: 60%; aspect-ratio: 1;
    background: conic-gradient(from 180deg, transparent, oklch(1 0 0 / 0.12), transparent 40%);
    border-radius: 50%; animation: spin 14s linear infinite; pointer-events: none;
  }
  @keyframes spin { to { rotate: 1turn; } }

  /* panel & list */
  .panel {
    border-radius: calc(var(--radius) + 4px); border: 1px solid var(--line);
    background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(12px);
    container-type: inline-size; overflow: hidden;
  }
  .panel.error { padding: 1.5rem; display: grid; gap: 0.5rem; border-color: oklch(0.68 0.2 25 / 0.4); }
  .panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    padding: 1.1rem clamp(1rem, 2vw, 1.4rem);
    border-bottom: 1px solid var(--line);
  }
  .panel-head h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.5rem; }
  .count { font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--bg-2); color: var(--muted); border: 1px solid var(--line); }
  .search {
    display: flex; align-items: center; gap: 0.5rem; color: var(--dim);
    padding: 0.5rem 0.75rem; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2);
    width: min(320px, 100%); transition: border-color 0.15s, box-shadow 0.15s;
  }
  .search:focus-within { border-color: oklch(0.72 0.17 255 / 0.6); box-shadow: 0 0 0 4px oklch(0.72 0.17 255 / 0.15); }
  .search input { border: 0; background: transparent; outline: none; width: 100%; font-size: 0.9rem; }

  .list { display: grid; }
  .row {
    display: grid; align-items: center; gap: 1rem;
    grid-template-columns: minmax(220px, 2.2fr) 1.1fr 0.6fr 0.8fr 0.8fr 1.5fr 1.1fr;
    padding: 0.95rem clamp(1rem, 2vw, 1.4rem);
    border-bottom: 1px solid var(--line);
    font-size: 0.9rem;
    transition: background 0.15s;
  }
  .row:last-child { border-bottom: 0; }
  .row:not(.head):hover { background: oklch(0.72 0.17 255 / 0.06); }
  .row.head {
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--dim);
    padding-block: 0.7rem; background: color-mix(in oklch, var(--bg-2) 60%, transparent);
  }
  .row > span { display: grid; gap: 0.1rem; min-width: 0; }
  .row .num { text-align: right; justify-items: end; }
  .row strong { font-weight: 600; font-variant-numeric: tabular-nums; }
  .dim { color: var(--dim); font-size: 0.78rem; }
  .dim-strong { color: var(--text); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .name { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
  .name > div { display: grid; gap: 0.2rem; min-width: 0; }
  .name strong { font-size: 0.97rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; color: var(--dim); font-family: var(--mono); font-size: 0.76rem; }
  .tag {
    font-family: var(--font); font-size: 0.68rem; font-weight: 600;
    padding: 0.08rem 0.45rem; border-radius: 6px;
    color: light-dark(oklch(0.45 0.16 260), oklch(0.82 0.1 255)); background: oklch(0.72 0.17 255 / 0.12); border: 1px solid oklch(0.72 0.17 255 / 0.2);
  }
  .tag.ok { color: light-dark(oklch(0.45 0.13 155), oklch(0.85 0.12 155)); background: oklch(0.78 0.17 155 / 0.12); border-color: oklch(0.78 0.17 155 / 0.22); }
  .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--dim); }
  .dot.active { background: var(--ok); box-shadow: 0 0 12px oklch(0.78 0.17 155 / 0.7); }
  .dot.new { background: var(--warn); }
  .dot.off, .dot.archive { background: var(--bad); }

  .bar { display: block; width: 88px; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-block: 0.2rem; }
  .bar > span { display: block; height: 100%; width: var(--w); border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
  .empty { padding: 2rem; text-align: center; color: var(--muted); }

  /* entrance */
  .metric, .row:not(.head) { transition-behavior: allow-discrete; }
  @starting-style { .metric { opacity: 0; translate: 0 8px; } }
  .metric { opacity: 1; translate: 0 0; transition: opacity 0.5s, translate 0.5s, transform 0.25s, border-color 0.25s; }

  /* auth */
  .auth { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
  .auth-card {
    width: min(420px, 100%); display: grid; justify-items: center; gap: 1rem; text-align: center;
    padding: 2.5rem 2rem; border-radius: 24px; border: 1px solid var(--line);
    background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(16px);
  }
  .auth-card .logo { width: 52px; height: 52px; }
  .auth-card h1 { font-size: 1.7rem; letter-spacing: -0.03em; }
  .google-btn {
    display: inline-flex; align-items: center; gap: 0.7rem; margin-top: 0.5rem;
    padding: 0.75rem 1.2rem; border-radius: 12px; font-weight: 600; font-size: 0.95rem;
    background: white; color: oklch(0.25 0.02 265); border: 1px solid oklch(0 0 0 / 0.08);
    box-shadow: 0 8px 24px -12px oklch(0 0 0 / 0.5); transition: transform 0.15s, box-shadow 0.15s;
  }
  .google-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 28px -12px oklch(0 0 0 / 0.6); }

  /* responsive */
  @media (max-width: 1000px) {
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric.hero, .metric:last-child { grid-column: 1 / -1; }
  }
  @media (max-width: 560px) {
    .live > span:last-child { display: none; }
    .chip { display: none; }
    .search { width: 100%; }
    .metric .value { font-size: 1.6rem; }
  }
  @container (max-width: 860px) {
    .row.head { display: none; }
    .row {
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 0.8rem 1rem; padding-block: 1.1rem;
    }
    .row .name { grid-column: 1 / -1; }
    .row > span[data-label]::before {
      content: attr(data-label); font-size: 0.66rem; font-weight: 600; letter-spacing: 0.07em;
      text-transform: uppercase; color: var(--dim);
    }
    .row .num { text-align: left; justify-items: start; }
    .row > span[data-label="Image"] { grid-column: span 2; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
  }
}
