/* Aleksandria Triage - developer console
   Visual system ported from aleksandria-memory's admin console: Apple-flavoured
   "systemBlue on white", soft grey panels, generous rounding, a single azure
   accent. System font stack - no bundled webfonts. */

:root {
  --bg: #ffffff;
  --surface: #f2f2f7;
  --surface-2: #fafafc;
  --card: #ffffff;
  --border: #e5e5ea;
  --border-strong: #d6d6dc;

  --fg: #1c1c1e;
  --muted: #8e8e93;

  --accent: #007aff;
  --accent-hover: #0a6fe0;
  --accent-soft: #e7f1ff;

  --ok: #34c759;     --ok-fg: #1b8a3a;   --ok-bg: #e6f8ec;
  --warn: #ff9500;   --warn-fg: #b26b00; --warn-bg: #fff3e2;
  --danger: #ff3b30; --danger-fg: #c8362b; --danger-bg: #ffe9e7;
  --info: #007aff;   --info-fg: #0a6fe0; --info-bg: #e7f1ff;
  --neutral-fg: #6b6b80; --neutral-bg: #eeeef2; --neutral-dot: #c5c5cf;

  --r-card: 16px;
  --r-control: 10px;
  --r-pill: 999px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, 0.18);

  --font: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--fg); }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.021em; margin: 0.2rem 0 1.1rem; }
h2 { font-size: 1.15rem; font-weight: 650; letter-spacing: -0.012em; margin: 1.4rem 0 0.6rem; }
h3 { font-size: 1rem; font-weight: 650; margin: 0 0 0.5rem; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.85em; }

/* ------------------------------ header / nav ------------------------------ */
.admin-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: -0.01em; color: var(--fg); }
.admin-nav { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem; font-size: 0.875rem; }
.admin-nav a {
  color: var(--muted); text-decoration: none; font-weight: 500;
  padding: 0.4rem 0.7rem; border-radius: var(--r-pill);
  transition: background 0.12s ease, color 0.12s ease;
}
.admin-nav a:hover { background: var(--surface); color: var(--fg); }
.admin-nav a.active { background: var(--accent); color: #fff; }
.admin-nav a.active:hover { background: var(--accent-hover); }
.admin-nav .who { margin-left: 0.5rem; margin-right: 0.75rem; padding-left: 0.85rem; border-left: 1px solid var(--border); color: var(--muted); }
.logout-form { margin: 0; }
.admin-nav button { margin-top: 0; }
.admin-main { max-width: 1100px; margin: 1.75rem auto; padding: 0 1.5rem; }

/* ------------------------------ buttons ------------------------------ */
button, .button-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  margin: 0; padding: 0.5rem 1rem;
  background: var(--accent); color: #fff;
  border: 1px solid transparent; border-radius: var(--r-control);
  font: inherit; font-size: 0.9rem; font-weight: 600; line-height: 1.2;
  text-decoration: none; cursor: pointer;
  transition: background 0.12s ease, filter 0.12s ease, border-color 0.12s ease;
}
button:hover, .button-link:hover { background: var(--accent-hover); }
button:active, .button-link:active { filter: brightness(0.96); }
button[disabled] { opacity: 0.45; cursor: not-allowed; background: var(--neutral-dot); }
button.secondary { background: var(--card); color: var(--fg); border-color: var(--border-strong); }
button.secondary:hover { background: var(--surface); }
button.danger, .button-link.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-fg); }
.icon-btn { margin: 0; padding: 0.25rem 0.55rem; background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; font-size: 0.8rem; line-height: 1; }
.icon-btn:hover { background: var(--surface); border-color: var(--accent); color: var(--accent); }

