/* Back office (/admin/). Self-contained; shares the site's colours and type. Light and dark. */

/* Geist for Latin letters and digits (same file and range as landing.css). */
@font-face {
  font-family: 'Geist';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  src: url('/assets/geist-latin.woff2') format('woff2');
}
/* Anuphan for Thai glyphs only. Variable font, weights 100-700. */
@font-face {
  font-family: 'Anuphan';
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC;
  src: url('/assets/anuphan-thai.woff2') format('woff2');
}

:root {
  color-scheme: light;
  --surface: #fff;
  --page: #f8f8f7;
  --hover: #f1f1ef;
  --ink: #202020;
  --ink-secondary: #666661;
  --line: #e7e7e4;
  --line-strong: #d5d5d0;
  --coral: #ac513e;
  --bad: #a2362c;
  --bad-soft: #f8ebe8;
  --bad-line: #e8c9c2;
  --good: #397550;
  --good-soft: #e9f2ec;
  --good-line: #c6dccf;
  --warn: #8a5a00;
  --warn-soft: #f8f1e1;
  --warn-line: #e8d7ad;
  --bar: #3d3d3a;
  --focus: #4b6f9f;
  --primary: #202020;
  --on-primary: #fff;
  --shadow: rgba(0, 0, 0, 0.08);
  --scrim: rgba(32, 32, 32, 0.32);
  --font: 'Geist', 'Anuphan', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface: #1d1d1c;
    --page: #141413;
    --hover: #262625;
    --ink: #ececea;
    --ink-secondary: #a3a39e;
    --line: #2e2e2c;
    --line-strong: #444441;
    --coral: #e08d79;
    --bad: #f08c7c;
    --bad-soft: #3a211d;
    --bad-line: #5c322b;
    --good: #7fc398;
    --good-soft: #1b2e22;
    --good-line: #2e4b39;
    --warn: #e2b660;
    --warn-soft: #33290f;
    --warn-line: #574519;
    --bar: #c9c9c4;
    --focus: #8fb0de;
    --primary: #ececea;
    --on-primary: #141413;
    --shadow: rgba(0, 0, 0, 0.5);
    --scrim: rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
h2 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
}
h3 {
  margin: 24px 0 8px;
  font-size: 13px;
  font-weight: 600;
}
p {
  margin: 0;
}
a {
  color: inherit;
}
.muted {
  color: var(--ink-secondary);
  font-size: 13px;
}
.lead {
  margin: 0 2px 14px;
}
.right {
  text-align: right;
}
.grow {
  flex: 1;
  text-align: right;
}
.spaced {
  margin-top: 12px;
}

