/* IRM My — admin PWA styles.
 *
 * Two themes from one token set. Light is the default document theme, dark is
 * applied by the OS preference; no manual switch, so the page always matches
 * the operator's system.
 *
 * Brand anchors are preserved: #14171f / #1f2430 for the dark surfaces and the
 * lavender→mint pair #c9b6ff / #9fe8d8 for the mark and primary action.
 * On white, #c9b6ff measures ~1.7:1, which is unusable for text and focus
 * rings, so the light theme uses the same hue family at a lower lightness
 * (#6d4fd6 / #2f8f7a) and keeps the originals as the gradient stops.
 */

:root {
  color-scheme: light;

  /* Pale ledger paper, not warm cream: same violet family as the dark theme. */
  --paper: #f5f4f8;
  --surface: #ffffff;
  --sunken: #eceaf2;
  --row-alt: #faf9fc;

  --ink: #1b1a22;
  --muted: #5f5b70;
  --line: #ddd9e6;
  --line-strong: #c9c3d8;

  /* Signal colours: focus, selection, the single primary action. */
  --signal: #6d4fd6;
  --signal-soft: #efe9ff;
  --mint: #2f8f7a;

  /* Gradient stops keep the approved brand pair. */
  --brand-a: #c9b6ff;
  --brand-b: #9fe8d8;

  --danger: #b3261e;
  --danger-bg: #fdecea;
  --danger-line: #f2c4c0;
  --ok: #1f6f52;

  --top-bg: rgba(245, 244, 248, 0.94);
  --glow: radial-gradient(1100px 520px at 12% -18%, #e7e1fb 0%, transparent 62%);

  --radius-card: 14px;
  --radius-control: 9px;
  --radius-pill: 999px;

  --step-1: 11.5px;
  --step-2: 13px;
  --step-3: 15px;
  --step-4: 17px;
  --step-5: 21px;
  --step-6: 28px;

  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 26px;

  --ui-font: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui,
    -apple-system, "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --paper: #14171f;
    --surface: #1f2430;
    --sunken: #262c3a;
    --row-alt: #222834;

    --ink: #eef1f7;
    --muted: #a7b0c0;
    --line: #333b4d;
    --line-strong: #43506a;

    --signal: #c9b6ff;
    --signal-soft: #2b2440;
    --mint: #9fe8d8;

    --danger: #ff9a9a;
    --danger-bg: #3a222a;
    --danger-line: #5a3340;
    --ok: #9fe8b8;

    --top-bg: rgba(20, 23, 31, 0.96);
    --glow: radial-gradient(1100px 520px at 10% -10%, #2b2440 0%, transparent 60%);
  }
}

* { box-sizing: border-box; }

/* app.js shows and hides whole sections by toggling [hidden]; the display
 * values below would otherwise win. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--glow), var(--paper);
  color: var(--ink);
  font: var(--step-3) / 1.55 var(--ui-font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* Visible keyboard focus everywhere, including controls inside cards. */
:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: var(--radius-control);
}

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

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  max-width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--top-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(140%) blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: 4px 6px 4px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.brand:hover { border-color: var(--line); }
.brand strong { display: block; font-size: var(--step-4); letter-spacing: -0.01em; }
.brand small { display: block; color: var(--muted); font-size: var(--step-1); }

/* The one place the brand gradient is allowed to shout. */
.mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  color: #1a1c24;
  font-weight: 800;
  font-size: var(--step-4);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  min-width: 0;
}

