:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --ink: #1c2a2e;
  --muted: #5d6c70;
  --line: #dedbd0;
  --line-soft: #ebe9e1;
  --brand: #0e6b5c;
  --brand-ink: #ffffff;
  --brand-soft: #e1f0ec;
  --nav: #14262a;
  --nav-ink: #cfdcdb;
  --ok: #1b7a43;      --ok-bg: #e2f3e8;
  --warn: #8a5a00;    --warn-bg: #fdf0d2;
  --bad: #a52a2a;     --bad-bg: #fbe5e3;
  --info: #24527a;    --info-bg: #e3eef8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,38,42,.06), 0 4px 14px rgba(20,38,42,.05);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; line-height: 1.45; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.12rem; } h3 { font-size: 1rem; }
p { margin: .4rem 0; }
a { color: var(--brand); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: #fff; padding: 8px 12px; z-index: 99; }
:focus-visible { outline: 3px solid #5aa6ff; outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.stack { display: grid; gap: 14px; } .stack.tight { gap: 8px; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--nav); color: var(--nav-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.mobilebar, .navscrim, .only-mobile { display: none; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 16px; color: #fff; font-weight: 650; letter-spacing: -.01em; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; font-weight: 800; }
.brand small { display: block; font-weight: 400; color: #8fa6a6; font-size: .72rem; letter-spacing: 0; }
.side nav { display: grid; gap: 2px; }
.side a.nav { color: var(--nav-ink); text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; }
.side a.nav:hover { background: rgba(255,255,255,.07); }
.side a.nav[aria-current="page"] { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; }
.side .spacer { flex: 1; }
.side .who { padding: 10px; font-size: .82rem; color: #8fa6a6; border-top: 1px solid rgba(255,255,255,.1); }
.main { padding: 0 28px 60px; max-width: 1280px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 22px 0 16px; flex-wrap: wrap; }
.topbar .sub { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* ---- surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card > h2 + .sub, .card .sub { color: var(--muted); font-size: .9rem; margin: 4px 0 12px; }
.grid { display: grid; gap: 14px; } .g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat .value { font-size: 1.7rem; font-weight: 680; margin-top: 6px; letter-spacing: -.02em; }
.stat .note { color: var(--muted); font-size: .84rem; margin-top: 2px; }

/* ---- controls ---- */
button, .btn { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; min-height: 38px; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
button:hover, .btn:hover { background: #f4f3ed; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover { background: #0b5a4d; }
button.danger { color: var(--bad); border-color: #e6bcb8; } button.danger:hover { background: var(--bad-bg); }
button.ghost { border-color: transparent; background: transparent; } button.ghost:hover { background: rgba(0,0,0,.05); }
button.small { padding: 4px 10px; min-height: 30px; font-size: .86rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], input[type=tel], select, textarea {
  font: inherit; color: inherit; background: #fff; border: 1px solid #c9c6b9; border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { resize: vertical; line-height: 1.4; }
input:disabled, select:disabled { background: #f0efe9; }
label { display: grid; gap: 5px; font-weight: 600; font-size: .9rem; }
label .hint, .hint { font-weight: 400; color: var(--muted); font-size: .84rem; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--brand); }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; }
.seg { display: inline-flex; border: 1px solid #c9c6b9; border-radius: 9px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 8px 16px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; font-weight: 600; }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #ecebe4; color: #444; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.plain::before { display: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font-size: .88rem; cursor: pointer; display: inline-flex; gap: 6px; }
.chip b { font-weight: 700; } .chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tag { background: var(--brand-soft); color: #0b5a4d; padding: 1px 8px; border-radius: 6px; font-size: .78rem; font-weight: 600; margin-right: 4px; display: inline-block; }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 14px; background: #faf9f5; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfaf6; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fcfbf8; }
.toolbar input[type=search] { max-width: 260px; } .toolbar select { width: auto; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: .88rem; }

/* ---- notices ---- */
.notice { border-radius: 9px; padding: 11px 14px; border: 1px solid; font-size: .92rem; }
.notice.warn { background: var(--warn-bg); border-color: #ecd391; color: #5f3f00; }
.notice.bad { background: var(--bad-bg); border-color: #e9b9b4; color: #7a1d1d; }
.notice.info { background: var(--info-bg); border-color: #bcd3ea; color: #1b3f60; }
.notice.ok { background: var(--ok-bg); border-color: #b6dcc3; color: #14562f; }
.notice strong { display: block; margin-bottom: 2px; }

/* ---- progress ---- */
.bar { height: 10px; background: #e7e5dc; border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .4s; }

/* ---- dialog / toast ---- */
dialog { border: 0; border-radius: 14px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.28); width: min(720px, 94vw); max-height: 92vh; color: var(--ink); }
dialog::backdrop { background: rgba(14,28,31,.5); }
dialog .dhead { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: start; gap: 10px; }
dialog .dbody { padding: 14px 22px; overflow: auto; max-height: calc(92vh - 150px); }
dialog .dfoot { padding: 12px 22px 18px; display: flex; gap: 10px; justify-content: flex-end; }
dialog.wide { width: min(980px, 96vw); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; max-width: min(420px, 92vw); }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: .93rem; }
.toast.bad { background: #7a1d1d; } .toast.ok { background: #14562f; }

/* ---- device ---- */
.qrbox { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: inline-grid; place-items: center; }
.qrbox img { width: 260px; height: 260px; image-rendering: pixelated; }
.devstate { display: flex; align-items: center; gap: 14px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #aaa; flex: none; }
.dot.ok { background: #25a55a; box-shadow: 0 0 0 5px rgba(37,165,90,.18); } .dot.warn { background: #e0a400; } .dot.bad { background: #c9423a; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: .86rem; font-weight: 600; text-decoration: none; color: var(--ink); }
.pill .dot { width: 9px; height: 9px; box-shadow: none !important; }

/* ---- pairing code ---- */
.paircode { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 2.2rem; font-weight: 700; letter-spacing: .18em; background: #fff; border: 2px dashed var(--brand); border-radius: 12px; padding: 14px 18px; text-align: center; color: var(--ink); user-select: all; }

/* ---- bubbles (message preview) ---- */
.phone { background: #e9e2d6; border-radius: 14px; padding: 14px; display: grid; gap: 8px; min-height: 120px; }
.bubble { background: #fff; border-radius: 4px 12px 12px 12px; padding: 8px 12px; max-width: 88%; box-shadow: 0 1px 1px rgba(0,0,0,.1); white-space: pre-wrap; word-break: break-word; font-size: .93rem; }
.bubble.file { display: flex; gap: 10px; align-items: center; background: #f2fbf7; }
.bubble .fileicon { width: 34px; height: 40px; border-radius: 5px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: .65rem; font-weight: 700; flex: none; }
.bubble img.thumb { max-width: 100%; max-height: 180px; border-radius: 6px; display: block; margin-bottom: 6px; }
.bubble .cap { margin-top: 4px; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: .9rem; color: var(--muted); }
.step .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: #ecebe4; font-size: .8rem; }
.step.active { color: var(--ink); border-color: var(--brand); } .step.active .n { background: var(--brand); color: #fff; }
.step.done .n { background: var(--ok); color: #fff; }
.vars button { font-family: ui-monospace, Menlo, monospace; font-size: .82rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: .92rem; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
pre.details { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .8rem; color: var(--muted); max-width: 520px; }

/* ---- login ---- */
.loginwrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 70% -10%, #d7e9e3 0, transparent 60%), var(--bg); }
.logincard { width: min(400px, 100%); }

/* ---- menus (details-based dropdown) ---- */
details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary::after { content: " ▾"; font-size: .8em; }
details.menu[open] > .menupanel { display: grid; }
.menupanel { display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 6px; gap: 2px; }
.menupanel > a, .menupanel > button { border: 0; background: transparent; justify-content: flex-start; width: 100%; color: var(--ink); text-decoration: none; padding: 10px 12px; border-radius: 8px; min-height: 40px; display: flex; align-items: center; }
.menupanel > a:hover, .menupanel > button:hover { background: #f2f1ea; }

/* ---- bulk action bar ---- */
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 14px; background: #eef6f3; border-top: 1px solid #cfe3dc; position: sticky; bottom: 0; z-index: 20; box-shadow: 0 -4px 14px rgba(0,0,0,.08); }
.bulkbar .count { font-weight: 600; margin-right: auto; }

/* ================================ phones and small tablets ================================ */
@media (max-width: 860px) {
  .shell { display: block; }
  .mobilebar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40;
    background: var(--nav); color: #fff; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
  }
  .mobilebar .menubtn { background: transparent; border: 0; color: #fff; font-size: 1.4rem; min-height: 44px; min-width: 44px; justify-content: center; padding: 0; }
  .mobilebar .menubtn:hover { background: rgba(255,255,255,.1); }
  .mobilebar .title { font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobilebar .pill { padding: 4px 10px; font-size: .78rem; }
  .side {
    position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); height: 100dvh;
    transform: translateX(-105%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; box-shadow: 4px 0 24px rgba(0,0,0,.3);
    padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  body.nav-open .side { transform: none; visibility: visible; transition: transform .22s ease, visibility 0s; }
  body.nav-open { overflow: hidden; }
  .navscrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(10,20,22,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.nav-open .navscrim { opacity: 1; pointer-events: auto; }
  .side a.nav { padding: 12px 14px; font-size: 1rem; }
  .side .sidepill { display: none; }
  .main { padding: 0 14px calc(60px + env(safe-area-inset-bottom)); }
  .only-mobile { display: initial; }
}

@media (max-width: 640px) {
  :root { font-size: 15px; }
  h1 { font-size: 1.3rem; }
  .topbar { padding: 16px 0 12px; gap: 10px; }
  .topbar > div:first-child { flex: 1 1 100%; }
  .topbar > .row { flex: 1 1 100%; }
  .topbar > .row > .btn.primary, .topbar > .row > button.primary { flex: 1 1 auto; justify-content: center; }
  .card { padding: 14px; border-radius: 12px; }
  input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], input[type=tel], select, textarea { font-size: 16px; min-height: 44px; }
  button, .btn { min-height: 44px; }
  button.small, .btn.small { min-height: 38px; padding: 6px 12px; }
  .field-row { grid-template-columns: 1fr; }
  .toolbar { padding: 10px 12px; }
  .toolbar input[type=search] { max-width: none; flex: 1 1 100%; }
  .toolbar select { flex: 1 1 45%; }
  .toolbar .grow { display: none; }
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .value { font-size: 1.35rem; }
  .stat .note { font-size: .75rem; }
  .stat .label { font-size: .7rem; }
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1; justify-content: center; text-align: center; padding: 8px 6px; font-size: .9rem; }
  .steps { flex-wrap: nowrap; }
  .step { padding: 5px 10px 5px 6px; font-size: .85rem; }
  .step:not(.active) .lbl { display: none; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; min-height: 36px; align-items: center; }
  .qrbox img { width: min(260px, 70vw); height: min(260px, 70vw); }
  .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; }
  .pager { flex-wrap: wrap; gap: 8px; }
  .bulkbar { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .bulkbar .count { flex: 1 1 100%; }
  .menupanel { position: fixed; left: 10px; right: 10px; top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); min-width: 0; padding: 8px; }
  .menupanel > a, .menupanel > button { min-height: 48px; font-size: 1rem; }
  #toasts { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); max-width: none; }
  pre.details { max-width: 100%; }

  /* dialogs become full-screen sheets */
  dialog, dialog.wide { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog[open] { display: flex; flex-direction: column; }
  dialog .dhead { padding: calc(14px + env(safe-area-inset-top)) 16px 0; }
  dialog .dbody { flex: 1; max-height: none; padding: 12px 16px; }
  dialog .dfoot { border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: #fff; }
  dialog .dfoot button { flex: 1; justify-content: center; }

  /* tables become stacked cards */
  .tablewrap { overflow: visible; }
  .tablewrap table, .tablewrap tbody, .tablewrap tr, .tablewrap td { display: block; width: 100%; }
  .tablewrap thead tr { display: flex; padding: 0; }
  .tablewrap thead th { display: none; }
  .tablewrap thead th.sel { display: flex; align-items: center; gap: 10px; width: 100%; text-transform: none; letter-spacing: 0; font-size: .9rem; padding: 10px 14px; }
  .tablewrap tbody tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .tablewrap tbody tr:last-child { border-bottom: 0; }
  .tablewrap td { border: 0; padding: 4px 0; display: flex; gap: 14px; justify-content: space-between; align-items: flex-start; text-align: right; overflow-wrap: anywhere; }
  .tablewrap td::before { content: attr(data-label); flex: none; max-width: 42%; text-align: left; color: var(--muted); font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; padding-top: 3px; }
  .tablewrap td[data-label=""]::before, .tablewrap td:not([data-label])::before { display: none; }
  .tablewrap td[data-label=""] { justify-content: flex-start; }
  .tablewrap td:empty { display: none; }
  .tablewrap td.num { text-align: right; }
  .tablewrap td.right { justify-content: flex-end; flex-wrap: wrap; padding-top: 8px; }
}
