:root {
  --navy-900: #060d20;
  --navy-800: #0b1533;
  --navy-700: #131f45;
  --brand-700: #1d4ed8;
  --brand-600: #2563eb;
  --brand-500: #3b82f6;
  --brand-50:  #eff6ff;

  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --line:    #e2e8f0;
  --surface: #ffffff;
  --canvas:  #f5f7fb;

  --ok-600:   #16a34a;
  --ok-50:    #f0fdf4;
  --warn-600: #d97706;
  --warn-50:  #fffbeb;
  --bad-600:  #dc2626;
  --bad-50:   #fef2f2;

  --radius:    14px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-pop:  0 12px 40px -12px rgba(15, 23, 42, .28);
  --header-h: 56px;
  --nav-h: 64px;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink-900);
  font-family: Inter, "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* ------------------------------------------------------------------ shell */

.app-shell { min-height: 100%; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-header--brand {
  background: var(--navy-800);
  border-bottom-color: transparent;
  color: #fff;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 28px);
}

.app-main--wide { max-width: 1100px; }
.app-main--flush { padding-left: 0; padding-right: 0; }

/* No bottom nav on chrome-less pages, so nothing to reserve space for. */
.app-shell--bare .app-main { padding-bottom: 28px; }

/*
 * Desktop shell. The main column must keep reserving the fixed nav's height,
 * otherwise the last card sits underneath it and cannot be read.
 * (The .bottom-nav desktop treatment lives with the nav rules further down,
 * so it lands after the base declarations it needs to override.)
 */
@media (min-width: 768px) {
  .app-header {
    /* Centre the bar's contents on the content column, keep the bar full width. */
    padding-inline: max(16px, calc((100% - 720px) / 2));
  }

  .app-main { padding-bottom: calc(var(--nav-h) + 44px); }
  .app-shell--bare .app-main { padding-bottom: 40px; }
}

/* ------------------------------------------------------------------- type */

.h1 { font-size: 22px; line-height: 30px; font-weight: 700; letter-spacing: -.01em; }
.h2 { font-size: 17px; line-height: 24px; font-weight: 650; }
.muted { color: var(--ink-500); }
.tiny { font-size: 12px; line-height: 16px; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 10px;
  font-size: 13px; font-weight: 650; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-400);
}

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.card-pad { padding: 16px; }

.card-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
}
.card-row:last-child { border-bottom: 0; }
.card-row:active { background: #f8fafc; }

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.stat b { display: block; font-size: 24px; line-height: 30px; font-weight: 700; }
.stat span { font-size: 12px; color: var(--ink-500); }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 12px;
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, opacity .15s, transform .06s;
  user-select: none;
}
.btn:active { transform: scale(.985); }
.btn[disabled], .btn.is-busy { opacity: .6; pointer-events: none; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }

.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); }

