/* Sanrad CRM: layout only. Colours, controls and components come from sanrad-ui.css (kit 1.5.0);
   everything here uses its tokens. Two layouts:
     desktop / tablet (> 720px): full-width page, top navigation, dense tables;
     phone (<= 720px): one column of cards and a bottom tab bar. */

/* ---------- page frame ---------- */
.page.page-full { max-width: none; padding: var(--space-4) var(--space-5, 20px) var(--space-6); }
.page-head h1 { font-size: 1.35rem; }
.page-head .sub { color: var(--ink-soft); font-size: var(--text-sm); margin: 2px 0 0; }
.version { color: var(--ink-faint); font-size: var(--text-xs); }
.app-header .app-nav { margin-left: var(--space-2); }
.app-header .me { color: var(--ink-soft); font-size: var(--text-sm); white-space: nowrap; }
.nav-more { position: relative; }
.nav-more > summary { list-style: none; cursor: pointer; }
.nav-more > summary::-webkit-details-marker { display: none; }
.nav-more .menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: var(--space-2); display: grid; gap: 2px;
}
.nav-more .menu a { padding: 9px var(--space-3); border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; font-size: var(--text-sm); }
.nav-more .menu a:hover, .nav-more .menu a.active { background: var(--brand-tint); color: var(--brand-dark); }
.nav-more .menu .menu-label { font-size: var(--text-micro); text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); padding: 8px var(--space-3) 2px; }

/* Bottom tab bar: phones only. */
.bottom-tabs { display: none; }

/* ---------- desktop / tablet ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 var(--space-4); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: var(--space-4); align-items: start; }
.span-all { grid-column: 1 / -1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-soft); font-size: var(--text-sm); }

.filters { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: flex-end; margin-bottom: var(--space-3); }
.filters .field { margin: 0; flex: 1 1 160px; max-width: 280px; }
.filters .field.grow { flex: 2 1 260px; max-width: 420px; }
.filters .btn-row { margin: 0; }
.filters-toggle { display: none; }

table.data td, table.data th { vertical-align: top; }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data a.row-link { font-weight: 600; color: var(--ink); text-decoration: none; }
table.data a.row-link:hover { color: var(--brand-dark); text-decoration: underline; }
.muted-line { display: block; color: var(--ink-soft); font-size: var(--text-xs); margin-top: 2px; }
.nowrap { white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: var(--radius-pill); background: var(--canvas); border: 1px solid var(--line); font-size: var(--text-xs); color: var(--ink-soft); }
.inline-form { display: inline; margin: 0; }
.section-title { font-size: var(--text-micro); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); margin: var(--space-4) 0 var(--space-2); }
.perm-area { margin-bottom: var(--space-4); }
.perm-row { display: flex; align-items: flex-start; gap: var(--space-3); padding: 8px 0; border-bottom: 1px solid var(--line); }
.perm-row:last-child { border-bottom: 0; }
.perm-row .perm-text { flex: 1; min-width: 0; }
.perm-row.locked { opacity: .55; }
.review-table input, .review-table select { min-height: var(--control-h-sm); height: var(--control-h-sm); font-size: var(--text-sm); padding: 4px 8px; }
.review-table td { padding: 6px; }
.review-table .saved-as { font-size: var(--text-xs); color: var(--ink-soft); }
.review-table tr.row-skip td { opacity: .5; }
.row-status { font-size: var(--text-xs); }
.code-box { font-family: var(--font-mono, ui-monospace, monospace); font-size: .82rem; min-height: 140px; }
.slot-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2); align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.slot-row code { font-size: .82rem; }
.sticky-side { position: sticky; top: 80px; }

/* ---------- WhatsApp preview (from WIFI_Portal portal.css, kit tokens) ---------- */
.wa-phone {
  --wa-paper: #e5ddd5; --wa-bubble: #ffffff; --wa-ink: #111b21;
  --wa-soft: #667781; --wa-link: #027eb5; --wa-line: rgba(0,0,0,.08);
  background: var(--wa-paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 14px 16px 22px;
}
:root[data-theme="dark"] .wa-phone {
  --wa-paper: #0b141a; --wa-bubble: #202c33; --wa-ink: #e9edef;
  --wa-soft: #8696a0; --wa-link: #53bdeb; --wa-line: rgba(255,255,255,.09);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wa-phone {
    --wa-paper: #0b141a; --wa-bubble: #202c33; --wa-ink: #e9edef;
    --wa-soft: #8696a0; --wa-link: #53bdeb; --wa-line: rgba(255,255,255,.09);
  }
}
.wa-bubble {
  position: relative; background: var(--wa-bubble); color: var(--wa-ink);
  border-radius: 8px; border-top-left-radius: 0; padding: 8px 10px 6px; max-width: 100%;
  box-shadow: 0 1px 1px rgba(0,0,0,.13); font-size: .875rem; line-height: 1.45;
}
.wa-bubble::before {
  content: ""; position: absolute; top: 0; left: -8px; border: 8px solid transparent;
  border-top-color: var(--wa-bubble); border-right: 0;
}
.wa-media { background: var(--wa-line); border-radius: 6px; margin-bottom: 6px; min-height: 120px;
  display: flex; align-items: center; justify-content: center; color: var(--wa-soft); font-size: .8rem; overflow: hidden; }
