/* ============================================================
   VKS Patrol PWA — Design System
   Mobile-first. Native app feel. Lao + EN typography.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=JetBrains+Mono:wght@500;600&family=Noto+Sans+Lao:wght@400;500;600;700&display=swap');

/* ---------- Tokens ---------- */
:root {
  /* Surfaces */
  --bg:                hsl(222, 38%, 6%);
  --bg-overlay:        hsla(222, 40%, 5%, 0.6);
  --surface:           hsl(222, 28%, 10%);
  --surface-elev:      hsl(222, 24%, 14%);
  --surface-glass:     hsla(222, 30%, 12%, 0.72);
  --border:            hsla(220, 30%, 70%, 0.08);
  --border-strong:     hsla(220, 30%, 70%, 0.16);

  /* Foreground */
  --fg:                hsl(220, 20%, 96%);
  --fg-muted:          hsl(220, 14%, 64%);
  --fg-faint:          hsl(220, 14%, 44%);

  /* Brand & state */
  --accent:            hsl(150, 80%, 50%);
  --accent-deep:       hsl(150, 70%, 40%);
  --accent-glow:       hsla(150, 80%, 50%, 0.18);
  --accent-bg:         hsla(150, 80%, 50%, 0.10);
  --amber:             hsl(38, 95%, 60%);
  --danger:            hsl(355, 80%, 60%);
  --info:              hsl(210, 90%, 65%);

  /* Type stacks (Noto Sans Lao always present) */
  --font-display:      'Sora', 'Noto Sans Lao', system-ui, sans-serif;
  --font-body:         'Sora', 'Noto Sans Lao', system-ui, sans-serif;
  --font-mono:         'JetBrains Mono', 'Noto Sans Lao', ui-monospace, monospace;

  /* Layout */
  --max-w:             480px;
  --safe-top:          env(safe-area-inset-top, 0px);
  --safe-bottom:       env(safe-area-inset-bottom, 0px);

  /* Motion */
  --ease-out:          cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out:       cubic-bezier(0.65, 0, 0.35, 1);

  /* Radii & shadows */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px hsla(220, 40%, 2%, 0.4);
  --shadow-2: 0 8px 24px hsla(220, 40%, 2%, 0.35), 0 2px 6px hsla(220, 40%, 2%, 0.25);
  --shadow-glow: 0 0 0 1px var(--accent-glow), 0 8px 24px hsla(150, 80%, 50%, 0.18);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Subtle radial glow to break the flat dark */
  background-image:
    radial-gradient(1200px circle at 80% -10%, hsla(150, 80%, 40%, 0.12), transparent 50%),
    radial-gradient(900px circle at -10% 110%, hsla(220, 90%, 50%, 0.08), transparent 50%);
  background-attachment: fixed;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }

.app-shell {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.hidden { display: none !important; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */

.login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(48px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  animation: fadeUp 0.6s var(--ease-out) both;
}

.brand-block {
  text-align: center;
  margin-bottom: 40px;
}

.brand-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-glow);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  border: 1px solid hsla(0, 0%, 100%, 0.12);
}
.brand-mark span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: hsl(222, 60%, 8%);
  letter-spacing: 0.02em;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  background: linear-gradient(180deg, var(--fg) 0%, hsl(220, 14%, 70%) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tagline {
  color: var(--fg-muted);
  font-size: 13px;
  letter-spacing: 0.01em;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-2);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}

.label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 10px;
}
.label .hint { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.7; }

.id-input-wrap {
  position: relative;
}

.input {
  width: 100%;
  padding: 16px 18px;
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.06em;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out), background 0.18s var(--ease-out);
  text-transform: uppercase;
}
.input::placeholder {
  color: var(--fg-faint);
  letter-spacing: 0.08em;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
  background: hsl(222, 30%, 8%);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 14px 20px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.08s var(--ease-out), background 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
  user-select: none;
}
.btn-primary {
  color: hsl(222, 60%, 6%);
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  box-shadow: var(--shadow-glow);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-primary:active:not(:disabled) { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.btn-ghost {
  background: var(--surface-elev);
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: hsl(222, 22%, 17%); }
.btn-ghost:active:not(:disabled) { transform: scale(0.985); }

.btn-row { margin-top: 22px; }

.field-error {
  margin-top: 14px;
  padding: 12px 14px;
  background: hsla(355, 80%, 60%, 0.08);
  color: var(--danger);
  border: 1px solid hsla(355, 80%, 60%, 0.22);
  border-radius: var(--r-md);
  font-size: 13.5px;
  display: none;
  animation: shake 0.45s var(--ease-out);
}
.field-error.visible { display: flex; align-items: flex-start; gap: 8px; }
.field-error::before { content: "⚠"; flex: none; font-size: 14px; line-height: 1.4; }

.login-footer {
  text-align: center;
  margin-top: 22px;
  color: var(--fg-faint);
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* ============================================================
   HOME SCREEN
   ============================================================ */

#screen-home {
  display: flex;
  flex-direction: column;
  flex: 1;
  animation: fadeUp 0.4s var(--ease-out) both;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) 18px 12px;
  background: var(--surface-glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: var(--surface-elev);
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.status-pill .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--fg-faint);
  flex: none;
  position: relative;
}
.status-pill.online { color: var(--accent); background: var(--accent-bg); border-color: hsla(150, 80%, 50%, 0.25); }
.status-pill.online .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-pill.online .dot::after {
  content: ""; position: absolute; inset: -3px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: pulse 1.6s var(--ease-in-out) infinite;
}
.status-pill.offline { color: var(--amber); background: hsla(38, 95%, 60%, 0.10); border-color: hsla(38, 95%, 60%, 0.28); }
.status-pill.offline .dot { background: var(--amber); }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--fg);
  transition: background 0.15s var(--ease-out), transform 0.08s var(--ease-out);
}
.icon-btn:hover { background: hsl(222, 22%, 17%); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main.home-main {
  flex: 1;
  padding: 20px 18px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ----- Greeting hero card ----- */
.hero {
  position: relative;
  border-radius: var(--r-lg);
  padding: 24px 22px 22px;
  background:
    radial-gradient(120% 100% at 100% 0%, hsla(150, 80%, 45%, 0.18), transparent 55%),
    linear-gradient(180deg, var(--surface-elev) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  animation: fadeUp 0.5s 0.05s var(--ease-out) both;
}
.hero::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(800px circle at 100% 0%, hsla(150, 80%, 50%, 0.08), transparent 40%);
  pointer-events: none;
}

.greeting {
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin: 0 0 6px;
  font-weight: 500;
}
.hero-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  line-height: 1.2;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  position: relative;
  z-index: 1;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: hsla(220, 20%, 60%, 0.08);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}
.chip-id {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-bg);
  border-color: hsla(150, 80%, 50%, 0.22);
}
.chip-route { color: var(--fg); }
.chip-shift { color: var(--fg); }

