@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500;600&display=swap");

/*
 * What every admin page shares: the colours and sizes (one set of tokens,
 * in a dark and a light theme, so the pages cannot drift apart), and the
 * frame: a bar along the top with the three parts of the site (เครื่อง,
 * รายการ, ตั้งค่า), what the system is doing now (broker, partners, today's
 * money, the clock), and under it the pages of the part that is open.
 *
 * The theme is the `data-theme` attribute on <html>, set before the page
 * paints by one line in each page's <head>: dark unless this browser was
 * told otherwise (localStorage `sc.theme`). Classes here are specific
 * enough to beat the pages' element rules (button, dialog, h2).
 */

:root {
  color-scheme: dark;
  --paper: #0A0E13; --surface: #10161E; --sunken: #0C1118; --raised: #18212B; --bar: #0E131A;
  --ink: #E8EEF4; --muted: #9FB0C0; --faint: #7D8D9C;
  --border: #25303C; --grid: #1A232D;
  --primary: #38BDF8; --primary-strong: #7DD3FC; --on-primary: #06202E; --primary-wash: #0E2A3A;
  --good: #4ADE80; --bad: #F87171; --warn: #FBBF24; --idle: #7DD3FC;
  --good-wash: #0F3D2A; --bad-wash: #4A1714; --warn-wash: #33270B; --quiet-wash: #18212B;
  --good-ink: #D6FBE6; --bad-ink: #FFE1DD; --warn-ink: #FDEFC8; --on-bad: #2A0806;
  --pick: #0E2A3A; --seg-on: #2B3746;
  --radius: 10px; --radius-s: 8px;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --paper: #EEF2F5; --surface: #FFFFFF; --sunken: #F5F7F9; --raised: #FFFFFF; --bar: #FFFFFF;
  --ink: #0E1620; --muted: #4E5B69; --faint: #74808D;
  --border: #D3DAE1; --grid: #E5EAEF;
  --primary: #0B6FA8; --primary-strong: #085580; --on-primary: #FFFFFF; --primary-wash: #DDEFFA;
  --good: #15703F; --bad: #B3261E; --warn: #8A5300; --idle: #0B6FA8;
  --good-wash: #DBF3E4; --bad-wash: #FCE3E0; --warn-wash: #FCEEC6; --quiet-wash: #E9EEF2;
  --good-ink: #0B4F2B; --bad-ink: #7F1A13; --warn-ink: #6B4000; --on-bad: #FFFFFF;
  --pick: #DDEFFA; --seg-on: #FFFFFF;
}

.shell { display: flex; flex-direction: column; min-height: 100vh; }
.shell-main { flex: 1; min-width: 0; padding: 1.25rem 1.75rem 3rem; }

.shell-nav {
  position: sticky; top: 0; z-index: 40; flex: none;
  background: var(--bar); color: var(--ink); border-bottom: 1px solid var(--border);
  font-size: .95rem; line-height: 1.45;
}
.shell-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0 1.4rem; min-height: 3.6rem; padding: 0 1.75rem; }
.shell-logo { color: var(--ink); font-size: 1.08rem; font-weight: 700; letter-spacing: .01em; text-decoration: none; white-space: nowrap; }

.shell-tabs { display: flex; align-self: stretch; gap: .15rem; }
.shell-tab {
  position: relative; display: flex; align-items: center; gap: .45rem; min-height: 3.6rem; padding: 0 1rem;
  color: var(--muted); font-size: 1rem; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.shell-tab:hover { color: var(--ink); }
.shell-tab[aria-current="page"] { color: var(--ink); font-weight: 600; box-shadow: inset 0 -3px 0 var(--primary); }
/* A dot, not a number: it says "look at the machines page", which lists what waits. */
.shell-badge { flex: none; width: .55rem; height: .55rem; border-radius: 50%; background: var(--bad); font-size: 0; }
.shell-badge[hidden] { display: none; }

.shell-spacer { flex: 1; }
.shell-stats { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem 1.4rem; min-height: 3.6rem; }
.shell-stat { display: inline-flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .88rem; white-space: nowrap; text-decoration: none; }
a.shell-stat:hover { color: var(--ink); }
.shell-dot { flex: none; width: .5rem; height: .5rem; border-radius: 50%; background: var(--faint); }
.shell-dot.on { background: var(--good); }
.shell-dot.warn { background: var(--warn); }
.shell-dot.bad { background: var(--bad); }
.shell-total { display: inline-flex; align-items: baseline; gap: .5rem; color: var(--muted); font-size: .88rem; white-space: nowrap; text-decoration: none; }
.shell-total b { font-family: var(--mono); font-size: 1.45rem; font-weight: 600; color: var(--ink); line-height: 1; }
.shell-clock { font-family: var(--mono); font-size: 1rem; font-weight: 500; color: var(--muted); white-space: nowrap; }
.shell-icon-button {
  display: grid; place-items: center; width: 2.5rem; height: 2.5rem; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-s);
  background: none; color: var(--muted); cursor: pointer;
}
.shell-icon-button:hover { color: var(--ink); border-color: var(--faint); }
.shell-icon-button svg { width: 1.15rem; height: 1.15rem; }
.shell-tools { display: flex; align-items: center; gap: .5rem; }