.wa-media img { display: block; width: 100%; height: auto; }
.wa-header { font-weight: 600; margin-bottom: 4px; }
.wa-body { white-space: pre-wrap; word-break: break-word; }
.wa-footer { margin-top: 6px; font-size: .76rem; color: var(--wa-soft); white-space: pre-wrap; }
.wa-header:empty, .wa-footer:empty { display: none; }
.wa-meta { text-align: right; font-size: .68rem; color: var(--wa-soft); margin-top: 2px; }
.wa-var { display: inline-block; padding: 0 5px; border-radius: 4px; background: rgba(0,168,132,.16); color: #008069; font-size: .78em; }
.wa-buttons { margin-top: 2px; }
.wa-cta { display: flex; align-items: center; justify-content: center; gap: 7px; background: var(--wa-bubble);
  color: var(--wa-link); border-top: 1px solid var(--wa-line); padding: 9px 10px; font-size: .84rem; font-weight: 500; }
.wa-cta:last-child { border-radius: 0 0 8px 8px; }
.wa-body code { font-size: .9em; background: rgba(127,127,127,.16); border-radius: 3px; padding: 0 3px; }
.email-preview { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.email-preview .subject { font-weight: 600; padding: var(--space-3); border-bottom: 1px solid var(--line); }
.email-preview .body { padding: var(--space-3); white-space: pre-wrap; font-size: .92rem; }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .app-header .app-nav, .app-header .me, .app-header .nav-more { display: none; }
  .page.page-full { padding: var(--space-3) var(--space-3) calc(84px + env(safe-area-inset-bottom, 0px)); }
  .bottom-tabs {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 4px max(4px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px));
  }
  .bottom-tabs a, .bottom-tabs summary {
    display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: var(--touch-min);
    justify-content: center; color: var(--ink-soft); text-decoration: none; font-size: .7rem; list-style: none; cursor: pointer;
  }
  .bottom-tabs summary::-webkit-details-marker { display: none; }
  .bottom-tabs svg { width: 22px; height: 22px; }
  .bottom-tabs a.active { color: var(--brand-dark); }
  .bottom-tabs details { position: relative; }
  .bottom-tabs .menu {
    position: fixed; right: 8px; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); left: 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: var(--space-2); display: grid; gap: 2px;
  }
  .bottom-tabs .menu a { flex-direction: row; justify-content: flex-start; font-size: var(--text-base); padding: 10px var(--space-3); color: var(--ink); }
  .bottom-tabs .menu .menu-label { font-size: var(--text-micro); text-transform: uppercase; color: var(--ink-faint); padding: 8px var(--space-3) 2px; }
  .app-footer { display: none; }

  .grid-2, .grid-3, .grid-4, .split { grid-template-columns: minmax(0, 1fr); }
  .sticky-side { position: static; }
  .page-head { flex-wrap: wrap; }
  .page-head .card-actions { width: 100%; }
  .page-head .card-actions .btn { flex: 1; }
  .filters-toggle { display: block; margin-bottom: var(--space-3); }
  .filters-toggle > summary { cursor: pointer; color: var(--brand-dark); font-weight: 600; padding: 8px 0; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .field, .filters .field.grow { max-width: none; }
  .filters-toggle:not([open]) .filters { display: none; }
  /* Tables become cards: first cell is the card title, the rest are labelled rows. */
  .table-cards { border: 0; }
  .table-cards tr { box-shadow: var(--shadow); }
  .table-cards td:first-child { display: block; font-size: 1rem; padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
  .table-cards td:first-child::before { content: none; }
  .table-cards td.actions { justify-content: flex-end; padding-top: 8px; }
  .table-cards td.actions::before { content: none; }
  .table-cards td:empty { display: none; }
  .review-table td { display: block !important; }
  .review-table td::before { display: block; margin-bottom: 2px; }
  .slot-row { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 721px) {
  .filters-toggle { display: contents; }
  .filters-toggle > summary { display: none; }
}

/* ---------- utilities (no inline styles: the CSP forbids them) ---------- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 4px; }
.no-margin { margin: 0; }
.pre-wrap { white-space: pre-wrap; }
.narrow { max-width: 560px; }
.form-wide { max-width: 1400px; }
.filters .field.shrink { flex: 0 0 auto; }
.inline-edit { display: inline-block; text-align: left; }
.inline-edit > summary { list-style: none; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] > .card { position: absolute; right: var(--space-4); z-index: 20; width: min(360px, 90vw); box-shadow: var(--shadow-lg); }
a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--brand); }
fieldset.card { min-width: 0; margin: 0 0 var(--space-4); }
fieldset.card[disabled] { opacity: .85; }
