/* ==========================================================================
   WhatsON - "Signal" component library + app shell (Phase 3).
   Token-driven; light/dark via [data-theme]. Every colour references a token.
   ========================================================================== */

.ic { flex: none; vertical-align: middle; }
.iconbtn { display: grid; place-items: center; width: var(--control-h); height: var(--control-h);
  border: 1px solid transparent; border-radius: var(--radius-control); background: transparent;
  color: var(--muted); cursor: pointer; transition: background var(--transition), color var(--transition); }
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.only-mobile { display: none; } .only-desktop { display: inline-flex; }

/* --- App shell ------------------------------------------------------------ */
.app { min-height: 100vh; }
.shell { display: grid; grid-template-columns: var(--side-w, 248px) 1fr; min-height: 100vh; }
:root { --side-w: 248px; }
:root[data-rail] .shell { --side-w: 68px; }

.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  gap: var(--space-2); padding: var(--space-3); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2); }
.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--fw-semibold); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand__mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-weight: 700; flex: none; }
.side__collapse { display: none; }
@media (min-width: 993px) { .side__collapse { display: grid; } }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: var(--space-2); }
.nav__item { display: flex; align-items: center; gap: var(--space-3); padding: 9px var(--space-3); border-radius: var(--radius-control);
  color: var(--muted); font-weight: var(--fw-medium); background: transparent; border: 0; cursor: pointer; font: inherit; text-align: left; width: 100%; }
.nav__item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav__item.is-active { background: var(--accent-50); color: var(--accent-700); }
:root[data-theme="dark"] .nav__item.is-active { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-200); }
.side__foot { margin-top: auto; }
.th-moon { display: none; } :root[data-theme="dark"] .th-sun { display: none; } :root[data-theme="dark"] .th-moon { display: inline-flex; }

/* Icon-rail (collapsed) */
:root[data-rail] .brand__name, :root[data-rail] .nav__label, :root[data-rail] .wsswitch,
:root[data-rail] .side__collapse .ic { transition: none; }
:root[data-rail] .brand__name, :root[data-rail] .nav__label { display: none; }
:root[data-rail] .side { padding: var(--space-3) var(--space-2); }
:root[data-rail] .nav__item { justify-content: center; }
:root[data-rail] .wsswitch__cur { justify-content: center; }
:root[data-rail] .wsswitch__name, :root[data-rail] .wsswitch .pill { display: none; }
:root[data-rail] .side__collapse { transform: rotate(180deg); }

/* Workspace switcher */
.wsswitch { position: relative; }
.wsswitch__cur { display: flex; align-items: center; gap: var(--space-2); padding: 8px var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-control); cursor: pointer; list-style: none; font-size: var(--fs-sm); background: var(--bg); }
.wsswitch__cur::-webkit-details-marker { display: none; }
.wsswitch__name { font-weight: var(--fw-medium); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wsswitch[open] .wsswitch__cur { border-color: var(--accent); }
.wsswitch__menu { position: absolute; z-index: 40; left: 0; right: 0; margin-top: 4px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 4px; display: flex; flex-direction: column; }
.wsswitch__form { margin: 0; }
.wsswitch__item { display: flex; align-items: center; gap: var(--space-2); padding: 8px var(--space-3); border-radius: 6px; width: 100%;
  border: 0; background: transparent; color: var(--text); cursor: pointer; font: inherit; text-align: left; }
.wsswitch__item:hover { background: var(--surface-2); text-decoration: none; }
.wsswitch__item.is-current { color: var(--accent); }

/* Top bar */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-4); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); }
.topbar__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.searchtrigger { display: flex; align-items: center; gap: var(--space-2); height: 34px; padding: 0 var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-control); background: var(--surface); color: var(--muted); cursor: pointer; font: inherit; font-size: var(--fs-sm); }
.searchtrigger:hover { border-color: var(--accent); }
.searchtrigger kbd { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
.quota { font-size: var(--fs-xs); color: var(--muted); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 3px 10px; }

.avatar-menu { position: relative; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center;
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer; list-style: none; }
.avatar::-webkit-details-marker { display: none; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 4px; z-index: 50; }
.menu__head { padding: var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: var(--fs-sm); }
.menu__item { display: flex; align-items: center; gap: var(--space-2); padding: 8px var(--space-3); border-radius: 6px; color: var(--text); font-size: var(--fs-sm); }
.menu__item:hover { background: var(--surface-2); text-decoration: none; }
.menu__item--danger { color: var(--danger); }

.content { padding: var(--space-5); flex: 1; }

/* Mobile drawer + bottom nav */
.shell__scrim { display: none; }
.bottomnav { display: none; }
@media (max-width: 992px) {
  .only-mobile { display: inline-flex; } .only-desktop { display: none; }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 60; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform 180ms ease; }
  :root[data-drawer] .side { transform: none; box-shadow: var(--shadow-lg); }
  :root[data-drawer] .shell__scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
  .content { padding: var(--space-4); padding-bottom: 76px; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--bg); border-top: 1px solid var(--border);
    justify-content: space-around; padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
  .bottomnav__item { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); min-width: 56px; min-height: 44px; justify-content: center; }
  .bottomnav__item.is-active { color: var(--accent); }
  .bottomnav__item:hover { text-decoration: none; }
}

