/* ============================================================================
   Explorer Rank Backoffice — design system
   Light, dense, professional. GitHub-style neutrals, blue accent.
   Single stylesheet. Routes emit plain HTML (h1/h2/table/form/...) and this
   file styles all of it. Add new components here; pages get them for free.
   ============================================================================ */

:root {
  /* — surfaces — */
  --bg:          #F6F8FA;
  --panel:       #FFFFFF;
  --line:        #D0D7DE;
  --line-soft:   #EAEEF2;

  /* — text — */
  --ink:         #1F2328;
  --ink-dim:     #57606A;
  --ink-faint:   #8C959F;

  /* — accent / semantic — */
  --accent:       #0969DA;
  --accent-hover: #0860CA;
  --accent-bg:    #DDF4FF;
  --accent-line:  #54AEFF;
  --accent-ring:  rgba(9,105,218,.25);
  --ok:     #1A7F37; --ok-bg:     #DAFBE1; --ok-line:     #4AC26B;
  --warn:   #9A6700; --warn-bg:   #FFF8C5; --warn-line:   #EAC54F;
  --danger: #CF222E; --danger-hover: #A40E26;
  --danger-bg: #FFEBE9; --danger-line: #FF8182;
  --purple: #8250DF; --purple-bg: #FBEFFF; --purple-line: #E2C5FF;

  /* — system — */
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 10px;
  --sidebar-w: 220px;
  --shadow-sm: 0 1px 2px rgba(31,35,40,.06);
  --shadow:    0 3px 12px rgba(31,35,40,.14);

  --font-ui:   system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

::selection { background: var(--accent-bg); color: var(--accent); }

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff; font-weight: 700; font-size: 16px;
}
.brand-name { font-weight: 700; font-size: 14px; line-height: 1.15; }
.brand-sub  { font-size: 10.5px; color: var(--ink-faint); letter-spacing: .12em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav-label { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); padding: 10px 10px 5px; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-dim);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  position: relative;
  transition: background .12s, color .12s;
}
.nav-link svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav-link:hover { background: var(--bg); color: var(--ink); }
.nav-link.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.nav-link.active svg { opacity: 1; }
.nav-link.active::before {
  content: ""; position: absolute; left: -12px; top: 7px; bottom: 7px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-spacer { flex: 1; }
.nav-link.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* ── Shell / topbar / content ─────────────────────────────────────────── */
.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar .section { font-weight: 600; font-size: 14px; }
.topbar .crumb { color: var(--ink-faint); }
.live-dot {
  margin-left: auto; display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--ink-dim);
  padding: 3px 10px; border: 1px solid var(--line); border-radius: 100px; background: var(--bg);
}
.live-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok-line); }

/* Mobile nav controls — inert on desktop, activated in the @media block below. */
.nav-toggle {
  display: none; flex: none; place-items: center;
  width: 38px; height: 38px; padding: 0; cursor: pointer;
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: none;
}
.nav-toggle:hover { background: var(--bg); }
.nav-toggle svg { width: 20px; height: 20px; }
.nav-backdrop { display: none; }

.content { flex: 1; padding: 24px 28px 56px; max-width: 1120px; width: 100%; }

.footer { padding: 14px 28px; margin-left: var(--sidebar-w); color: var(--ink-faint); font-size: 12px; border-top: 1px solid var(--line-soft); }

/* ── Typography ───────────────────────────────────────────────────────── */
h1 { font-weight: 600; font-size: 22px; letter-spacing: -.2px; margin: 2px 0 16px; }
h2 {
  font-weight: 600; font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-dim); margin: 24px 0 10px;
}
p { color: var(--ink-dim); margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Tables ───────────────────────────────────────────────────────────── */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; margin: 6px 0 16px; box-shadow: var(--shadow-sm);
  font-size: 13px;
}
th {
  text-align: left; font-weight: 600; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-dim); background: var(--bg);
  padding: 8px 12px; border-bottom: 1px solid var(--line);
}
td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); color: var(--ink); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:hover td { background: var(--bg); }
/* first column reads like an identifier */
td:first-child { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }
td a { font-weight: 600; }
td form { display: inline; }
td .btn, td button { vertical-align: middle; }

/* ── Forms ────────────────────────────────────────────────────────────── */
/* Forms are invisible flex wrappers by default — no chrome. Standalone
   filter/search forms opt into the card look with class="panel". */
form {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
  margin: 0 0 12px;
}
form.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; box-shadow: var(--shadow-sm);
}

input, select, textarea {
  font-family: var(--font-ui); font-size: 13px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 5px 10px; min-width: 0; flex: 1 1 130px;
  max-width: 320px;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
input[type=hidden] { display: none; }
select { flex: 0 1 auto; cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-ui); font-weight: 500; font-size: 13px;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 5px 12px; cursor: pointer;
  flex: 0 0 auto; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--line-soft); border-color: var(--ink-faint); text-decoration: none; }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.primary, .btn.primary {
  font-weight: 600; color: #fff;
  background: var(--accent); border-color: rgba(31,35,40,.15);
}
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: rgba(31,35,40,.15); }