.muted {
  color: var(--muted);
  font-size: var(--step-2);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

main {
  display: grid;
  gap: var(--space-3);
  width: min(1240px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-5);
}

footer {
  margin-top: auto;
  padding: var(--space-4);
  color: var(--muted);
  font-size: var(--step-1);
  text-align: center;
}

/* ---------- surfaces ---------- */

.card {
  min-width: 0;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.card.narrow {
  width: 100%;
  max-width: 420px;
  margin: var(--space-5) auto;
}

#ticket-detail,
#user-detail { scroll-margin-top: 84px; }

h1,
h2 {
  margin: 0 0 var(--space-2);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h1 { font-size: var(--step-5); font-weight: 650; }
h2 { font-size: var(--step-4); font-weight: 600; }

/* ---------- ledgers strip: four numbers, one surface ---------- */

/* The ledger strip is part of the shell, not the overview page: it stays on
 * every view so the operator can jump between sections from anywhere. */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  font: inherit;
  text-align: left;
  transition: background-color 120ms ease;
}

.stat:first-child { border-left: 0; }
.stat:hover { background: var(--row-alt); }
.stat:active { background: var(--sunken); }

.stat strong,
.dual > strong {
  display: block;
  font-size: var(--step-6);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.stat > span {
  color: var(--muted);
  font-size: var(--step-2);
}

.stat-link { width: 100%; align-items: stretch; }

.dual {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
}

.dual-right {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: var(--step-2);
  text-align: right;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
}

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

label {
  display: grid;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
  color: var(--muted);
  font-size: var(--step-2);
}

input,
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  font: inherit;
  transition: border-color 120ms ease, background-color 120ms ease;
}

input::placeholder,
textarea::placeholder { color: var(--muted); opacity: 0.85; }

input:hover,
select:hover,
textarea:hover { border-color: var(--line-strong); }

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--signal);
  outline-offset: 1px;
}

button {
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}

button:hover { border-color: var(--line-strong); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* One primary per surface: the gradient is the brand, used sparingly. */
.primary {
  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  border-color: transparent;
  color: #1a1c24;
  font-weight: 700;
}

.primary:hover { filter: brightness(1.04); }
.primary:active { filter: brightness(0.97); }

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.ghost:hover { background: var(--sunken); color: var(--ink); }

.danger {
  background: var(--danger-bg);
  border-color: var(--danger-line);
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}

.actions select { width: auto; }

.reply {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-2);
}

.inline > * { flex: 1 1 220px; }

.pager { margin: var(--space-2) 0; }
.pager label { display: flex; align-items: center; gap: var(--space-1); margin: 0; }
.pager select { width: auto; }
.page-actions { display: flex; align-items: center; gap: var(--space-1); }

/* Repeated pager under a long table (50 or 100 rows per page). */
.pager-bottom {
  justify-content: flex-end;
  margin: var(--space-3) 0 0;
  padding-top: var(--space-2);
  border-top: 1px solid var(--line);
}

/* ---------- rows and layout helpers ---------- */

.view {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.row > input,
.row > select {
  flex: 1 1 220px;
  min-width: 0;
}

.row h1 { margin: 0; }

.list { display: grid; gap: var(--space-1); }

.item {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  color: var(--ink);
  font: inherit;
  text-align: left;
}

button.item { cursor: pointer; }
button.item:hover { border-color: var(--line-strong); background: var(--row-alt); }
.item strong { font-weight: 600; }

.item small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--step-2);
}

.chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.chip {
  padding: 5px 11px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: var(--step-2);
}

/* ---------- tables ---------- */

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step-2);
  line-height: 1.35;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: 0.02em;
}

tbody tr { cursor: pointer; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--signal-soft); }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- messages ---------- */

.message {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  font-size: var(--step-2);
}

.message.error { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.message.ok { color: var(--ok); }

.messages {
  display: grid;
  gap: var(--space-1);
  max-height: 420px;
  overflow: auto;
  padding-right: 4px;
}

.msg {
  padding: var(--space-2) var(--space-3);
  background: var(--sunken);
  border: 1px solid transparent;
  border-left: 2px solid var(--line-strong);
  border-radius: var(--radius-control);
}

/* Staff replies read as the answering side of the thread. */
.msg.staff {
  background: var(--signal-soft);
  border-left-color: var(--signal);
}

.msg small {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: var(--step-1);
}

/* ---------- narrow screens ---------- */

@media (max-width: 560px) {
  main { padding: var(--space-3) 12px var(--space-5); }
  .top { padding: var(--space-2) 12px; }
  .card { padding: var(--space-3); }
  #admin-email { display: none; }
  .top-actions button { padding: 7px 10px; font-size: var(--step-2); }
  h1 { font-size: var(--step-4); }
  .stat { padding: var(--space-2) var(--space-3); }
  .stat strong,
  .dual > strong { font-size: var(--step-5); }
  th,
  td { padding: 8px; }
  .dual { flex-direction: column; gap: 2px; }
  .dual-right { text-align: left; white-space: normal; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- forced colours ---------- */

@media (forced-colors: active) {
  .card,
  .stat,
  .item,
  .msg,
  input,
  select,
  textarea,
  button { border: 1px solid CanvasText; }

  .primary { background: Highlight; color: HighlightText; }
}