/* --- Primitives ----------------------------------------------------------- */
.pill, .badge { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: var(--fw-medium);
  border-radius: var(--radius-pill); padding: 2px 10px; border: 1px solid var(--border); }
.pill--muted { color: var(--muted); }
.badge--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.badge--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.badge--info { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, var(--border)); background: color-mix(in srgb, var(--info) 10%, transparent); }

.avatar-sm { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 600; }
.avatar-group { display: inline-flex; } .avatar-group .avatar-sm { margin-left: -8px; border: 2px solid var(--bg); }
.avatar-group .avatar-sm:first-child { margin-left: 0; }

/* Stat tile */
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); background: var(--surface); }
.stat__label { color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; }
.stat__num { font-family: var(--font-mono); font-size: var(--fs-2xl); font-weight: var(--fw-semibold); margin-top: 4px; }
.stat__delta { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.stat__delta--up { color: var(--ok); } .stat__delta--down { color: var(--danger); }

/* Toggle / switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch__track { width: 38px; height: 22px; border-radius: 999px; background: var(--border); transition: background var(--transition); position: relative; flex: none; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform var(--transition); box-shadow: var(--shadow-sm); }
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--focus-ring); }

/* Spinner + skeleton */
.spinner { width: 16px; height: 16px; border: 2px solid color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.2s ease infinite; border-radius: 6px; height: 14px; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .spinner { animation: none; } }

/* Progress */
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress__bar { height: 100%; background: var(--accent); border-radius: 999px; }

/* Tabs / accordion */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs__tab { padding: var(--space-3) var(--space-4); color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; background: 0; border-top: 0; border-left: 0; border-right: 0; font: inherit; }
.tabs__tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: var(--fw-medium); }
.accordion__item { border: 1px solid var(--border); border-radius: var(--radius-control); margin-bottom: var(--space-2); }
.accordion__sum { padding: var(--space-3) var(--space-4); cursor: pointer; font-weight: var(--fw-medium); display: flex; justify-content: space-between; list-style: none; }
.accordion__sum::-webkit-details-marker { display: none; }
.accordion__body { padding: 0 var(--space-4) var(--space-4); color: var(--muted); }

/* Toast + modal */
.toast-stack { position: fixed; z-index: 90; right: var(--space-4); bottom: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); max-width: 360px; }
.toast { display: flex; align-items: flex-start; gap: var(--space-2); background: var(--bg); border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-control);
  box-shadow: var(--shadow-lg); padding: var(--space-3) var(--space-4); font-size: var(--fs-sm); animation: toastin 150ms ease; }
.toast--ok { border-left-color: var(--ok); } .toast--danger { border-left-color: var(--danger); }
.toast--warn { border-left-color: var(--warn); } .toast--info { border-left-color: var(--info); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }
.modal-root:empty { display: none; }
.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: var(--space-4); animation: toastin 120ms ease; }
.modal { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }
.modal--sm { max-width: 360px; } .modal--lg { max-width: 720px; } .modal--full { max-width: 96vw; height: 90vh; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4); border-bottom: 1px solid var(--border); }
.modal__head h3 { margin: 0; font-size: var(--fs-lg); }
.modal__body { padding: var(--space-4); }
.modal__foot { padding: var(--space-4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Channel spine (the signature element) */
.spine { display: inline-flex; align-items: center; gap: var(--space-2); position: relative; padding-left: var(--space-3); }
.spine::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: var(--spine-w); border-radius: 3px; background: var(--ch, var(--muted)); }
.spine--whatsapp { --ch: var(--ch-whatsapp); } .spine--instagram { --ch: var(--ch-instagram); }
.spine--messenger { --ch: var(--ch-messenger); } .spine--sms { --ch: var(--ch-sms); } .spine--email { --ch: var(--ch-email); }
.spine__icon { color: var(--ch, var(--muted)); }

/* Stepper + timeline */
.stepper { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.stepper__step { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--fs-sm); }
.stepper__num { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); display: grid; place-items: center; font-size: var(--fs-xs); }
.stepper__step.is-active .stepper__num { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.stepper__step.is-done .stepper__num { background: var(--ok); color: #fff; border-color: var(--ok); }
.timeline { position: relative; padding-left: var(--space-5); }
.timeline__item { position: relative; padding-bottom: var(--space-4); }
.timeline__item::before { content: ""; position: absolute; left: calc(-1 * var(--space-5) + 6px); top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--bg); }
.timeline__item::after { content: ""; position: absolute; left: calc(-1 * var(--space-5) + 10px); top: 14px; bottom: 0; width: 1px; background: var(--border); }
.timeline__item:last-child::after { display: none; }

/* Kanban shell + split pane */
.kanban { display: flex; gap: var(--space-4); overflow-x: auto; }
.kanban__col { flex: none; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); }
.kanban__col h4 { margin: 0 0 var(--space-3); font-size: var(--fs-sm); display: flex; justify-content: space-between; }
.split { display: grid; grid-template-columns: 320px 1fr; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; min-height: 320px; }
.split__list { border-right: 1px solid var(--border); overflow-y: auto; }
@media (max-width: 768px) { .split { grid-template-columns: 1fr; } }