button.danger, .btn.danger {
  font-weight: 600; color: #fff;
  background: var(--danger); border-color: rgba(31,35,40,.15);
}
button.danger:hover, .btn.danger:hover { background: var(--danger-hover); border-color: rgba(31,35,40,.15); }

button.sm, .btn.sm { padding: 3px 10px; font-size: 12px; }

/* ── Action row (Reply / status buttons under a card's content) ───────── */
.actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-soft);
}
.actions form { margin: 0; }

/* ── Cards & stats ────────────────────────────────────────────────────── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.card h2:first-child { margin-top: 0; }
.card.warn { border-left: 3px solid var(--warn-line); background: #FFFCF0; }
.grid { display: grid; gap: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 4px 0 18px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.stat .value { font-weight: 600; font-size: 28px; line-height: 1.15; margin-top: 4px; letter-spacing: -.5px; }
.stat .value.accent { color: var(--accent); }

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  font-family: var(--font-ui); font-size: 11px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 100px; border: 1px solid transparent; text-transform: capitalize;
}
.badge-ok     { color: var(--ok);      background: var(--ok-bg);      border-color: var(--ok-line); }
.badge-warn   { color: var(--warn);    background: var(--warn-bg);    border-color: var(--warn-line); }
.badge-accent { color: var(--purple);  background: var(--purple-bg);  border-color: var(--purple-line); }
.badge-muted  { color: var(--ink-dim); background: var(--bg);         border-color: var(--line); }
.badge-info   { color: var(--accent);  background: var(--accent-bg);  border-color: var(--accent-line); }

/* ── Empty state ──────────────────────────────────────────────────────── */
.empty {
  padding: 26px 16px; text-align: center; color: var(--ink-faint); font-size: 13px;
  background: var(--panel); border: 1px dashed var(--line); border-radius: var(--r);
  margin: 6px 0 16px;
}

/* ── Toasts (htmx action feedback) ────────────────────────────────────── */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--r);
  background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transform: translateX(16px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast::before { content: ""; width: 3px; align-self: stretch; border-radius: 3px; flex: none; }
.toast-ok::before  { background: var(--ok-line); }
.toast-err { border-color: var(--danger-line); }
.toast-err::before { background: var(--danger); }

/* ── Auth / login ─────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 36px 32px; box-shadow: var(--shadow-sm);
}
.auth-card .brand { justify-content: center; padding-bottom: 22px; }
.auth-card h1 { font-size: 19px; margin: 0 0 6px; }
.auth-card p { margin-bottom: 22px; }
.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 10px 16px; font-weight: 600; font-size: 14px; border-radius: var(--r-sm);
  color: #fff; background: var(--accent); border: 1px solid rgba(31,35,40,.15);
}
.google-btn:hover { text-decoration: none; background: var(--accent-hover); }

.error { color: var(--danger); }

/* ── Helpers ──────────────────────────────────────────────────────────── */
.muted { color: var(--ink-faint); font-size: 13px; }
.mono { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--ink-dim); font-weight: 600; font-size: 13px; }
.back-link:hover { color: var(--accent); text-decoration: none; }

/* ── Field (label + control) ──────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 3px; flex: 0 1 200px; max-width: 320px; }
.field > label { font-size: 10.5px; font-weight: 600; letter-spacing: .04em; color: var(--ink-faint); text-transform: uppercase; }
/* Inside a column .field, reset flex so flex-basis stops setting the HEIGHT. */
.field input, .field select, .field textarea { flex: none; width: 100%; max-width: none; }

/* ── Profile 360 header ───────────────────────────────────────────────── */
.profile-head {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px;
  box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.pf-id { display: flex; align-items: center; gap: 14px; }
.pf-avatar { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; flex: none; border: 1px solid var(--line); }
.pf-avatar-ph { display: grid; place-items: center; font-weight: 700; font-size: 22px; color: var(--accent); background: var(--accent-bg); }
.pf-name { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pf-sub { margin-top: 2px; color: var(--ink-dim); font-size: 13px; overflow-wrap: anywhere; }
.pf-dates { margin-top: 3px; }
.pf-title { font-size: 11px; font-weight: 600; color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 100px; padding: 2px 8px; }

.pf-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(82px, 1fr)); gap: 8px; margin-top: 16px; }
.pf-stat { background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--r-sm); padding: 9px 10px; text-align: center; }
.pf-stat .v { display: block; font-family: var(--font-mono); font-weight: 600; font-size: 16px; color: var(--ink); }
.pf-stat .l { display: block; font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }

/* ── Action panels grid ───────────────────────────────────────────────── */
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.panel-grid .card { margin: 0; }
.panel-grid form:last-child { margin-bottom: 0; }

/* ── Visits panel ─────────────────────────────────────────────────────── */
.visit-group { margin-bottom: 14px; }
.visit-group h3 { font-family: var(--font-ui); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-dim); margin: 0 0 6px; }
.visit-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--line-soft); border-radius: var(--r-sm); margin-bottom: 5px; background: var(--bg); }
.visit-row .mono { flex: 1; color: var(--ink); }
.visit-row form { display: inline; margin: 0; }
.visit-add { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }

