/* admin_kit web panel — mobile-first, no external assets. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c1f24;
  --muted: #667085;
  --border: #dde1e7;
  --primary: #2a7ae2;
  --primary-text: #ffffff;
  --danger: #d63b3b;
  --ok-bg: #e7f6ec;
  --ok-text: #17663a;
  --err-bg: #fdecec;
  --err-text: #9b1c1c;
  --warn-bg: #fff6e0;
  --warn-text: #7a5300;
  --on: #1f9d55;
  --off: #9aa3af;
  --bar: #2a7ae2;
  --bar-2: #1f9d55;
  --radius: 12px;
  --gap: 12px;
  --tap: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --text: #e8eaed;
    --muted: #9aa3af;
    --border: #2e333c;
    --primary: #4c93f0;
    --danger: #ef5f5f;
    --ok-bg: #12301f;
    --ok-text: #7fd6a2;
    --err-bg: #3a1717;
    --err-text: #f4a3a3;
    --warn-bg: #3a2d10;
    --warn-text: #f1cf7a;
    --on: #38c172;
    --off: #6b7280;
    --bar: #4c93f0;
    --bar-2: #38c172;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 20px 0 10px; }
h3 { font-size: 1rem; margin: 14px 0 8px; }
p { margin: 8px 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: .88em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
[hidden] { display: none !important; }

/* --- top bar & nav ------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; min-height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who-name { color: var(--muted); font-size: .9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.nav {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; color: var(--text);
  background: var(--surface-2); white-space: nowrap; font-size: .93em;
}
.nav a.active { background: var(--primary); color: var(--primary-text); }
.nav a:hover { text-decoration: none; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.page-head p { margin: 2px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* --- cards & grids --------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: var(--gap);
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card.narrow { max-width: 520px; margin: 24px auto; }
.grid { display: grid; gap: var(--gap); grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
.stats { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); margin-bottom: var(--gap); }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: .88em; }
.stat-hint { font-size: .8em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* --- buttons ---------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: .9em; }
.btn-block { width: 100%; }
.btn.disabled { opacity: .45; pointer-events: none; }
form.inline { display: inline; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- forms -------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span:first-child { font-weight: 500; font-size: .93em; }
.hint { color: var(--muted); font-size: .84em; margin: 2px 0 0; }
input[type=text], input[type=number], input[type=date], input[type=search], input[type=url],
input[type=email], input[type=tel], input[type=password], input:not([type]), select, textarea {
  width: 100%; min-height: var(--tap); padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
  /* under 16px iOS Safari zooms in on focus and stays zoomed */
  font-size: max(16px, 1em);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.4; }
textarea.mono, input.mono { font-size: max(16px, .92em); }
.file-error { color: var(--err-text); }
input[type=file] { font: inherit; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: 0 0 auto; }
fieldset { border: 0; padding: 0; margin: 0; }
.filters { display: grid; gap: 8px 10px; grid-template-columns: 1fr 1fr; align-items: end; }
.filters .field { margin-bottom: 0; }
.filters .filters-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
@media (min-width: 720px) {
  .filters { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .filters .filters-actions { grid-column: auto; }
}
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.presets a { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: .92em; }
.presets a.active { background: var(--primary); color: var(--primary-text); }

/* --- flashes, badges ------------------------------------------------------------ */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: var(--gap); }
.flash ul { margin: 0; padding-left: 18px; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }
.flash-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8em; font-weight: 600; white-space: nowrap; }
.badge-on { background: var(--ok-bg); color: var(--on); }
.badge-off { background: var(--surface-2); color: var(--off); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-err { background: var(--err-bg); color: var(--err-text); }
.badge-info { background: var(--surface-2); color: var(--primary); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* --- tables: scroll on phones, or stack with .table-stack ----------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--gap); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .82em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
@media (max-width: 719px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { border: 0; padding: 3px 0; }
  .table-stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85em; }
  .table-stack td.num { text-align: left; }
}

/* --- list items (cards stacked on phones) --------------------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: var(--gap); }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.item-title { font-weight: 600; }
.item-meta { color: var(--muted); font-size: .88em; }
a.item { display: block; color: var(--text); }
a.item:hover { text-decoration: none; border-color: var(--primary); }

/* --- bars (per-day chart) ------------------------------------------------------- */
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 52px 1fr 80px; gap: 8px; align-items: center; font-size: .85em; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 14px; position: relative; overflow: hidden; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 6px; }
.bar-fill.alt { background: var(--bar-2); height: 50%; top: 50%; }
.legend { display: flex; gap: 14px; font-size: .85em; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; background: var(--bar); vertical-align: -1px; }
.legend i.alt { background: var(--bar-2); }
.progress { background: var(--surface-2); border-radius: 999px; height: 12px; overflow: hidden; }
.progress > div { background: var(--primary); height: 100%; }

.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input { flex: 1; min-width: 0; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 6px; }
.payload { margin: 0; padding: 0; list-style: none; }
.payload li { margin: 1px 0; }
.payload b { font-weight: 600; }
pre.box { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 10px; border-radius: 10px; margin: 6px 0; }

/* width steps for bars/progress without inline styles (CSP): class="bar-fill w35" */
.w0 { width: 0%; }
.w5 { width: 5%; }
.w10 { width: 10%; }
.w15 { width: 15%; }
.w20 { width: 20%; }
.w25 { width: 25%; }
.w30 { width: 30%; }
.w35 { width: 35%; }
.w40 { width: 40%; }
.w45 { width: 45%; }
.w50 { width: 50%; }
.w55 { width: 55%; }
.w60 { width: 60%; }
.w65 { width: 65%; }
.w70 { width: 70%; }
.w75 { width: 75%; }
.w80 { width: 80%; }
.w85 { width: 85%; }
.w90 { width: 90%; }
.w95 { width: 95%; }
.w100 { width: 100%; }