/* ------------------------------ cards ------------------------------ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card); padding: 1.1rem 1.2rem; box-shadow: var(--shadow-card); margin: 0 0 1.1rem; }

/* ------------------------------ status pills ------------------------------ */
.status, .tag {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.18rem 0.6rem; border-radius: var(--r-pill);
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; line-height: 1.4; white-space: nowrap;
}
.status::before, .tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag-ok { background: var(--ok-bg); color: var(--ok-fg); }
.tag-warn { background: var(--warn-bg); color: var(--warn-fg); }
.tag-danger { background: var(--danger-bg); color: var(--danger-fg); }
.tag-info { background: var(--info-bg); color: var(--info-fg); }
.tag-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.tag-neutral::before { background: var(--neutral-dot); }

/* ------------------------------ tables ------------------------------ */
.table-wrap { overflow-x: auto; border-radius: 12px; }
.admin-table { width: 100%; border-collapse: collapse; margin: 0.5rem 0 1.25rem; font-size: 0.875rem; background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table th { background: var(--surface); color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.admin-table tbody tr:hover td { background: var(--surface-2); }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table td a { color: var(--accent); text-decoration: none; }
.admin-table td a:hover { text-decoration: underline; }
.summary-cell { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mono { font-family: var(--mono); font-size: 0.82rem; letter-spacing: 0; color: var(--fg); }
time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted, .hint { color: var(--muted); }
.small { font-size: 0.78rem; }

/* ------------------------------ toolbar / segmented ------------------------------ */
.toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; margin: 0.5rem 0 1rem; }
.toolbar h1, .toolbar h2 { margin: 0; }
.badges { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 0.2rem; background: var(--surface); padding: 0.25rem; border-radius: var(--r-pill); margin: 0.5rem 0 1rem; }
.segmented a { padding: 0.35rem 0.85rem; border-radius: var(--r-pill); color: var(--muted); text-decoration: none; font-size: 0.85rem; font-weight: 600; }
.segmented a:hover { color: var(--fg); }
.segmented a.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow-card); }

/* ------------------------------ login (phase 05 reuses) ------------------------------ */
.login { max-width: 400px; margin: 4.5rem auto; background: var(--card); padding: 2rem; border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.login-hint { max-width: 400px; margin: 0.9rem auto 0; text-align: center; }

/* ------------------------------ stacked forms (login, upload, add-mapping) ------------------------------ */
.stacked-form label { display: block; margin: 0 0 1rem; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.stacked-form label:last-of-type { margin-bottom: 1.1rem; }
.stacked-form input[type="text"],
.stacked-form input[type="email"],
.stacked-form input[type="password"],
.stacked-form input[type="number"],
.stacked-form input[type="file"],
.stacked-form select,
.stacked-form textarea {
  display: block; width: 100%; margin-top: 0.4rem;
  padding: 0.6rem 0.7rem; border: 1px solid var(--border-strong); border-radius: var(--r-control);
  font: inherit; font-size: 0.9rem; background: var(--card); color: var(--fg);
}
.stacked-form textarea { resize: vertical; min-height: 4.5rem; }
.stacked-form input[type="file"] { padding: 0.45rem 0.6rem; background: var(--surface); cursor: pointer; }
.stacked-form button[type="submit"] { width: 100%; margin-top: 0.2rem; }
.upload-card { max-width: 560px; margin: 0 auto; }

/* checkbox groups (Slack routing) + inline row forms */
fieldset { border: 0; margin: 0; padding: 0; }
.chk-group { border: 1px solid var(--border); border-radius: var(--r-control); padding: 0.7rem 0.9rem; margin: 0 0 1.1rem; }
.chk-group legend { padding: 0 0.3rem; font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.chk, .stacked-form .chk { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0.2rem 0.9rem 0.2rem 0; font-size: 0.85rem; font-weight: 400; color: var(--fg); }
.inline-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0; }
.row-actions { display: flex; gap: 0.4rem; }

/* ====================================================================== */
/*  Issue page (phase 04)                                                 */
/* ====================================================================== */

/* action bar: status edit + self-assign */
.actions-card .action-group { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1.25rem; }
.status-form { display: flex; align-items: flex-end; gap: 0.5rem; margin: 0; }
.status-form label, .filter-bar label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.status-form select { padding: 0.45rem 0.55rem; border: 1px solid var(--border-strong); border-radius: var(--r-control); font: inherit; font-size: 0.875rem; background: var(--card); min-width: 9rem; }
.assign-form { margin: 0; }
.assigned-to { margin: 0; align-self: center; color: var(--muted); }

/* triage result grid + per-field feedback */
.result-grid { margin: 0.5rem 0 0; display: grid; gap: 0.1rem; }
.result-grid .field { display: grid; grid-template-columns: 9.5rem 1fr; gap: 0.5rem 1rem; padding: 0.55rem 0; border-top: 1px solid var(--border); }
.result-grid .field:first-child { border-top: 0; }
.result-grid dt { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin: 0; }
.result-grid dd { margin: 0; }
.files { margin: 0; padding-left: 1.1rem; }
.labels { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.3rem 0; }
.proposed-body { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem; margin: 0.4rem 0 0; white-space: pre-wrap; font-size: 0.84rem; max-height: 240px; overflow: auto; }

.feedback-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); font-weight: 500; cursor: pointer; }
.feedback-control { display: none; margin-left: 0.5rem; vertical-align: middle; }
.result-section.feedback-on .feedback-control { display: inline-flex; }
.feedback-form { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; align-items: flex-start; margin: 0; }
.feedback-done { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.72rem; }