/* ── Content: chips + souvenir slots ──────────────────────────────────── */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip-row button:hover { border-color: var(--accent); color: var(--accent); background: var(--panel); }
.sv-slot { border: 1px solid var(--line-soft); border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 10px; background: var(--bg); }
.sv-slot h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
#lm-results, #lm-editor, #sv-editor { margin-bottom: 14px; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  /* ── Nav: the full sidebar becomes an off-canvas drawer ── */
  .nav-toggle { display: inline-grid; }
  .sidebar {
    width: min(82vw, 290px); padding: 16px 14px;
    transform: translateX(-100%); will-change: transform;
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 25;
    background: rgba(31, 35, 40, .45);
    opacity: 0; visibility: hidden; transition: opacity .28s, visibility .28s;
  }
  body.nav-open .nav-backdrop { opacity: 1; visibility: visible; }
  body.nav-open { overflow: hidden; }

  .shell, .footer { margin-left: 0; }
  .content { padding: 18px 14px 52px; }
  .topbar { padding: 0 12px; gap: 10px; }
  h1 { font-size: 19px; }

  /* ── Tables → labelled cards (each row stacks; td::before shows the column) ── */
  table { display: block; background: transparent; border: 0; box-shadow: none; border-radius: 0; margin: 6px 0 14px; }
  table tr:has(th) { display: none; }                  /* the bare header row */
  table tr {
    display: block; background: var(--panel);
    border: 1px solid var(--line); border-radius: var(--r);
    box-shadow: var(--shadow-sm); padding: 4px 12px; margin: 0 0 10px;
  }
  table td, table tbody tr:hover td, table tr:hover td {
    display: flex; align-items: center; gap: 14px; justify-content: space-between;
    padding: 8px 0; border-bottom: 1px solid var(--line-soft);
    text-align: right; white-space: normal; overflow-wrap: anywhere; background: transparent;
  }
  table td:last-child { border-bottom: 0; }
  table td::before {
    content: attr(data-label); flex: none; text-align: left;
    font-family: var(--font-ui); font-weight: 600; font-size: 10.5px;
    letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint);
  }
  table td:first-child { font-size: 12px; }
  td.cell-actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
  td.cell-actions::before { display: none; }

  /* ── Forms: full-width, comfortable, 16px to stop iOS focus-zoom ── */
  form { gap: 10px; }
  form.panel { padding: 14px; }
  .field { flex: 1 1 100%; max-width: none; }
  input, select, textarea { font-size: 16px; padding: 9px 12px; max-width: none; flex: 1 1 100%; }
  button, .btn { padding: 9px 14px; }
  form > button, form > .btn { width: 100%; }
  /* but inline action buttons (cells, visit rows, chips, action rows) stay compact */
  td.cell-actions button, td.cell-actions .btn,
  .visit-row button, .visit-row .btn, .chip-row button,
  .actions button, .actions .btn { width: auto; }

  /* ── Profile ── */
  .profile-head { padding: 14px; }
  .pf-stats { grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }

  /* ── Toasts span the bottom on a phone ── */
  #toasts { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* ── Showcase moderation grid ── */
.sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 10px 0; }
.sc-thumb { position: relative; border-radius: var(--r); overflow: hidden; cursor: pointer; border: 3px solid transparent; background: var(--line-soft); }
.sc-thumb.selected { border-color: var(--accent); }
.sc-thumb img { width: 100%; height: 140px; object-fit: cover; display: block; }
.sc-order { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: none; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.sc-thumb.selected .sc-order { display: flex; }
.sc-credit { position: absolute; bottom: 0; left: 0; right: 0; padding: 3px 7px; background: rgba(31,35,40,.6); color: #fff; font-size: 11px; }

/* ── Landmark moderation ── */
.mod-photo { width: 100%; max-width: 420px; height: 220px; object-fit: cover; border-radius: var(--r); display: block; margin: 8px 0; background: var(--line-soft); }

/* ── Support category sub-tabs ── */
.support-tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin: 0 0 14px; }
.support-tab { padding: 8px 14px; font-size: 13px; font-weight: 500; color: var(--ink-dim); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.support-tab:hover { color: var(--ink); text-decoration: none; }
.support-tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tab-count { display: inline-block; min-width: 16px; text-align: center; font-size: 11px; font-weight: 600; color: var(--ink-dim); background: var(--bg); border: 1px solid var(--line); border-radius: 100px; padding: 0 6px; margin-left: 3px; }
.support-tab.active .tab-count { color: var(--accent); background: var(--accent-bg); border-color: var(--accent-line); }

/* ── Danger zone (destructive account actions, isolated from daily use) ── */
.card.danger-zone { border-color: var(--danger-line); background: #FFF8F8; margin-top: 16px; }
.card.danger-zone > h2:first-child { color: var(--danger); }
