/* Order Sync admin panel. No external fonts or assets (strict CSP). */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16191d;
  --muted: #5b6471;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --primary: #3451d1;
  --primary-hover: #2a43b3;
  --primary-soft: #eaeefc;
  --on-primary: #ffffff;
  --danger: #c0282d;
  --danger-hover: #a21f24;
  --danger-soft: #fdecec;
  --on-danger: #ffffff;
  --ok: #18794e;
  --ok-soft: #e4f4eb;
  --warn: #8f5300;
  --warn-soft: #fff3df;
  --bar: #3451d1;
  --bar-2: #d9822b;
  --bar-3: #8c95a3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #161a20;
    --surface-2: #1e232b;
    --text: #e8ebf0;
    --muted: #9ba4b1;
    --border: #282e38;
    --border-strong: #39404c;
    --primary: #8fa2ff;
    --primary-hover: #a9b8ff;
    --primary-soft: #1f2749;
    --on-primary: #0e1014;
    --danger: #ff8080;
    --danger-hover: #ffa0a0;
    --danger-soft: #3b1d20;
    --on-danger: #1a0b0c;
    --ok: #62d39e;
    --ok-soft: #13301f;
    --warn: #f2b65c;
    --warn-soft: #33270f;
    --bar: #8fa2ff;
    --bar-2: #f2a65c;
    --bar-3: #6b7480;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}
