/*
 * The same Nocturne palette the phone uses, so the two do not look like
 * different products. The values are copied rather than imported because a
 * stylesheet cannot read TypeScript — packages/shared/src/theme.ts is the
 * source, and these must be changed together.
 */
:root {
  --bg: #161826;
  --panel: #1b1e2e;
  --raised: #22263a;
  --text: #e9e9ed;
  --n300: #cfd3e5;
  --n400: #b2b6ca;
  --n500: #9397ab;
  --n600: #75798c;
  --n700: #595d6c;
  --accent: #9184d9;
  --a200: #e7e5fe;
  --a300: #d2cefd;
  --a700: #5d5294;
  --a800: #423a6a;
  --a900: #2b2741;
  --good: #9fe0b8;
  --bad: #f0a6a6;
  --warn: #d2cefd;
  --hairline: rgba(233, 233, 237, 0.07);
  --border: rgba(233, 233, 237, 0.15);
  --radius: 10px;
}

/*
 * Light, for a laptop by a window. Every colour above has a counterpart here,
 * so a screen written against the tokens works in both without knowing which
 * one it is in — and the text tones are darkened rather than merely inverted,
 * because grey-on-white at the same lightness as grey-on-black is unreadable.
 */
:root[data-theme='light'] {
  --bg: #f6f6fa;
  --panel: #ffffff;
  --raised: #f0f0f6;
  --text: #16161c;
  --n300: #4a4d5c;
  --n400: #5d6070;
  --n500: #6c6f7e;
  --n600: #83869a;
  --n700: #a6a9ba;
  --accent: #5a4cae;
  --a200: #3b3178;
  --a300: #4a3f94;
  --a700: #b5abfc;
  --a800: #e7e5fe;
  --a900: #f0eeff;
  --good: #1d7a4a;
  --bad: #b23a3a;
  --warn: #4a3f94;
  --hairline: rgba(22, 22, 28, 0.08);
  --border: rgba(22, 22, 28, 0.18);
}

* { box-sizing: border-box; }

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

h1 { font-size: 22px; font-weight: 500; margin: 0; }
h2 { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--n500); margin: 0 0 12px; }
a { color: inherit; text-decoration: none; }

.muted { color: var(--n500); margin: 2px 0 0; }
.small { font-size: 11.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--n600); padding: 28px 0; text-align: center; }

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

#root { display: flex; min-height: 100vh; }

.sidebar {
  width: 212px;
  flex: 0 0 212px;
  border-right: 1px solid var(--hairline);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; }
.brand__mark { width: 34px; height: 34px; border-radius: 8px; }
.brand strong { display: block; font-size: 13.5px; }
.brand span { display: block; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item {
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--n400);
  font-size: 13.5px;
}
.nav__item:hover { background: var(--hairline); color: var(--text); }
.nav__item--on { background: var(--a900); color: var(--a200); }

.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }

.content { flex: 1; min-width: 0; padding: 22px 26px 60px; display: flex; flex-direction: column; gap: 18px; }

.page__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* -------------------------------------------------------------- pieces -- */

.panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 16px 18px;
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card__label { font-size: 11.5px; color: var(--n500); text-transform: uppercase; letter-spacing: 0.06em; }
.card__value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card__value--good { color: var(--good); }
.card__value--bad { color: var(--bad); }
.card__value--warn { color: var(--warn); }
.card__detail { font-size: 11.5px; color: var(--n600); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* --------------------------------------------------------------- table -- */

.table-wrap { overflow-x: auto; margin: 0 -18px -16px; padding: 0 18px 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--n600);
  padding: 0 10px 8px;
  white-space: nowrap;
}
.table td { padding: 9px 10px; border-top: 1px solid var(--hairline); vertical-align: top; }
.table tr:hover td { background: var(--hairline); }
.table tr.clickable { cursor: pointer; }
.row--group td {
  background: var(--raised);
  color: var(--n400);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  padding: 6px 10px;
}
.row--group:hover td { background: var(--raised); }
.row--muted td { opacity: 0.55; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn + .btn { margin-left: 6px; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 10.5px;
  color: var(--n400);
  vertical-align: middle;
}
.tag--warn { border-color: var(--a700); color: var(--a300); background: var(--a900); }

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

.btn {
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--hairline); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--primary { background: var(--a800); border-color: var(--a700); color: var(--a200); }
.btn--primary:hover:not(:disabled) { background: var(--a700); }
.btn--ghost { border-color: transparent; color: var(--n400); }
.btn--ghost:hover:not(:disabled) { color: var(--text); }
.btn--danger { color: var(--bad); border-color: rgba(240, 166, 166, 0.25); }
.btn--danger:hover:not(:disabled) { background: rgba(240, 166, 166, 0.09); }
.btn--small { padding: 4px 9px; font-size: 11.5px; }
.btn--block { width: 100%; }
.btn--active { background: var(--a800); border-color: var(--accent); color: var(--a200); }

.chips { gap: 6px; }
.chip {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--n300);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.chip--on { border-color: var(--accent); background: var(--a800); color: var(--a200); }

.input {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  min-width: 0;
}
.input:focus { outline: 2px solid var(--a700); outline-offset: -1px; }
.input--date { color-scheme: dark; }
:root[data-theme='light'] .input--date { color-scheme: light; }
.input--select { padding-right: 26px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field__label { font-size: 11.5px; color: var(--n500); text-transform: uppercase; letter-spacing: 0.06em; }
.check { display: flex; align-items: center; gap: 8px; color: var(--n300); margin-bottom: 14px; }
.form__error { color: var(--bad); font-size: 12.5px; min-height: 18px; margin: 0 0 6px; }

/* --------------------------------------------------------------- chart -- */

.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; }
.chart__col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; }
.chart__bar { width: 100%; max-width: 44px; background: var(--a800); border-radius: 5px 5px 2px 2px; cursor: pointer; }
.chart__bar:hover { background: var(--a700); }
.chart__bar--loss { background: rgba(240, 166, 166, 0.35); }
.chart__bar--active { background: var(--accent); }
.chart__label { font-size: 10.5px; color: var(--n600); }

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar__head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.bar__track { height: 6px; border-radius: 3px; background: var(--hairline); margin: 5px 0 3px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--accent); border-radius: 3px; }

.qr { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.qr__img { background: #fff; padding: 12px; border-radius: var(--radius); }

/* ------------------------------------------------------------ sign-in --- */

.signin { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.signin__card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
}
.signin__mark { width: 62px; height: 62px; border-radius: 14px; margin-bottom: 12px; }
.signin__form { margin-top: 18px; text-align: left; }
.signin__card .btn + .btn { margin-top: 8px; }

/* -------------------------------------------------------------- dialog -- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 16, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 40;
}
.dialog {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
}
.dialog__actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* -------------------------------------------------------------- toasts -- */

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  max-width: 320px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.toast--error { border-color: rgba(240, 166, 166, 0.4); color: var(--bad); }
.toast__close { background: none; border: 0; color: inherit; cursor: pointer; margin-left: 8px; font-size: 15px; }

/* --------------------------------------------------------------- phone -- */

@media (max-width: 760px) {
  #root { flex-direction: column; }
  .sidebar {
    width: auto;
    flex: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
    flex-direction: row;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
    padding: 12px 14px;
  }
  .nav { flex-direction: row; gap: 4px; }
  .sidebar__foot { margin: 0; flex-direction: row; }
  .content { padding: 16px 14px 40px; }
  .table-wrap { margin: 0 -18px -16px; }
}

/* ------------------------------------------------------ table QR cards -- */

.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.qr-card {
  background: #fff;
  color: #111;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  break-inside: avoid;
}
.qr-card__table { font-size: 19px; font-weight: 700; }
.qr-card__img { width: 100%; max-width: 190px; }
.qr-card__hint { font-size: 11px; color: #555; }

/*
 * Printing drops everything but the cards. A sheet of QR codes with a sidebar
 * and a dark background down one edge wastes ink and looks like a mistake.
 */
@media print {
  .sidebar, .page__head, .no-print, #toasts { display: none !important; }
  html, body { background: #fff; color: #111; }
  .content { padding: 0; }
  .qr-sheet { grid-template-columns: repeat(2, 1fr); gap: 10mm; }
  .qr-card { border: 1px solid #ddd; }
}

/* ------------------------------------------------------------- stages -- */

.stages { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.stage {
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--hairline); color: var(--n600);
}
.stage--done { border-color: var(--a700); background: var(--a900); color: var(--a300); }
.stage--now { border-color: var(--accent); background: var(--a800); color: var(--a200); font-weight: 600; }
.stage__arrow { color: var(--n700); font-size: 11px; }

/* A dot that says how long something has been waiting, at a glance. */
.age { font-variant-numeric: tabular-nums; }
.age--old { color: var(--bad); font-weight: 600; }

.detail dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--n500); margin-top: 12px; }
.detail dd { margin: 3px 0 0; font-size: 14px; }
