/* admin.css — Matzorkis admin panel
   One stylesheet, no framework, no external fonts. Light and dark. */

:root {
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --surface-2: #f9fafb;
  --border:    #e2e5ea;
  --text:      #14181f;
  --muted:     #667085;
  --accent:    #2563eb;
  --accent-2:  #1d4ed8;
  --good:      #15803d;
  --warn:      #b45309;
  --bad:       #b42318;
  --bot:       #a855f7;
  /* Behind the map tiles while they load. */
  --map-sea:   #f0f2f5;
  --radius:    10px;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1319;
    --surface:   #171c24;
    --surface-2: #1e242e;
    --border:    #2a323d;
    --text:      #e7ebf0;
    --muted:     #94a0b0;
    --accent:    #60a5fa;
    --accent-2:  #93c5fd;
    --good:      #4ade80;
    --warn:      #fbbf24;
    --bad:       #f87171;
    --bot:       #c084fc;
    --map-sea:   #131820;
    --shadow:    0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; height: 56px;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 20px; flex: 1; }
.mainnav a {
  color: var(--muted); font-weight: 500; padding: 6px 0;
  border-bottom: 2px solid transparent;
}
.mainnav a.on { color: var(--text); border-bottom-color: var(--accent); }
.mainnav a:hover { color: var(--text); text-decoration: none; }
.whoami { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.inline { display: inline; }
.linkbtn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: 13px;
}
.linkbtn:hover { text-decoration: underline; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 20px 56px; }

.pagehead { display: flex; align-items: baseline; gap: 14px; margin: 0 0 18px; }
.pagehead h1 { font-size: 22px; margin: 0; }
.pagehead .meta { color: var(--muted); font-size: 13px; }

/* ---------- Filter bar ---------- */
.filterbar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 20px;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.grow { flex: 1 1 220px; }
.field label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600;
}
.field.actions { margin-left: auto; }
input[type=text], input[type=search], input[type=date], input[type=password], select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 14px; min-width: 130px;
}
.field.grow input { width: 100%; }
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.block { width: 100%; margin-top: 18px; }
/* A filter-bar layout without the card chrome, for forms already inside a panel. */
.filterbar.plain { border: 0; box-shadow: none; padding: 0; margin: 0; background: none; }
.hint { margin: 12px 0 0; }
.w-order { min-width: 5rem; width: 5rem; }
table.data input[type=text], table.data input[type=number] { width: 100%; min-width: 0; }
table.data td form { display: inline; }

/* Compact one-line form: an input or select plus its button, sitting in a
   table cell or a panel footer. */
.inline-form { display: inline-flex; align-items: center; gap: 6px; }
.inline-form + .inline-form { margin-left: 14px; }
.inline-form input[type=text], .inline-form select { min-width: 12rem; }
table.data .inline-form input[type=text] { width: auto; }

/* ---------- Mute buttons ---------- */
.muteform { display: inline; }
.mutebtn {
  background: none; border: 0; padding: 2px 4px; cursor: pointer;
  color: var(--muted); line-height: 1; border-radius: 5px;
  vertical-align: -3px;
}
.mutebtn:hover { color: var(--bad); background: var(--surface-2); }
.mutetag {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px;
  border-radius: 999px; color: var(--muted);
  border: 1px solid var(--border);
}