body:has(dialog[open]) { overflow: hidden; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 0; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { font-size: 17px; line-height: 1.3; margin: 0; }
h3 { font-size: 12px; margin: 0 0 6px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
p { margin: 0 0 10px; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.main { flex: 1; padding-top: 24px; padding-bottom: 40px; outline: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.block { display: block; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.narrow { max-width: 640px; }

/* ------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 12px;
  font-weight: 750;
}
.brand-sub { color: var(--muted); font-weight: 500; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: var(--radius-sm); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }

/* ------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-danger-outline { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn-icon { min-width: 38px; padding: 6px; font-size: 18px; line-height: 1; }
.btn-block { width: 100%; }

/* --------------------------------------------------------- page layout */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .grow { flex: 1 1 320px; min-width: 0; }
.page-sub { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { display: inline-block; margin-bottom: 10px; font-size: 14px; }
.title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title-row h1 { margin-right: 4px; }
.meta-line { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; color: var(--muted); font-size: 14px; }
.section { margin-top: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card > h2 { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

/* --------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.stats.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat {
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 13px; font-weight: 550; }
.stat-value { margin-top: 2px; font-size: 24px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat-sub { margin-top: 2px; color: var(--muted); font-size: 13px; }
.stat.danger .stat-value { color: var(--danger); }
.stat.good .stat-value { color: var(--ok); }

/* -------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  vertical-align: middle;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cell .badge { margin-left: 6px; }

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

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table-scroll { overflow-x: auto; }
.cell-sub { display: block; color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- bars */

.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-num { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }
.bar { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { display: block; width: 0; height: 100%; border-radius: 999px; background: var(--bar); }
.bar-fill.alt { background: var(--bar-2); }
.bar-fill.dim { background: var(--bar-3); }

/* --------------------------------------------------------------- forms */

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.label, .field label { font-size: 14px; font-weight: 600; }
.input {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.input::placeholder { color: var(--muted); opacity: 0.8; }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 14px; cursor: pointer; }
.check input { flex: none; width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--primary); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.error-text { min-height: 1em; margin: 0 0 12px; color: var(--danger); font-size: 14px; }
.error-text:empty { display: none; }
.notice { margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--primary-soft); font-size: 14px; }
.notice:empty { display: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 260px; width: auto; }
.toolbar select { flex: 0 1 230px; width: auto; }
.list-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.list-foot:empty { display: none; }

/* -------------------------------------------------------------- alerts */

.alert { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 14px; }
.alert p:last-child { margin-bottom: 0; }
.alert strong { display: block; margin-bottom: 2px; }
.alert .btn { margin-top: 8px; }
.alert.warn { background: var(--warn-soft); }
.alert.warn strong { color: var(--warn); }
.alert.danger { background: var(--danger-soft); }
.alert.danger strong { color: var(--danger); }
.alert + .stats, .alert + .section { margin-top: 16px; }
.stack-gap > * + * { margin-top: 14px; }

/* ---------------------------------------------------------- login, keys */

.login { max-width: 440px; margin: 7vh auto 0; padding: 24px; }
.login h1 { margin-bottom: 6px; }

.keybox { display: flex; gap: 8px; margin: 8px 0 16px; }
.keybox .input { min-width: 0; font-family: var(--mono); font-size: 14px; }
.steps { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin: 7px 0; }
.keymsg-wrap { display: grid; gap: 8px; margin: 6px 0 4px; }
.keymsg { min-height: 150px; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.45; }
.keymsg-wrap .btn { justify-self: start; }

/* ----------------------------------------------------- empty, loading */

.empty { padding: 32px 16px; color: var(--muted); text-align: center; }
.empty-title { margin-bottom: 4px; color: var(--text); font-size: 16px; font-weight: 600; }
.empty .btn { margin-top: 6px; }
.loading { display: flex; align-items: center; gap: 10px; margin: 0; padding: 14px 0; color: var(--muted); }
.loading::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading::before { animation-duration: 3s; } }

/* ------------------------------------------------------------- dialogs */

dialog { color: var(--text); }
dialog::backdrop { background: rgba(10, 12, 16, 0.5); }
dialog.modal {
  width: min(500px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-body { padding: 20px 20px 10px; }
.modal-body h2 { margin-bottom: 10px; font-size: 18px; }
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

dialog.drawer {
  width: min(780px, 100vw);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
}
.drawer-inner { min-height: 100%; }
.drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.drawer-title { font-size: 19px; overflow-wrap: anywhere; }
.drawer-body { display: grid; gap: 14px; padding: 16px 18px 40px; }
.drawer-body .card > h2 { font-size: 15px; }

/* --------------------------------------------------------- order detail */

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.addr { margin: 0 0 10px; white-space: pre-line; overflow-wrap: anywhere; }
.note-box { margin-top: 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
}
.timeline li::after {
  content: "";
  position: absolute;
  top: 19px;
  bottom: 0;
  left: 8px;
  width: 1px;
  background: var(--border-strong);
}
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::after { display: none; }
.tl-sub { color: var(--muted); font-size: 13px; }

.notes { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.notes li { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }

.raw {
  max-height: 60vh;
  margin: 10px 0 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre;
}

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

.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(460px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 14px;
  pointer-events: auto;
}
.toast.error { background: var(--danger); color: var(--on-danger); }

.footer { padding: 18px 16px 28px; color: var(--muted); font-size: 13px; text-align: center; }

/* -------------------------------------------------------------- phones */

@media (max-width: 720px) {
  body { font-size: 15px; }
  .main { padding-top: 16px; }
  h1 { font-size: 21px; }
  .card { padding: 14px; }
  .stats, .stats.stats-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 19px; }
  .nav a[data-nav="overview"] { display: none; }
  .brand-sub { display: none; }
  .page-head .actions { width: 100%; }

  /* Tables become stacked cards: each cell shows its column name. */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr { display: block; width: 100%; }
  .table.stack tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table.stack tbody tr:last-child { border-bottom: 0; }
  .table.stack td { display: flex; justify-content: space-between; gap: 14px; padding: 3px 0; border: 0; text-align: right; }
  .table.stack td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 13px; text-align: left; }
  .table.stack td .cell { min-width: 0; }
  .table.stack tr.clickable:hover td { background: transparent; }

  .kv { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  .keybox { flex-direction: column; }
  .nav a[data-nav="docs"] { padding: 6px 8px; }
  .drawer-head { padding: 12px 14px; }
  .drawer-body { padding: 12px 12px 32px; }
}

@media (max-width: 340px) {
  .stats, .stats.stats-3 { grid-template-columns: 1fr; }
}
