/* ui.css — shared design system for the operator admin (admin/) and the tenant portal
   (portal/). Light by default, dark when the device prefers it. Mobile-first. */

:root {
  color-scheme: light;
  --bg: #f5f6f8;            /* page */
  --surface: #ffffff;       /* cards */
  --surface-2: #f1f3f6;     /* inputs, wells */
  --line: #e3e6eb;
  --fg: #111418;            /* primary ink */
  --fg-2: #4a4f57;          /* secondary ink */
  --muted: #6b7079;
  --accent: #1f63d6;
  --accent-hover: #1a55b8;
  --accent-fg: #ffffff;
  --accent-soft: #e9f0fd;
  /* status (dataviz status palette; always shown with an icon + label) */
  --good: #0ca30c;   --good-ink: #067406;   --good-soft: #e8f6e8;
  --warn: #fab219;   --warn-ink: #7a5000;   --warn-soft: #fff5dc;
  --bad: #d03b3b;    --bad-ink: #b32626;    --bad-soft: #fdecec;
  /* charts (dataviz reference palette, validated light) */
  --chart-surface: #fcfcfb; --grid: #e1e0d9; --axis: #c3c2b7;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --shadow: 0 1px 2px rgba(17, 20, 24, .04), 0 1px 1px rgba(17, 20, 24, .03);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --line: #2c2c2a;
    --fg: #f0efec; --fg-2: #c3c2b7; --muted: #8f8d87;
    --accent: #4b8bf0; --accent-hover: #6a9ff3; --accent-fg: #0b1220; --accent-soft: #1b2638;
    --good-ink: #3fcf3f; --good-soft: #142414;
    --warn-ink: #fab219; --warn-soft: #2a2210;
    --bad-ink: #ef7373;  --bad-soft: #2b1616;
    --chart-surface: #1a1a19; --grid: #2c2c2a; --axis: #383835;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 22px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 650; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2);
       padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- layout --------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface);
          border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 0 16px; height: 56px;
                display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--fg);
         white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
              background: var(--accent); color: var(--accent-fg); font-size: 16px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav { margin-left: auto; display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: var(--fg-2); padding: 7px 12px; border-radius: 8px; font-weight: 550;
         font-size: 14px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
main, .container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
             flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; margin-bottom: 10px; }

/* bottom tab bar (portal, phones) */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex;
          background: var(--surface); border-top: 1px solid var(--line);
          padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
            padding: 8px 4px 9px; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.tabbar a .ico { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--accent); }
.tabbar a:hover { text-decoration: none; }
.has-tabbar main { padding-bottom: 96px; }
@media (min-width: 768px) {
  .tabbar { display: none; }
  .has-tabbar main { padding-bottom: 32px; }
}
@media (max-width: 767px) { .nav.hide-mobile { display: none; } }

/* ---- surfaces --------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
@media (min-width: 768px) { .card { padding: 20px 22px; } }
.card > h3:first-child, .card-title { margin: 0 0 12px; font-size: 16px; font-weight: 650;
        display: flex; align-items: center; gap: 8px; }
.card-sub { color: var(--muted); font-size: 13px; margin: -8px 0 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 240px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 20px; }
.kv .k { font-size: 12.5px; color: var(--muted); }
.kv .v { font-weight: 550; overflow-wrap: anywhere; }

/* stat tiles */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); margin-bottom: 16px; }
@media (min-width: 768px) { .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
       padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.kpi .hint { font-size: 12.5px; color: var(--fg-2); }

/* status chips (icon + label, never colour alone) */
.chip, .pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
               border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 1.4;
               background: var(--surface-2); color: var(--fg-2); white-space: nowrap; }
.chip::before, .pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%;
               background: var(--muted); flex: none; }
.chip.ok, .pill.ok { background: var(--good-soft); color: var(--good-ink); }
.chip.ok::before, .pill.ok::before { background: var(--good); }
.chip.warn, .pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip.warn::before, .pill.warn::before { background: var(--warn); }
.chip.bad, .pill.bad { background: var(--bad-soft); color: var(--bad-ink); }
.chip.bad::before, .pill.bad::before { background: var(--bad); }
.chip.none::before, .pill.none::before { background: var(--line); }
.chip.lg { font-size: 14px; padding: 5px 12px; }
.status-live { color: var(--good-ink); font-weight: 600; }
.status-paused { color: var(--warn-ink); font-weight: 600; }
.status-draft, .status-provisioned { color: var(--muted); font-weight: 600; }
.ok:not(.chip):not(.pill) { color: var(--good-ink); }
.bad:not(.chip):not(.pill) { color: var(--bad-ink); }