.fix-details { display: inline-block; }
.fix-details summary { list-style: none; cursor: pointer; }
.fix-details summary::-webkit-details-marker { display: none; }
.fix-details[open] summary { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.fix-body { display: flex; gap: 0.4rem; align-items: flex-start; margin-top: 0.45rem; }
.fix-body textarea { flex: 1; max-width: 320px; padding: 0.45rem 0.6rem; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit; font-size: 0.82rem; resize: vertical; min-height: 3.2rem; background: var(--card); }
.fix-body button { padding: 0.42rem 0.75rem; font-size: 0.8rem; white-space: nowrap; }

/* message thread + composer */
.thread { max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; padding: 0.4rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.empty-thread { margin: 0.5rem; }
.msg { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; max-width: 80%; }
.msg-developer { align-self: flex-end; background: var(--accent-soft); border-color: #cfe2ff; }
.msg-customer { align-self: flex-start; }
.msg-head { display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.72rem; color: var(--muted); margin-bottom: 0.15rem; }
.msg-head .who { font-weight: 600; }
.msg-body { white-space: pre-wrap; font-size: 0.9rem; }
.composer { display: flex; gap: 0.5rem; margin-top: 0.6rem; align-items: flex-end; }
.composer textarea { flex: 1; padding: 0.5rem 0.6rem; border: 1px solid var(--border-strong); border-radius: var(--r-control); font: inherit; resize: vertical; }

/* metadata + report body */
.kv { display: grid; grid-template-columns: 9rem 1fr; gap: 0.35rem 1rem; margin: 0.3rem 0 0; }
.kv dt { color: var(--muted); font-size: 0.8rem; }
.kv dd { margin: 0; }
.err-preview { color: var(--danger-fg); font-size: 0.82rem; }
pre.report { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem; overflow: auto; max-height: 480px; white-space: pre-wrap; font-size: 0.84rem; }

.copy-feedback { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--fg); color: #fff; padding: 0.45rem 0.9rem; border-radius: var(--r-pill); font-size: 0.82rem; box-shadow: var(--shadow-pop); opacity: 0; transition: opacity 0.15s ease; pointer-events: none; z-index: 50; }
.copy-feedback.show { opacity: 1; }

/* ------------------------------ ergonomics ------------------------------ */
tr[data-href] { cursor: pointer; }
tr[data-href]:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.copy { cursor: pointer; border-bottom: 1px dashed var(--border-strong); }
.copy:hover { color: var(--accent); border-bottom-color: var(--accent); }
.copy.copied { color: var(--ok-fg); border-bottom-color: var(--ok); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 760px) {
  .admin-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; position: static; }
  .result-grid .field { grid-template-columns: 1fr; }
  .msg { max-width: 100%; }
}

/* ------------------------------ audit explorer (phase 10) ------------------------------ */
/* A quiet control strip under the window presets — subordinate to the table, in the
   same input/label vocabulary as .status-form (issue page). */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.55rem 0.9rem; margin: 0.35rem 0 1.1rem; }
.filter-bar input[type="text"], .filter-bar select {
  padding: 0.4rem 0.55rem; border: 1px solid var(--border-strong); border-radius: var(--r-control);
  font: inherit; font-size: 0.85rem; background: var(--card);
}
.filter-bar input[name="action"] { width: 15rem; }
.filter-bar select[name="page_size"] { width: 4.75rem; }
.more-filters { flex-basis: 100%; margin: 0.1rem 0 0; }
.more-filters > summary { display: inline-flex; align-items: center; gap: 0.35rem; width: max-content;
  cursor: pointer; font-size: 0.78rem; color: var(--muted); font-weight: 600; list-style: none; }
.more-filters > summary::-webkit-details-marker { display: none; }
.more-filters > summary::before { content: "\25B8"; font-size: 0.65rem; }   /* ▸ */
.more-filters[open] > summary { color: var(--accent); margin-bottom: 0.55rem; }
.more-filters[open] > summary::before { content: "\25BE"; }                  /* ▾ */
.more-filters label { display: inline-flex; margin: 0 0.9rem 0.35rem 0; }
.more-filters input[type="text"] { width: 11rem; }
.pager { display: flex; align-items: center; gap: 0.9rem; margin: 0.25rem 0 1.25rem; }
.pager a { text-decoration: none; }
/* Export reads as a footer action, set off from the table by a rule. */
.export-form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin: 0.75rem 0 0; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.admin-table .tag { margin: 0 0.15rem 0.15rem 0; }

/* ------------------------------ retention center (phase 10) ------------------------------ */
.banner-ok { background: var(--ok-bg); color: var(--ok-fg); border-radius: var(--r-control); padding: 0.55rem 0.9rem; margin: 0 0 1rem; font-size: 0.875rem; }
.impact { margin: 0.4rem 0 1rem; padding-left: 1.1rem; line-height: 1.7; }
.policy-modal { border: 1px solid var(--border); border-radius: var(--r-card); padding: 1.2rem 1.3rem; max-width: 640px; width: calc(100% - 2rem); box-shadow: var(--shadow-pop); color: var(--fg); background: var(--card); }
.policy-modal::backdrop { background: rgba(0, 0, 0, 0.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.modal-head h3 { margin: 0; }
.policy-modal .admin-table { margin: 0.3rem 0 0.8rem; }
.policy-form { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--border); }
.policy-form label { margin-bottom: 0.7rem; }        /* tighter than the default stacked-form */
.policy-form .row-actions { margin-top: 0.3rem; }
.policy-form button[type="submit"] { width: auto; }  /* not full-width beside Cancel */
#retention-policy-select { padding: 0.45rem 0.6rem; border: 1px solid var(--border-strong); border-radius: var(--r-control); font: inherit; font-size: 0.875rem; background: var(--card); min-width: 15rem; }

/* Rendered problem report (report.html) shown in a sandboxed iframe; white bg so a
   report authored for light rendering stays legible regardless of dashboard theme. */
.report-html { width: 100%; height: 70vh; border: 1px solid var(--border-strong); border-radius: var(--r-card); background: #fff; }
.report-md-fallback { margin-top: 0.75rem; }
.report-md-fallback > summary { cursor: pointer; color: var(--muted); font-size: 0.875rem; }
