/* Anno — shared design system.
   Tokens keep their historical names (--bg, --bg2, --bg3, --line, --fg, --fg-dim,
   --accent, --accent2, --ok, --bad, --warn, --hover): every page and inline
   <style> block reads them, so restyling here restyles the whole app. */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #0f1216; --bg2: #161a20; --bg3: #1f242c; --line: #2b323c;
  --fg: #e7eaef; --fg-dim: #8d95a3; --accent: #8b7cff; --accent2: #a99cff;
  --ok: #3ecf6f; --bad: #ff5b5b; --warn: #ffb454; --hover: #262a44;
  --accent-soft: #8b7cff22; --shadow: 0 10px 34px #00000088;
  --on-accent: #0f1216;                 /* text on --accent: 5.7:1 (white was 3.3:1) */
  --canvas: #0b0c0f;                    /* image viewers / crops: always dark so packaging colours read true */
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Sora", "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 8px; --radius-lg: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef0f4; --bg2: #ffffff; --bg3: #e4e7ee; --line: #cdd3dd;
  --fg: #1a202b; --fg-dim: #5c6675; --accent: #5b4de0; --accent2: #4638c2;
  --ok: #12803c; --bad: #d3322a; --warn: #a86400; --hover: #e6e3ff;
  --accent-soft: #5b4de01a; --shadow: 0 10px 30px #1a202b22;
  --on-accent: #ffffff;                 /* 5.9:1 on the light accent */
  --canvas: #0b0c0f;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;      /* counts line up in tables and stats */
}
::selection { background: var(--accent); color: var(--on-accent); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- type scale: display for the page title only, body for the rest ---------- */
h1 { font: 600 22px/1.2 var(--font-display); letter-spacing: -.01em; margin: 0 0 6px; }
h2 { font: 600 15px/1.3 var(--font-display); letter-spacing: -.005em; margin: 22px 0 10px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
b, strong { font-weight: 600; }
code, .mono, .kbd { font-family: var(--font-mono); }

/* ---------- controls ---------- */
button, .btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 12px; cursor: pointer; font: inherit;
  font-weight: 500; line-height: 1.35; text-decoration: none;
  transition: border-color .15s, background-color .15s, color .15s, transform .06s;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover, .btn.primary:hover { background: var(--accent2); border-color: var(--accent2); }
button.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
button.danger:hover { background: #ff5b5b1a; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
select, label:has(input) { cursor: pointer; }
input, select, textarea {
  background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 10px; font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
/* native checks/radios: one size and the accent colour everywhere (pages may enlarge) */
input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px; padding: 0; margin: 0 6px 0 0; vertical-align: -3px;
  accent-color: var(--accent); cursor: pointer;
}
input::placeholder, textarea::placeholder { color: var(--fg-dim); opacity: .8; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
/* keyboard users get the same ring everywhere; mouse clicks don't */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible, .btn:focus-visible { outline-offset: 1px; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--fg-dim); font: 500 11px/1.3 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; }
tbody tr:hover { background: var(--bg2); }
/* long numeric tables: alternate rows so the eye keeps its line */
table.zebra tbody tr:nth-child(even) { background: var(--bg2); }
table.zebra tbody tr:hover { background: var(--bg3); }

/* ---------- nav: the logo wears the bracket; the current page is marked ---------- */
.nav {
  display: flex; align-items: center; gap: 4px; padding: 0 14px; height: 48px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.nav .logo {
  font: 600 15px/1 var(--font-display); color: var(--fg); letter-spacing: .02em;
  padding: 5px 10px; margin-right: 8px; position: relative;
}
.nav .logo::before, .nav .logo::after {
  content: ""; position: absolute; width: 7px; height: 7px; border: 1.5px solid var(--accent);
}
.nav .logo::before { left: 0; top: 0; border-right: 0; border-bottom: 0; }
.nav .logo::after  { right: 0; bottom: 0; border-left: 0; border-top: 0; }
.nav a { color: var(--fg-dim); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
.nav a:hover { color: var(--fg); background: var(--bg3); text-decoration: none; }
.nav a.current { color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 6px 6px 0 0; }
.nav .spacer { flex: 1; }
.nav .who { color: var(--fg-dim); font-size: 13px; padding: 0 4px 0 8px; }
.nav button { padding: 5px 10px; font-size: 13px; }
.nav button.icon { width: 32px; justify-content: center; padding: 0; }
.rolechip {
  display: inline-flex; align-items: center; font: 500 11px/1 var(--font-mono);
  letter-spacing: .04em; padding: 4px 8px; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--line); color: var(--fg-dim);
}

/* ---------- layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 72px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  position: relative; background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 14px 16px; cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.card:hover, .card:focus-visible { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
/* the signature: a bounding-box corner appears on the card you are about to open */
.card::before, .card::after {
  content: ""; position: absolute; width: 10px; height: 10px; opacity: 0;
  border: 2px solid var(--accent); transition: opacity .15s; pointer-events: none;
}
.card::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 3px; }
.card::after  { right: -1px; bottom: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 3px; }
.card:hover::before, .card:hover::after,
.card:focus-visible::before, .card:focus-visible::after { opacity: 1; }
.card h3 { margin: 0 0 6px; }
.muted { color: var(--fg-dim); font-size: 12px; }
.stat { display: inline-block; margin-right: 12px; color: var(--fg-dim); font-size: 12px; }
.stat b { color: var(--fg); font-family: var(--font-mono); font-weight: 500; font-size: 13px; }
.section { margin-top: 30px; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; }
.empty {
  border: 1px dashed var(--line); border-radius: var(--radius-lg); padding: 28px 16px;
  text-align: center; color: var(--fg-dim);
}
.errorcard {
  display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  border: 1px solid var(--bad); border-radius: var(--radius-lg); padding: 14px 16px;
  background: #ff5b5b12; color: var(--fg);
}

/* ---------- class chips + reference hover ---------- */
.classchip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 999px; border: 1.5px solid var(--line); cursor: pointer;
  background: var(--bg3); font-size: 12.5px; white-space: nowrap; user-select: none;
  transition: border-color .15s, background-color .15s;
}
.classchip:hover { border-color: var(--fg-dim); }
.classchip .dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1px #0004 inset; }
.classchip.active {
  border-color: var(--fg);
  box-shadow: 0 0 0 1.5px var(--accent), 0 0 12px 3px var(--accent-soft);
  background: var(--hover);
}
.classchip.newflag { border-color: var(--bad); }
.refpop {
  position: fixed; z-index: 400; background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px; pointer-events: none; box-shadow: var(--shadow);
}
/* hover preview: big enough to read packaging, small enough not to swamp the
   screen. `width` (not max-width) so small source thumbnails still scale up. */
.refpop img { width: min(460px, 34vw); height: auto; max-height: 46vh;
              object-fit: contain; display: block; border-radius: 5px; }
.refpop .cap { font-size: 12px; color: var(--fg-dim); padding: 4px 2px 0; }

/* ---------- image grids ---------- */
.grid-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.imgcard { position: relative; border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; background: var(--bg2); transition: border-color .15s; }
.imgcard:hover { border-color: var(--accent); }
.imgcard img { width: 100%; height: 110px; object-fit: cover; display: block; }
.imgcard .meta { padding: 5px 8px; font: 12px/1.3 var(--font-mono); color: var(--fg-dim); display: flex; justify-content: space-between; }
.imgcard.newclass { border-color: var(--bad); }
.badge { position: absolute; top: 5px; left: 5px; font: 500 11px/1.6 var(--font-mono); letter-spacing: .03em; padding: 0 7px; border-radius: 999px; color: #fff; }
.badge.completed { background: var(--ok); color: #05320f; }
.badge.reviewed { background: var(--accent); color: var(--on-accent); }
.badge.in_progress { background: var(--warn); color: #402800; }
.badge.pending { background: #555c6b; }
.badge.newcls { top: auto; bottom: 28px; background: var(--bad); }

/* ---------- overlays ---------- */
.modal-back { position: fixed; inset: 0; background: #0009; backdrop-filter: blur(2px); z-index: 300; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; min-width: 420px; max-width: 760px; max-height: 84vh; overflow: auto; box-shadow: var(--shadow); animation: rise .16s ease-out; }
.modal h2 { margin-top: 0; }
.modal:focus-visible { outline: none; }   /* the box takes focus on open; only its controls show a ring */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 18px; z-index: 500; box-shadow: var(--shadow); animation: rise .16s ease-out;
}
.toast.err { border-color: var(--bad); color: var(--bad); }

.browser { border: 1px solid var(--line); border-radius: var(--radius); max-height: 380px; overflow: auto; background: var(--bg); }
.browser .entry { padding: 5px 12px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.browser .entry:hover { background: var(--bg3); }
.browser .entry.sel { background: var(--hover); }
#netbar {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent) 40%, var(--accent2) 60%, transparent);
  background-size: 50% 100%; opacity: 0; transition: opacity .15s;
}
#netbar.on { opacity: 1; transition-delay: .25s; animation: netbar 1.1s linear infinite; }
@keyframes netbar { from { background-position: -50% 0; } to { background-position: 150% 0; } }
/* long page tables keep their header visible under the sticky nav */
.page thead th { position: sticky; top: 48px; background: var(--bg); z-index: 1; }
.page .panel thead th, .page .browser thead th { top: 0; background: var(--bg2); }
.progressbar { height: 6px; border-radius: 3px; background: var(--bg3); overflow: hidden; }
.progressbar > div { height: 100%; background: var(--accent); transition: width .3s; }
.kbd { background: var(--bg3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 6px; font-size: 11.5px; color: var(--fg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .card:hover, .card:focus-visible { transform: none; }
}

/* ---------------- touch devices (any width) ---------------- */
@media (pointer: coarse) {
  /* finger-sized targets: 40px rows, 8px between neighbours */
  button, .btn { min-height: 40px; padding: 8px 14px; }
  .nav button, .nav button.icon { min-height: 36px; }
  .nav button.icon { width: 36px; }
  input, select, textarea { min-height: 40px; font-size: 16px; }   /* 16px: iOS does not zoom the page on focus */
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; }
  .classchip { padding: 7px 14px; font-size: 14px; }
  .browser .entry { padding: 10px 12px; }
  .nav a { padding: 10px 12px; }
  .row { gap: 10px; }
}
@media (hover: none) {
  .refpop { display: none !important; }        /* the hover preview has no hover to answer to */
  .card:hover { transform: none; box-shadow: none; }
  .card:hover::before, .card:hover::after { opacity: 0; }
}

/* ---------------- mobile (phones) ---------------- */
@media (max-width: 760px) {
  /* one row that scrolls sideways instead of three wrapped rows */
  .nav { gap: 2px; padding: 0 max(8px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right));
         height: 48px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
         scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .nav > * { flex-shrink: 0; }
  .nav .who, .nav .rolechip { display: none; }
  .nav .logo { margin-right: 4px; }
  .page { padding: 14px max(12px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  h1 { font-size: 20px; }
  .cards { gap: 10px; }
  /* dialogs become bottom sheets: full width, thumb-reachable buttons, scroll inside */
  .modal-back { align-items: flex-end; }
  .modal { min-width: 0; width: 100vw; max-width: 100vw; max-height: 92dvh; padding: 16px 14px calc(14px + env(safe-area-inset-bottom));
           border-radius: 14px 14px 0 0; border-bottom: 0; }
  .modal * { min-width: 0 !important; max-width: 100%; }   /* also defeats the desktop min/width some dialogs set inline */
  .modal-back .modal { animation: sheet .2s ease-out; }
  @keyframes sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
  .toast, #progpill { bottom: calc(16px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
  #progpill { right: 16px; }
  .refpop img { width: min(320px, 78vw); }
  .grid-imgs { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  /* tables scroll sideways inside the page instead of pushing it wider */
  .page table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: 8px 8px; font-size: 13px; white-space: nowrap; }
  .page thead th { position: static; }   /* the nav has no fixed height to pin under */
}