/* --- Top bar ------------------------------------------------------------------------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand-period {
  color: var(--coral);
}
.brand-area {
  margin-left: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--line-strong);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 400;
}
.tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tabs button {
  flex: none;
  min-height: 36px;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-secondary);
  font: inherit;
  cursor: pointer;
}
.tabs button:hover {
  background: var(--hover);
}
.tabs button[aria-current='page'] {
  background: var(--hover);
  color: var(--ink);
  font-weight: 600;
}
.top-side {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 24px 64px;
}

.banner {
  margin: 14px 24px 0;
  padding: 10px 14px;
  border: 1px solid var(--bad-line);
  border-radius: 10px;
  background: var(--bad-soft);
  color: var(--bad);
}
.banner.warn {
  border-color: var(--warn-line);
  background: var(--warn-soft);
  color: var(--warn);
}
.drawer .banner,
.card > .banner {
  margin: 12px 0;
}

/* --- Buttons and fields -------------------------------------------------------------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.button:hover {
  background: var(--hover);
}
.button.small {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 13px;
}
.button.danger {
  border-color: var(--bad-line);
  color: var(--bad);
}
.button:disabled {
  opacity: 0.45;
  cursor: default;
}
.button.primary,
.primary-small {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}
.button.primary:hover,
.primary-small:hover {
  background: var(--primary);
  opacity: 0.88;
}
.button.primary {
  margin-top: 18px;
  padding: 11px 14px;
}
.danger-solid {
  border-color: var(--bad);
  background: var(--bad);
  color: var(--on-primary);
}
.danger-solid:hover {
  background: var(--bad);
  opacity: 0.88;
}
.text-button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
input,
select {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- Overview ------------------------------------------------------------------------ */
.status-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 18px;
  padding: 10px 14px;
  border: 1px solid var(--good-line);
  border-radius: 10px;
  background: var(--good-soft);
  color: var(--ink);
  font-size: 13px;
}
.status-line.warn {
  border-color: var(--warn-line);
  background: var(--warn-soft);
}
.status-line.bad {
  border-color: var(--bad-line);
  background: var(--bad-soft);
}
.status-line .text-button {
  margin-left: auto;
  color: var(--ink-secondary);
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.segmented button {
  min-height: 32px;
  padding: 4px 14px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.segmented button[aria-pressed='true'] {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 500;
}
.section-title {
  margin: 24px 2px 10px;
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.section-note {
  margin: -4px 2px 12px;
}

/* --- Cards and tiles ----------------------------------------------------------------- */
.card {
  margin-bottom: 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.card-title {
  margin: 0 0 2px;
  font-size: 14px;
}
.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.grid.two > .card {
  margin-bottom: 0;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  padding: 14px 16px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.tile.link {
  cursor: pointer;
}
.tile.link:hover {
  border-color: var(--line-strong);
}
.tile-label {
  color: var(--ink-secondary);
  font-size: 13px;
}
.tile-value {
  margin: 4px 0 2px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.tile-note {
  color: var(--ink-secondary);
  font-size: 12.5px;
}
.tile.bad {
  border-color: var(--bad-line);
}
.tile.bad .tile-value {
  color: var(--bad);
}

.attention {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
.attention li {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
}
.attention li:first-child {
  border-top: 0;
}
.dot {
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--warn);
}
.status-line .dot {
  margin-top: 0;
}
.dot.good {
  background: var(--good);
}
.dot.bad {
  background: var(--bad);
}

/* --- Charts -------------------------------------------------------------------------- */
.chart {
  margin-top: 12px;
}
.chart svg {
  display: block;
  width: 100%;
  height: 150px;
}
.chart.short svg {
  height: 100px;
}
.chart .bar {
  fill: var(--bar);
}
.chart .bar.zero {
  fill: var(--line);
}
.chart .bar:hover {
  fill: var(--coral);
}
.chart .grid-line {
  stroke: var(--line);
  stroke-width: 1;
}
.chart text {
  fill: var(--ink-secondary);
  font-size: 11px;
  font-family: var(--font);
}
.chart-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  color: var(--ink-secondary);
  font-size: 12px;
}

/* --- Tables -------------------------------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 12px;
}
.toolbar input[type='search'] {
  flex: 1 1 240px;
  max-width: 320px;
}
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
th.right {
  text-align: right;
}
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  white-space: nowrap;
}
td.wrap {
  min-width: 220px;
  white-space: normal;
  overflow-wrap: anywhere;
}
tbody tr[data-user],
tbody tr[data-entry],
tbody tr[data-report] {
  cursor: pointer;
}
tbody tr[data-user]:hover,
tbody tr[data-entry]:hover,
tbody tr[data-report]:hover {
  background: var(--hover);
}
.cell-main {
  font-weight: 500;
}
.cell-sub {
  color: var(--ink-secondary);
  font-size: 12.5px;
}
.meter {
  width: 90px;
  height: 4px;
  margin: 5px 0 0 auto;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  background: var(--bar);
}
.meter.full span {
  background: var(--bad);
}
.empty {
  padding: 22px 0 6px;
  color: var(--ink-secondary);
  text-align: center;
}
.pager {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.chip {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--page);
  color: var(--ink-secondary);
  font-size: 12px;
  white-space: nowrap;
}
.chip.good {
  border-color: var(--good-line);
  background: var(--good-soft);
  color: var(--good);
}
.chip.bad {
  border-color: var(--bad-line);
  background: var(--bad-soft);
  color: var(--bad);
}
.chip.warn {
  border-color: var(--warn-line);
  background: var(--warn-soft);
  color: var(--warn);
}

/* --- Facts --------------------------------------------------------------------------- */
.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 18px;
  margin: 10px 0 0;
}
.facts dt {
  color: var(--ink-secondary);
}
.facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.provider-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 10px;
}
.provider-model {
  color: var(--ink-secondary);
  font-size: 12.5px;
  word-break: break-all;
}
.plain {
  margin: 0;
  padding: 0;
  list-style: none;
}
.plain li {
  padding: 7px 0;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.plain li:first-child {
  border-top: 0;
}
.export-row {
  margin-top: 12px;
}

/* --- Sign-in page and operators -------------------------------------------------------- */
body.sign-in {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 40px;
}
.sign-in-box {
  width: 100%;
  max-width: 380px;
  margin: 0;
  padding: 0;
}
.sign-in-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 22px;
  padding: 24px;
}
.sign-in-form h1 {
  font-size: 20px;
}
.sign-in-form label {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
}
.sign-in-form input {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
}
.sign-in-form .banner {
  margin: 10px 0 0;
}
.operator-forms {
  margin: 4px 0 8px;
}
.operator-forms input,
.operator-forms select {
  width: 170px;
  max-width: 100%;
}

/* --- Drawer -------------------------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 9;
  background: var(--scrim);
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  width: 480px;
  max-width: 100vw;
  padding: 20px 22px 48px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px var(--shadow);
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.drawer-title {
  min-width: 0;
}
.drawer-head h2 {
  font-size: 17px;
  overflow-wrap: anywhere;
}
.mark {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--bad-line);
  border-left: 4px solid var(--bad);
  border-radius: 8px;
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 13px;
}
.mark span {
  overflow-wrap: anywhere;
}
.limit,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.limit input {
  width: 110px;
}

/* --- Confirmation dialog ------------------------------------------------------------- */
.confirm {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 48px var(--shadow);
}
.confirm::backdrop {
  background: var(--scrim);
}
.confirm form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 22px;
}
.confirm h2 {
  font-size: 17px;
}
.confirm-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--ink-secondary);
  overflow-wrap: anywhere;
}
.confirm-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}
.confirm-field input {
  width: 100%;
  font-size: 16px;
}
.confirm-problem {
  color: var(--bad);
  font-size: 13px;
}
.confirm-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 900px) {
  .top {
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 10px 16px 0;
  }
  .tabs {
    order: 3;
    flex-basis: 100%;
    margin: 0 -16px;
    padding: 0 12px 6px;
    overflow-x: auto;
  }
  .top-side {
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
  }
  .top-side .muted {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand-area {
    display: none;
  }
  main {
    padding: 16px 16px 48px;
  }
  .banner {
    margin: 12px 16px 0;
  }
  .grid.two {
    grid-template-columns: minmax(0, 1fr);
  }
  .tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .top-side [data-updated] {
    display: none;
  }
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .tile {
    padding: 12px 13px;
  }
  .tile-value {
    font-size: 22px;
  }
  .card {
    padding: 16px;
  }
  .drawer {
    width: 100vw;
    padding: 16px 16px 48px;
    border-left: 0;
  }
  .page-head h1 {
    font-size: 19px;
  }
  .segmented {
    width: 100%;
  }
  .segmented button {
    flex: 1;
  }
  .toolbar input[type='search'] {
    max-width: none;
  }
  .confirm-buttons .button {
    flex: 1;
  }
}
body.sign-in .brand-area {
  display: inline;
}

/* --- Switches, the log and the model list ---------------------------------------------- */
.switch {
  position: relative;
  width: 34px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--line-strong);
  cursor: pointer;
  vertical-align: middle;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.12s ease;
}
.switch[aria-checked='true'] {
  background: var(--good);
}
.switch[aria-checked='true']::after {
  transform: translateX(14px);
}
.drawer.wide {
  width: 620px;
}
.step {
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.step-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
}
.step-head .muted {
  font-weight: 400;
}
.step .facts {
  margin-top: 6px;
}
.step-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 14px;
}
.app-log {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.bar-row {
  display: flex;
  height: 8px;
  margin: 10px 0 4px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--line);
}
.bar-row span {
  display: block;
  height: 100%;
}
.bar-speech {
  background: var(--bar);
}
.bar-cleanup {
  background: var(--coral);
}
.bar-other {
  background: var(--line-strong);
}
[data-models] input,
[data-models] select,
[data-cleanup-models] input {
  width: 100%;
  min-width: 140px;
}
.model-actions {
  margin: 12px 0 6px;
}
.drawer h3 + p.muted,
.drawer p.muted.spaced {
  margin-bottom: 10px;
}
.status-line {
  flex-wrap: nowrap;
  align-items: flex-start;
}
.status-line > span:nth-child(2) {
  flex: 1;
  min-width: 0;
}
.status-line .dot {
  margin-top: 6px;
}
.status-line .text-button {
  margin-left: 0;
}

/* Phones: the account list and the record read as stacked rows, one label per line. */
@media (max-width: 560px) {
  table.stack thead {
    display: none;
  }
  table.stack tr {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
  }
  table.stack td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 2px 0;
    border: 0;
    text-align: right;
    white-space: normal;
  }
  table.stack td::before {
    content: attr(data-label);
    flex: none;
    color: var(--ink-secondary);
    text-align: left;
  }
  table.stack td:first-child {
    display: block;
    margin-bottom: 4px;
    text-align: left;
  }
  table.stack td:first-child::before {
    content: none;
  }
  table.stack td.wrap {
    min-width: 0;
  }
  table.stack .meter {
    margin-left: auto;
  }
  .table-wrap:has(table.stack) {
    margin: 0;
    padding: 0;
  }
}

[data-support-content] {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.support-triage,
.support-thread,
.support-compose {
  display: grid;
  gap: 8px;
}

.support-triage p,
.support-message p {
  margin: 0;
}

.support-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.support-message {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.support-message.support-note {
  background: var(--page);
}

.support-compose {
  justify-items: start;
  padding-top: 8px;
}

.support-compose label {
  display: grid;
  width: 100%;
  gap: 6px;
}

.support-compose textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}