/* banners */
.banner { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 550;
          background: var(--good-soft); color: var(--good-ink); border: 1px solid transparent; }
.banner.err { background: var(--bad-soft); color: var(--bad-ink); }
.banner.info { background: var(--accent-soft); color: var(--accent); }

/* ---- controls --------------------------------------------------------------- */
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
               background: var(--accent); color: var(--accent-fg); border: 1px solid transparent;
               border-radius: 9px; padding: 9px 16px; min-height: 40px; font: inherit;
               font-weight: 600; font-size: 14.5px; cursor: pointer; text-decoration: none;
               white-space: nowrap; }
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--fg);
               border-color: var(--line); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); }
.btn-danger, button.btn-danger { background: var(--surface); color: var(--bad-ink);
               border: 1px solid var(--bad); }
.btn-danger:hover, button.btn-danger:hover { background: var(--bad-soft); }
.btn.sm, button.sm { min-height: 34px; padding: 6px 12px; font-size: 13.5px; }
.btn.block, button.block { width: 100%; }
button:disabled { opacity: .6; cursor: progress; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 550; color: var(--fg-2); margin: 12px 0 5px; }
input[type=text], input[type=password], input[type=date], input[type=search], input[type=tel],
input[type=email], input[type=number], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); color: var(--fg);
  border-radius: 9px; padding: 9px 11px; min-height: 42px; font: inherit; font-size: 16px; }
@media (min-width: 768px) {
  input[type=text], input[type=password], input[type=date], input[type=search], input[type=tel],
  input[type=email], input[type=number], select, textarea { font-size: 15px; }
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft);
  border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 13.5px; line-height: 1.5; }
input[type=file] { font: inherit; max-width: 100%; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg a { padding: 6px 12px; border-radius: 8px; color: var(--fg-2); font-weight: 600; font-size: 13.5px; }
.seg a:hover { text-decoration: none; background: var(--surface); }
.seg a.active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }

/* ---- tables (become cards on phones) ---------------------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line);
         vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase;
     letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px;
                        margin-bottom: 10px; background: var(--surface); }
  table.responsive td { border: 0; padding: 6px 0; display: flex; justify-content: space-between;
                        align-items: center; gap: 12px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px;
                                font-weight: 600; text-align: left; }
  table.responsive td[data-label=""]::before { content: none; }
  table.responsive td.primary { font-size: 15.5px; }
}

/* ---- misc --------------------------------------------------------------- */
pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
      padding: 12px; overflow: auto; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; }
.spinner { display: inline-block; width: 16px; height: 16px; vertical-align: -3px;
           border: 2px solid var(--line); border-top-color: var(--accent);
           border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
.loading-box { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 24px 4px; }
.qr { background: #fff; color: #000; font-family: var(--mono); line-height: 1.0; font-size: 9px;
      letter-spacing: 0; padding: 14px; width: max-content; max-width: 100%; overflow: auto;
      border-radius: 10px; margin: 0 auto; }
@media (min-width: 480px) { .qr { font-size: 11px; } }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0;
             border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
          background: var(--accent-soft); color: var(--accent); font-weight: 650; flex: none; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat bubbles (portal transcript view) */
.thread { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap;
          overflow-wrap: anywhere; font-size: 14.5px; }
.bubble.in { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble .meta { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* charts */
.chart { position: relative; background: var(--chart-surface); border-radius: 10px; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--fg-2); margin-bottom: 8px; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 3px;
               margin-right: 6px; vertical-align: -1px; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); color: var(--fg);
           border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px;
           box-shadow: 0 4px 16px rgba(0, 0, 0, .12); white-space: nowrap; z-index: 5; display: none; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row strong { min-width: 18px; }
.tooltip .t-line { display: inline-block; width: 12px; height: 2px; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; }
details[open] > summary { margin-bottom: 10px; }

/* narrow phones: logo only, compact nav, so the menu never gets cut off */
@media (max-width: 520px) {
  .topbar-inner { gap: 8px; }
  .brand > span:not(.brand-mark) { display: none; }
  .nav a { padding: 6px 9px; font-size: 13.5px; }
}