.btn-dark { background: var(--navy-800); color: #fff; }
.btn-dark:hover { background: var(--navy-700); }

.btn-outline { background: #fff; border-color: var(--line); color: var(--ink-900); }
.btn-outline:hover { border-color: #cbd5e1; background: #f8fafc; }

.btn-ghost { background: transparent; color: var(--ink-700); }
.btn-ghost:hover { background: #f1f5f9; }

.btn-danger { background: var(--bad-600); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-success { background: var(--ok-600); color: #fff; }

.field { margin-bottom: 14px; }

.label {
  display: block; margin-bottom: 6px;
  font-size: 13px; font-weight: 600; color: var(--ink-700);
}

.input, .textarea, .select {
  width: 100%; min-height: 46px;
  padding: 11px 13px;
  background: #fff;
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; font-family: inherit; color: var(--ink-900);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}

.input[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--bad-600);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}

.input-error { display: none; margin-top: 5px; font-size: 12.5px; color: var(--bad-600); }
.input-error.is-shown { display: block; }

.hint { margin-top: 5px; font-size: 12.5px; color: var(--ink-500); }

/*
 * Prefixed input. --prefix-w reserves room for the prefix; the default suits a
 * single icon, and a text prefix like "metzo.in/" overrides it so the typed
 * value never collides with the label.
 */
.input-group { position: relative; display: flex; align-items: center; --prefix-w: 34px; }
.input-group .input { padding-left: var(--prefix-w); }
.input-group .prefix {
  position: absolute; left: 13px;
  font-size: 16px; color: var(--ink-400); pointer-events: none;
  white-space: nowrap;
}
.input-group--text { --prefix-w: 92px; }

.otp-input {
  width: 100%; padding: 14px;
  font-size: 26px; font-weight: 700; letter-spacing: 14px; text-align: center;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font-variant-numeric: tabular-nums;
}
.otp-input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(59,130,246,.16); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; }
.switch + .switch { border-top: 1px solid var(--line); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  flex: none; width: 46px; height: 28px; border-radius: 999px;
  background: #cbd5e1; position: relative; cursor: pointer; transition: background .18s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--brand-600); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(59,130,246,.3); }

/* --------------------------------------------------------------- identity */

.avatar {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand-50); color: var(--brand-700);
  font-weight: 700; font-size: 15px; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 34px; height: 34px; font-size: 12px; }
.avatar-lg { width: 88px; height: 88px; font-size: 30px; }

.handle { color: var(--ink-500); font-size: 13.5px; }

/* ----------------------------------------------------------------- status */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.badge-green  { background: var(--ok-50);   color: #15803d; }
.badge-amber  { background: var(--warn-50); color: #b45309; }
.badge-red    { background: var(--bad-50);  color: #b91c1c; }
.badge-violet { background: #f5f3ff;        color: #6d28d9; }
.badge-slate  { background: #f1f5f9;        color: #475569; }
.badge-blue   { background: var(--brand-50);color: var(--brand-700); }

.status-pick {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 13px 14px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  font-family: inherit; font-size: 15px; text-align: left; cursor: pointer;
}
.status-pick[aria-pressed="true"] { border-color: var(--brand-500); background: var(--brand-50); }
.status-pick .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* -------------------------------------------------------------- bottom nav */

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.96);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 10.5px; font-weight: 600;
  color: var(--ink-400); text-decoration: none; position: relative;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.is-active { color: var(--brand-600); }

.nav-item .nav-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 0 4px;
  display: none; place-items: center;
  background: var(--bad-600); color: #fff;
  border-radius: 999px; font-size: 10px; font-weight: 700;
}
.nav-item .nav-badge.is-shown { display: grid; }

.nav-fab {
  display: grid; place-items: center;
  width: 50px; height: 50px; margin-top: -18px;
  border-radius: 16px; background: var(--navy-800); color: #fff;
  box-shadow: 0 8px 20px -6px rgba(11, 21, 51, .5);
}
.nav-fab svg { width: 24px; height: 24px; }

/*
 * On desktop the nav stops being a full-width bar (absurd at 1500px) and
 * becomes a floating pill centred over the content column. Declared here,
 * after the base rules, so it actually overrides left/right/bottom.
 */
@media (min-width: 768px) {
  .bottom-nav {
    left: 50%;
    right: auto;
    bottom: 18px;
    transform: translateX(-50%);
    width: min(520px, calc(100vw - 40px));
    height: var(--nav-h);
    padding-bottom: 0;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow-pop);
    overflow: hidden;
  }

  .nav-fab { margin-top: 0; width: 44px; height: 44px; border-radius: 13px; }
}

/* ------------------------------------------------------------ sheet/modal */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, .45);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-height: 86vh; overflow-y: auto;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  background: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-pop);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.32,.72,0,1);
  /* A closed panel must never intercept clicks meant for the page beneath it. */
  pointer-events: none;
}
.sheet.is-open { transform: translateY(0); pointer-events: auto; }

@media (min-width: 640px) {
  .sheet {
    left: 50%; bottom: auto; top: 50%;
    width: min(480px, calc(100vw - 32px));
    border-radius: var(--radius-lg);
    transform: translate(-50%, -46%) scale(.97);
    opacity: 0; transition: transform .2s, opacity .2s;
  }
  .sheet.is-open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.sheet-grip {
  width: 38px; height: 4px; margin: 6px auto 12px;
  background: #cbd5e1; border-radius: 999px;
}
@media (min-width: 640px) { .sheet-grip { display: none; } }

.sheet-title { font-size: 17px; font-weight: 700; margin: 0 0 4px; }

/* ----------------------------------------------------------------- toasts */

.toast-stack {
  /* Sit below the sticky header rather than covering it. */
  position: fixed; left: 50%; top: calc(var(--header-h) + 10px); z-index: 80;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--navy-800); color: #fff;
  border-radius: 12px; box-shadow: var(--shadow-pop);
  font-size: 14px; line-height: 20px;
  animation: toast-in .22s ease-out;
}
.toast.is-out { animation: toast-out .18s ease-in forwards; }
.toast-success { background: #14532d; }
.toast-error   { background: #7f1d1d; }
.toast svg { flex: none; width: 18px; height: 18px; margin-top: 1px; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(-10px); } }

/* ------------------------------------------------------------------ misc */

.empty {
  padding: 40px 20px; text-align: center; color: var(--ink-500);
}
.empty svg { width: 44px; height: 44px; margin: 0 auto 12px; color: #cbd5e1; display: block; }
.empty h3 { margin: 0 0 4px; font-size: 15px; font-weight: 650; color: var(--ink-700); }
.empty p { margin: 0; font-size: 13.5px; }

.skeleton {
  background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

.divider { height: 1px; background: var(--line); margin: 18px 0; }

.list-reset { list-style: none; margin: 0; padding: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line);
  font-size: 13px; font-weight: 550; color: var(--ink-700);
  cursor: pointer; text-decoration: none;
}
.chip.is-active { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }

.qr-frame {
  display: grid; place-items: center;
  padding: 18px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.qr-frame svg { width: 100%; height: auto; max-width: 260px; display: block; }

.link { color: var(--brand-600); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stack  { display: flex; flex-direction: column; gap: 10px; }
.row    { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow   { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

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

/* -------------------------------------------------------------- admin ui */

.admin-shell { display: flex; min-height: 100vh; background: var(--canvas); }

.admin-side {
  position: fixed; inset: 0 auto 0 0; z-index: 50;
  width: 236px; padding: 18px 12px;
  background: var(--navy-800); color: #cbd5e1;
  overflow-y: auto;
  transform: translateX(-100%); transition: transform .22s;
}
.admin-side.is-open { transform: translateX(0); }

.admin-side a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 10px; color: #cbd5e1;
  font-size: 14px; font-weight: 550; text-decoration: none;
}
.admin-side a:hover { background: rgba(255,255,255,.07); color: #fff; }
.admin-side a.is-active { background: var(--brand-600); color: #fff; }
.admin-side svg { width: 18px; height: 18px; flex: none; }

.admin-body { flex: 1; min-width: 0; padding: 16px; }

@media (min-width: 1024px) {
  .admin-side { transform: none; }
  .admin-body { margin-left: 236px; }
  .admin-burger { display: none !important; }
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 11px 14px; text-align: left; white-space: nowrap; }
table.data th {
  background: #f8fafc; color: var(--ink-500);
  font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--line);
}
table.data td { border-bottom: 1px solid #f1f5f9; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #f8fafc; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