/* Tooltip / popover (CSS-only tooltip) */
[data-tip] { position: relative; }
[data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-size: var(--fs-xs); padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 70; }

/* Command palette (global search) */
.palette { position: fixed; inset: 0; z-index: 100; display: none; padding-top: 12vh; }
.palette.is-open { display: block; }
.palette__scrim { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.palette__box { position: relative; max-width: 560px; margin: 0 auto; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.palette__input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: var(--space-4); font: inherit; font-size: var(--fs-lg); background: var(--bg); color: var(--text); }
.palette__input:focus { outline: none; }
.palette__results { max-height: 50vh; overflow-y: auto; padding: 4px; }
.palette__group { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: var(--space-2) var(--space-3) 4px; }
.palette__item { display: flex; align-items: center; gap: var(--space-2); padding: 9px var(--space-3); border-radius: 6px; color: var(--text); cursor: pointer; }
.palette__item.is-active, .palette__item:hover { background: var(--surface-2); text-decoration: none; }

/* File drop / preview */
.filedrop { border: 2px dashed var(--border); border-radius: var(--radius); padding: var(--space-6); text-align: center; color: var(--muted); }
.filedrop.is-over { border-color: var(--accent); background: var(--accent-50); color: var(--accent-700); }

/* --- Data table (driven by table.js) ------------------------------------- */
.dt__bar { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.dt__search { flex: 1; max-width: 320px; }
.dt__bulkbar { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); color: var(--muted); }
.dt__scroll { overflow-x: auto; }
.dt__sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.dt__sortable:hover { color: var(--text); }
.dt__arrow { color: var(--accent); }
.dt__foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-3); gap: var(--space-3); }
.dt__pager { display: flex; gap: 4px; flex-wrap: wrap; }
.dt__cbcol { width: 36px; } .dt__empty, .dt__err { text-align: center; color: var(--muted); padding: var(--space-6); }

/* --- Mandatory responsive table: stacked cards below 768px (GLOBAL §6) ---- */
@media (max-width: 768px) {
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table tr { display: block; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--space-3); padding: 4px var(--space-2); }
  .table td { display: flex; justify-content: space-between; gap: var(--space-4); border: 0; padding: 8px var(--space-2); text-align: right; }
  .table td[data-label]::before { content: attr(data-label); color: var(--muted); font-weight: var(--fw-medium); text-align: left; }
  .row-actions { justify-content: flex-end; }
  .dt__scroll { overflow-x: visible; }
}

kbd { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; }

/* --- Fills for component partials ----------------------------------------- */
.alert { display: flex; align-items: flex-start; gap: var(--space-2); }
.alert--warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: var(--warn); }
.alert--info { background: color-mix(in srgb, var(--info) 12%, transparent); border-color: var(--info); }
.btn--block { width: 100%; }
.btn--lg { height: var(--control-h-lg); min-height: var(--control-h-lg); padding: 0 var(--space-5); font-size: var(--fs-lg); }
.btn--secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { background: var(--border); text-decoration: none; }
.btn.is-loading { pointer-events: none; opacity: .8; }
.empty__icon { color: var(--muted); margin-bottom: var(--space-3); display: flex; justify-content: center; }
.empty__title { font-size: var(--fs-lg); margin: 0 0 var(--space-1); color: var(--text); }

/* Style guide layout */
.sg { max-width: 980px; }
.sg__sec { padding: var(--space-5) 0; border-bottom: 1px solid var(--border); }
.sg__sec h2 { font-size: var(--fs-xl); margin: 0 0 var(--space-4); }
.sg__row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-3); }
.sg__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-3); }
.sg__swatch { height: 56px; border-radius: var(--radius-control); border: 1px solid var(--border); display: flex; align-items: flex-end; padding: 4px 6px; font-size: 11px; font-family: var(--font-mono); }
.sg__contrast { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.sg__chip { padding: var(--space-4); border-radius: var(--radius); font-weight: var(--fw-semibold); text-align: center; }