.shell-sub { display: flex; align-items: center; gap: .25rem; padding: .4rem 1.75rem; border-top: 1px solid var(--grid); overflow-x: auto; }
.shell-sub[hidden] { display: none; }
.shell-sublink {
  display: inline-flex; align-items: center; min-height: 2.1rem; padding: 0 .8rem; border-radius: var(--radius-s);
  color: var(--muted); font-size: .92rem; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.shell-sublink:hover { color: var(--ink); }
.shell-sublink[aria-current="page"] { background: var(--quiet-wash); color: var(--ink); font-weight: 600; }
.shell-sub .shell-spacer { min-width: 1rem; }
.shell-user { color: var(--faint); font-size: .85rem; white-space: nowrap; }
.shell-sub .shell-button {
  display: inline-flex; align-items: center; min-height: 2.1rem; padding: 0 .6rem; border: 0; border-radius: var(--radius-s);
  background: none; color: var(--muted); font: inherit; font-size: .88rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.shell-sub .shell-button:hover { color: var(--ink); text-decoration: underline; }

.shell-tab:focus-visible, .shell-sublink:focus-visible, .shell-stat:focus-visible, .shell-total:focus-visible,
.shell-button:focus-visible, .shell-logo:focus-visible, .shell-icon-button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: -2px;
}

/*
 * The pages that keep their own <style> (sales, the management page, users,
 * the account, service fees) wear the control-room look through this: full
 * width, compact headings, panels, sunken table heads. Their <body> carries
 * `classic`; the scope beats their element and one-class rules, and leaves
 * their more specific ones alone.
 */
/* One column that never grows past the screen: a grid's own column would widen to its widest table or row of buttons. */
.classic .wrap { max-width: 1680px; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.classic header { align-items: center; }
.classic h1 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .75rem; font-size: 1.25rem; font-weight: 700; line-height: 1.35; }
.classic h1 small { display: inline; font-size: .88rem; font-weight: 400; color: var(--muted); }
.classic .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; }
.classic .card h2 { font-size: .98rem; font-weight: 600; margin-bottom: .7rem; }
.classic input:not([type="checkbox"]):not([type="radio"]), .classic select, .classic textarea {
  background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-s); color: var(--ink);
}
.classic table { font-size: .92rem; }
.classic th { background: var(--sunken); font-size: .8rem; font-weight: 500; color: var(--muted); padding: .5rem .7rem; border-bottom: 1px solid var(--border); }
.classic td { padding: .55rem .7rem; border-bottom: 1px solid var(--grid); }
.classic .mono { font-family: var(--mono); }
.classic dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 12px; }
/* Two columns on a wide screen: what is worked on at the left, what is looked up at the right. */
@media (min-width: 1180px) {
  .classic .wrap.cols { grid-template-columns: minmax(0, 1fr) minmax(22rem, 30rem); grid-auto-flow: dense; align-items: start; }
  .classic .wrap.cols > * { grid-column: 1 / -1; }
  .classic .wrap.cols > .col-main { grid-column: 1; }
  .classic .wrap.cols > .col-side { grid-column: 2; }
  /* A tall side panel runs beside two rows of the main column, so nothing under the first is pushed down. */
  .classic .wrap.cols > .col-side.tall { grid-row: span 2; }
}

@media (max-width: 860px) {
  .shell-main { padding: 1rem .9rem 3rem; }
  .shell-bar { padding: 0 .9rem; gap: 0 .6rem; }
  .shell-tab { min-height: 3.1rem; padding: 0 .7rem; }
  .shell-stats { min-height: 0; padding: 0 0 .5rem; gap: .2rem 1rem; flex-basis: 100%; }
  .shell-clock { display: none; }
  .shell-sub { padding: .35rem .9rem; }
}

@media print {
  .shell-nav { display: none !important; }
  .shell-main { padding: 0; }
}