/* ----- Action grid ----- */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-card {
  position: relative;
  padding: 18px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
  cursor: pointer;
  transition: transform 0.12s var(--ease-out), border-color 0.18s var(--ease-out), background 0.18s var(--ease-out);
  overflow: hidden;
  animation: fadeUp 0.5s var(--ease-out) both;
}
.action-card:nth-child(1) { animation-delay: 0.10s; }
.action-card:nth-child(2) { animation-delay: 0.16s; }
.action-card:nth-child(3) { animation-delay: 0.22s; }
.action-card:nth-child(4) { animation-delay: 0.28s; }

.action-card:hover { border-color: var(--border-strong); background: var(--surface-elev); }
.action-card:active { transform: scale(0.98); }

.action-card.primary {
  background: linear-gradient(160deg, hsla(150, 80%, 30%, 0.30), hsla(150, 80%, 14%, 0.10) 60%), var(--surface);
  border-color: hsla(150, 80%, 50%, 0.30);
}
.action-card.primary::after {
  content: "";
  position: absolute; right: -40px; top: -40px;
  width: 140px; height: 140px;
  background: radial-gradient(circle, var(--accent-glow), transparent 65%);
  pointer-events: none;
}

.action-card.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.action-card.disabled:hover { background: var(--surface); border-color: var(--border); }
.action-card.disabled:active { transform: none; }

.action-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-bg);
  border: 1px solid hsla(150, 80%, 50%, 0.18);
  display: grid; place-items: center;
  color: var(--accent);
  transition: transform 0.2s var(--ease-out);
}
.action-card:hover .action-icon { transform: rotate(-4deg) scale(1.05); }
.action-card.disabled .action-icon { background: hsla(220, 20%, 60%, 0.08); border-color: var(--border); color: var(--fg-muted); }
.action-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.action-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  margin: 0;
  line-height: 1.3;
  color: var(--fg);
}
.action-desc {
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.4;
  margin: 0;
}

.coming-soon-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: hsla(38, 95%, 60%, 0.12);
  color: var(--amber);
  border: 1px solid hsla(38, 95%, 60%, 0.25);
}

/* ----- Section heading ----- */
.section-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 2px 0;
}
.section-h h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin: 0;
}
.section-h .section-sub {
  font-size: 11.5px;
  color: var(--fg-faint);
  letter-spacing: 0.02em;
}

/* ============================================================
   MENU SHEET (bottom drawer)
   ============================================================ */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease-out);
}
.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 100%);
  width: 100%;
  max-width: var(--max-w);
  background: var(--surface);
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  border-top: 1px solid var(--border-strong);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 12px 16px calc(20px + var(--safe-bottom));
  z-index: 101;
  transition: transform 0.32s var(--ease-out);
  box-shadow: 0 -10px 40px hsla(220, 60%, 2%, 0.5);
}
.sheet.open { transform: translate(-50%, 0); }

.sheet-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 6px auto 16px;
}

.sheet-header {
  padding: 0 4px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.sheet-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  margin: 0 0 2px;
}
.sheet-sub {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-faint);
  letter-spacing: 0.06em;
  margin: 0;
}

.sheet-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 8px;
  border-radius: var(--r-md);
  transition: background 0.15s var(--ease-out);
  width: 100%;
  text-align: left;
  color: var(--fg);
  min-height: 52px;
}
.sheet-row:hover { background: var(--surface-elev); }
.sheet-row:active { background: hsl(222, 22%, 17%); }
.sheet-row .icn {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--fg-muted);
  flex: none;
}
.sheet-row .icn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sheet-row .lbl {
  flex: 1;
  font-size: 14.5px;
  font-weight: 500;
}
.sheet-row .meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-faint);
  letter-spacing: 0.04em;
}
.sheet-row.danger .icn { background: hsla(355, 80%, 60%, 0.10); border-color: hsla(355, 80%, 60%, 0.22); color: var(--danger); }
.sheet-row.danger .lbl { color: var(--danger); }

/* ============================================================
   MICRO ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%   { transform: scale(1); opacity: 0.5; }
  70%  { transform: scale(1.8); opacity: 0; }
  100% { transform: scale(1.8); opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid hsla(0, 0%, 100%, 0.25);
  border-top-color: hsl(222, 60%, 6%);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  .status-pill.online .dot::after { display: none; }
}