/* ---------- Settings rows ---------- */
.setting { border-bottom: 1px solid var(--border); padding: 12px 0; }
.setting:last-of-type { border-bottom: 0; }
.setting-row { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.setting-row input[type=checkbox] { margin-top: 3px; flex: none; }
.setting-row > span { display: flex; flex-direction: column; gap: 2px; }

/* Visible to screen readers, not on screen. */
.sr-label {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Cards ---------- */
.cards {
  display: grid; gap: 14px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.card .k {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; margin-bottom: 6px;
}
.card .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 20px; overflow: hidden;
}
.panel > h2 {
  font-size: 14px; margin: 0; padding: 13px 16px;
  border-bottom: 1px solid var(--border); font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.panel > h2 .note { font-weight: 400; color: var(--muted); font-size: 12px; }
.panel-body { padding: 16px; }
.grid2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* ---------- Chart ---------- */
.chart { width: 100%; height: 260px; display: block; }
.chart-legend {
  display: flex; gap: 16px; font-size: 12px; color: var(--muted);
  padding: 0 16px 14px;
}
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.swatch-human { background: var(--accent); }
.swatch-bot { background: var(--bot); }

/* ---------- Tabs ----------
   A panel header made of folder-style tabs, top-left — the card-header-tabs
   look. The active tab shares the body's background and overhangs the
   header's bottom border by 1px (margin-bottom: -1px, no bottom border of
   its own), so it reads as part of the pane below it. */
.tabbar {
  display: flex; gap: 4px; align-items: flex-end;
  padding: 8px 12px 0; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.tabbar button {
  background: none; border: 1px solid transparent; border-bottom: 0;
  border-radius: 8px 8px 0 0; padding: 8px 16px 9px; margin-bottom: -1px;
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.tabbar button:hover { color: var(--text); }
.tabbar button.on {
  color: var(--text); background: var(--surface); border-color: var(--border);
}
/* [hidden] on a flex or grid child loses to the display rule that follows it,
   so say it once, loudly, for the tab panels. */
[role=tabpanel][hidden] { display: none; }

/* ---------- Map ---------- */
/* The Leaflet container. Leaflet's own stylesheet does the heavy lifting;
   this sets the box, and a sea-colored backdrop for the moment before the
   tiles arrive (and for the message shown if Leaflet doesn't). */
.worldmap {
  width: 100%; height: 380px; display: block;
  background: var(--map-sea); border-radius: 8px;
}
.map-message {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-align: center; padding: 0 24px;
}
.map-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  font-size: 12px; color: var(--muted); padding: 0 16px 14px;
}
/* The size key: three circles at the sizes map.js would draw, so "bigger dot
   means more hits" doesn't have to be guessed. */
.map-key { display: flex; align-items: center; gap: 7px; }
.map-key i {
  display: inline-block; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 45%, transparent);
  border: 1px solid var(--accent);
}
.map-key i.s1 { width: 6px;  height: 6px; }
.map-key i.s2 { width: 13px; height: 13px; }
.map-key i.s3 { width: 22px; height: 22px; }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td {
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; background: var(--surface-2);
  /* Sticks to the top of .tablescroll, its own scroll container — NOT to the
     page. Offsetting this by the topbar's height would push the header down
     inside every panel and cover the first row. */
  position: sticky; top: 0; z-index: 2;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.nowrap { white-space: nowrap; }

/* Horizontal scroller for wide tables. Note that setting overflow-x alone
   makes the browser compute overflow-y to auto as well, so this is a scroll
   container in both axes — which is what the sticky header above anchors to. */
.tablescroll { overflow-x: auto; }

/* Opt-in vertical scroller for long tables, so the header stays in view while
   you page through rows instead of scrolling off the top. */
.tablescroll.tall { max-height: min(72vh, 760px); overflow: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.bar {
  display: block; height: 4px; border-radius: 2px; background: var(--accent);
  opacity: .5; margin-top: 4px; min-width: 2px;
}

.tag {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px;
  border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
}
.tag.bot { color: var(--bot); border-color: color-mix(in srgb, var(--bot) 45%, transparent); }
.tag.human { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, transparent); }

details.ai summary { cursor: pointer; color: var(--accent); font-size: 12px; }
details.ai p { margin: 6px 0 0; white-space: pre-wrap; color: var(--muted); font-size: 12.5px; max-width: 60ch; }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- Pagination ---------- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px 16px; padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted); flex-wrap: wrap;
}
.pager .inline-form + .inline-form { margin-left: 0; }
.pager .links { display: flex; gap: 6px; }
.pager .links a, .pager .links span {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 7px;
}
.pager .links span { opacity: .45; }

/* ---------- Alerts ---------- */
.alert {
  padding: 10px 13px; border-radius: 8px; font-size: 13.5px;
  border: 1px solid var(--border); margin-bottom: 16px;
}
.alert.error  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.alert.notice { color: var(--muted); }

/* ---------- Login ---------- */
body.loginpage {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.loginbox {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 32px; width: 100%; max-width: 380px;
}
.loginbox h1 { font-size: 20px; margin: 0 0 4px; }
.loginbox .sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.loginbox label {
  display: block; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 5px;
}
.loginbox input { width: 100%; padding: 9px 11px; }

/* ---------- Footer ---------- */
.pagefoot {
  max-width: 1280px; margin: 0 auto; padding: 0 20px 32px;
  display: flex; justify-content: space-between; gap: 16px;
  color: var(--muted); font-size: 12px;
}

@media (max-width: 640px) {
  .topbar-inner { gap: 14px; }
  .whoami span { display: none; }
}
