/* ══ BASE CSS ════════════════════════════════════════════ v2.8 ══ */

/* ══ SHARED TOKENS (theme-independent) ══════════════════════════ */
:root {
  --sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', 'Fira Mono', monospace;
  --r:    5px;
  --r2:   8px;
  --r-btn: 20px;
}

/* ══ DARK THEME ═════════════════════════════════════════════════ */
html.dark {
  --bg:        #0a0a0a;
  --s1:        #141414;
  --s2:        #1c1c1c;
  --s3:        #242424;
  --s4:        #333333;
  --b1:        #262626;
  --b2:        #333333;
  --b3:        #4d4d4d;
  --tx:        #f0f0f0;
  --tx2:       #aaaaaa;
  --tx3:       #666666;
  --acc:       #e85d04;
  --acc2:      #fb923c;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --ok:        #22c55e;
  --purple:    #a78bfa;
  --shadow:    0 4px 24px rgba(0,0,0,.5);
  --acc-bg:    rgba(232,93,4,.08);
  --acc-bd:    rgba(232,93,4,.28);
  --ok-bg:     rgba(34,197,94,.08);
  --ok-bd:     rgba(34,197,94,.28);
  --warn-bg:   rgba(245,158,11,.08);
  --warn-bd:   rgba(245,158,11,.28);
  --danger-bg: rgba(239,68,68,.08);
  --danger-bd: rgba(239,68,68,.28);
  --purple-bg: rgba(167,139,250,.08);
  --purple-bd: rgba(167,139,250,.28);
  --info-bg:   rgba(251,146,60,.08);
  --info-bd:   rgba(251,146,60,.28);
  --row-hover: rgba(255,255,255,.035);
  --pd-row-bd: rgba(255,255,255,.05);
}

/* ══ LIGHT THEME — Apple / Pinterest ════════════════════════════ */
html.light {
  --bg:        #e4e4e8;
  --s1:        #efeff2;
  --s2:        #e8e8ec;
  --s3:        #dfdfe5;
  --s4:        #d4d4da;
  --b1:        #c0c0ca;
  --b2:        #acacb8;
  --b3:        #888898;
  --tx:        #1d1d1f;
  --tx2:       #38383f;
  --tx3:       #505060;
  --acc:       #e85d04;
  --acc2:      #c94e00;
  --warn:      #9a6700;
  --danger:    #c0392b;
  --ok:        #1a7f37;
  --purple:    #5e35b1;
  --shadow:    0 4px 24px rgba(0,0,0,.10);
  --acc-bg:    rgba(232,93,4,.10);
  --acc-bd:    rgba(232,93,4,.22);
  --ok-bg:     rgba(26,127,55,.10);
  --ok-bd:     rgba(26,127,55,.22);
  --warn-bg:   rgba(154,103,0,.10);
  --warn-bd:   rgba(154,103,0,.22);
  --danger-bg: rgba(192,57,43,.10);
  --danger-bd: rgba(192,57,43,.22);
  --purple-bg: rgba(94,53,177,.10);
  --purple-bd: rgba(94,53,177,.22);
  --info-bg:   rgba(201,78,0,.10);
  --info-bd:   rgba(201,78,0,.22);
  --row-hover: rgba(0,0,0,.06);
  --pd-row-bd: rgba(0,0,0,.08);
}

/* ══ RESET ══════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--tx);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--b3); border-radius: 2px; }

/* ══ USER SELECTOR ══════════════════════════════════════════════ */
.us-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

.us-box {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px;
}

.us-logo {
  width: 48px; height: 48px;
  background: var(--acc);
  border-radius: var(--r2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 15px; font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.us-title {
  font-family: var(--mono);
  font-size: 13px; font-weight: 600;
  letter-spacing: .2em;
  color: var(--tx2);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.us-sub {
  font-size: 12px; color: var(--tx3);
  font-family: var(--mono);
  margin-bottom: 24px;
}

.us-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 400px;
}

.us-btn {
  height: 56px;
  background: var(--s2);
  border: 1px solid var(--b2);
  border-radius: var(--r2);
  color: var(--tx);
  font-family: var(--mono);
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
}
.us-btn:hover {
  border-color: var(--acc);
  background: var(--acc-bg);
  color: var(--acc);
}
.us-btn .us-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--b3);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}

/* ══ APP SHELL ══════════════════════════════════════════════════ */
.app-shell { display: flex; width: 100%; height: 100vh; overflow: hidden; }

/* ══ SIDEBAR ════════════════════════════════════════════════════ */
.sidebar {
  width: 52px;
  background: var(--s1);
  border-right: 1px solid var(--b1);
  display: flex; flex-direction: column;
  align-items: center;
  padding: 8px 0 14px;
  gap: 2px;
  flex-shrink: 0;
  overflow: hidden;
  transition: width .2s cubic-bezier(.4,0,.2,1);
  z-index: 10;
}
.sidebar.expanded { width: 192px; }

/* Toggle button */
.sb-toggle {
  width: 100%; height: 28px;
  background: transparent;
  border: none;
  color: var(--tx3);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  transition: color .12s, background .12s;
  flex-shrink: 0;
  margin-bottom: 4px;
}
.sb-toggle:hover { color: var(--tx); background: var(--s2); }
#sb-toggle-ic {
  display: inline-block;
  transition: transform .2s cubic-bezier(.4,0,.2,1);
}
.sidebar.expanded #sb-toggle-ic { transform: rotate(180deg); }

.sb-logo {
  width: 30px; height: 30px;
  background: var(--acc);
  border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  color: #fff;
  margin-bottom: 14px; flex-shrink: 0;
}

.sb-nav { display: flex; flex-direction: column; gap: 2px; width: 100%; flex: 1; }
.sb-bottom { width: 100%; padding: 0 0 4px; }
.sb-divider { height: 1px; background: var(--b1); margin: 8px 11px; }

.ni {
  width: 100%;
  height: 36px;
  display: flex; align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  color: var(--tx3);
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
  text-align: left;
}
.ni:hover { background: var(--s2); color: var(--tx); }
.ni.active {
  background: var(--acc-bg);
  border-left-color: var(--acc);
  color: var(--acc);
}
.ni-ic {
  font-size: 14px; flex-shrink: 0; width: 18px; text-align: center;
  display: flex; align-items: center; justify-content: center;
}
.ni-ic svg { display: block; }
.ni-lbl {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  opacity: 0; transition: opacity .15s;
  pointer-events: none; white-space: nowrap;
}
.sidebar.expanded .ni-lbl { opacity: 1; }

.sb-user {
  margin: 4px 8px 0;
  padding: 8px;
  border-radius: var(--r);
  cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  min-height: 36px;
  transition: background .12s;
  overflow: hidden;
}
.sb-user:hover { background: var(--s2); }
.sb-user-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--b3);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  color: var(--tx2); flex-shrink: 0;
}
.sb-user-name {
  font-family: var(--mono); font-size: 11px; color: var(--tx2);
  opacity: 0; transition: opacity .15s; white-space: nowrap;
}
.sidebar.expanded .sb-user-name { opacity: 1; }

/* ══ MAIN AREA ══════════════════════════════════════════════════ */
.main-area {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

.topbar {
  height: 48px; flex-shrink: 0;
  background: var(--s1);
  border-bottom: 1px solid var(--b1);
  display: flex; align-items: center;
  padding: 0 18px; gap: 10px;
}
.tb-left { display: flex; align-items: center; gap: 8px; flex: 1; }
.tb-mod {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--tx2); letter-spacing: .1em; text-transform: uppercase;
}
.tb-right { display: flex; align-items: center; gap: 6px; }

.sync-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok); transition: background .3s;
}
.sync-dot.loading { background: var(--warn); animation: pulse .8s infinite; }
.sync-dot.error   { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

#module-container {
  flex: 1; overflow-x: auto; overflow-y: hidden;
  display: flex; flex-direction: column;
}

/* ══ TOASTS ═════════════════════════════════════════════════════ */
#toasts {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 7px;
  z-index: 9999; pointer-events: none;
}
.toast {
  background: var(--s3);
  border: 1px solid var(--b2);
  border-radius: var(--r2);
  padding: 9px 14px;
  font-family: var(--mono); font-size: 11px;
  display: flex; align-items: center; gap: 8px;
  min-width: 220px; max-width: 340px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease;
  pointer-events: all;
}
.toast.ok   { border-color: var(--ok-bd);     color: var(--ok); }
.toast.err  { border-color: var(--danger-bd); color: var(--danger); }
.toast.warn { border-color: var(--warn-bd);   color: var(--warn); }
.toast.info { border-color: var(--info-bd);   color: var(--acc2); }
@keyframes toast-in { from{opacity:0;transform:translateX(12px)} to{opacity:1;transform:none} }

/* ══ TOOLBAR PATTERN ════════════════════════════════════════════ */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--b1);
  background: var(--s1);
  flex-shrink: 0; flex-wrap: wrap;
}
.tb-grp { display: flex; align-items: center; gap: 5px; }
.tb-lbl { font-family: var(--mono); font-size: 10px; color: var(--tx3); white-space: nowrap; }
.tb-sep { width: 1px; height: 18px; background: var(--b2); margin: 0 2px; }
.ml-auto { margin-left: auto; }

/* ══ FORM CONTROLS ══════════════════════════════════════════════ */
.inp {
  height: 28px;
  background: var(--s3);
  border: 1px solid var(--b2);
  border-radius: var(--r);
  color: var(--tx);
  font-family: var(--mono); font-size: 11px;
  padding: 0 8px;
  outline: none;
  transition: border-color .12s;
}
.inp:focus { border-color: var(--acc); }
.inp::placeholder { color: var(--tx3); }
.inp-lg { height: 32px; font-size: 12px; }

select.inp option { background: var(--s3); }

textarea.inp {
  height: auto; padding: 6px 8px;
  resize: vertical; line-height: 1.5;
}

.fg {
  display: flex; flex-direction: column; gap: 4px;
}
.fg label {
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  color: var(--tx3); text-transform: uppercase; letter-spacing: .07em;
}
.fg .inp { width: 100%; }

.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

/* ══ SECTIONS ═══════════════════════════════════════════════════ */
.sec {
  background: var(--s2);
  border: 1px solid var(--b1);
  border-radius: var(--r2);
  margin-bottom: 10px;
  overflow: hidden;
}
.sec-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}
.sec-hd:hover { background: var(--s3); }
.sec-title {
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  color: var(--tx3); text-transform: uppercase; letter-spacing: .12em;
  display: flex; align-items: center; gap: 7px;
}
.sec-tog { color: var(--tx3); font-size: 10px; transition: transform .15s; }
.sec.collapsed .sec-tog { transform: rotate(-90deg); }
.sec.collapsed .sec-body { display: none; }
.sec-body { padding: 12px 14px; border-top: 1px solid var(--b1); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* ══ TABLES ═════════════════════════════════════════════════════ */
.tbl { width: 100%; border-collapse: collapse; }
.tbl thead th {
  padding: 7px 10px;
  text-align: left;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  color: var(--tx3); text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--b2);
  white-space: nowrap;
  background: var(--s2);
  position: sticky; top: 0; z-index: 1;
}
.tbl thead th.r, .tbl td.r { text-align: right; }
.tbl td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--b1);
  font-size: 12px;
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { cursor: pointer; transition: background .08s; }
.tbl tbody tr:hover td { background: var(--row-hover); }
.tbl tbody tr.sel td { background: var(--acc-bg) !important; }

/* ══ BADGES / PILLS ═════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 3px;
  border: 1px solid; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
.badge-ok      { color: var(--ok);     border-color: var(--ok-bd);     background: var(--ok-bg); }
.badge-warn    { color: var(--warn);   border-color: var(--warn-bd);   background: var(--warn-bg); }
.badge-danger  { color: var(--danger); border-color: var(--danger-bd); background: var(--danger-bg); }
.badge-neutral { color: var(--tx3);   border-color: var(--b2);        background: var(--s3); }
.badge-info    { color: var(--acc2);  border-color: var(--info-bd);   background: var(--info-bg); }
.badge-acc     { color: var(--acc);   border-color: var(--acc-bd);    background: var(--acc-bg); }
.badge-purple  { color: var(--purple); border-color: var(--purple-bd); background: var(--purple-bg); }

/* ══ EMPTY STATE ════════════════════════════════════════════════ */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 60px 20px;
  color: var(--tx3); font-family: var(--mono); font-size: 11px;
}
.empty-icon { font-size: 30px; opacity: .15; }

/* ══ LOADING ════════════════════════════════════════════════════ */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--b3);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══ OVERLAY / MODAL ════════════════════════════════════════════ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.overlay.open { opacity: 1; pointer-events: all; }
.overlay.open .modal { transform: translateY(0); }

.modal {
  background: var(--s2);
  border: 1px solid var(--b2);
  border-radius: var(--r2);
  width: 560px; max-width: 95vw;
  max-height: 88vh; overflow-y: auto;
  transform: translateY(10px);
  transition: transform .18s;
  display: flex; flex-direction: column;
}
.modal-lg { width: 720px; }
.modal-xl { width: 900px; }

.modal-hd {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--b1);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--s2); z-index: 1;
  flex-shrink: 0;
}
.modal-title {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em; color: var(--tx);
}
.modal-close {
  background: none; border: none; color: var(--tx3);
  font-size: 17px; cursor: pointer; padding: 0 2px;
  transition: color .12s; line-height: 1;
}
.modal-close:hover { color: var(--tx); }
.modal-body { padding: 18px; flex: 1; }
.modal-ft {
  padding: 12px 18px;
  border-top: 1px solid var(--b1);
  display: flex; justify-content: flex-end; gap: 7px;
  position: sticky; bottom: 0; background: var(--s2);
  flex-shrink: 0;
}

/* ══ DETAIL PANEL ═══════════════════════════════════════════════ */
.panel {
  width: 360px; flex-shrink: 0;
  border-left: 1px solid var(--b1);
  background: var(--s1);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width .15s cubic-bezier(.4,0,.2,1);
}
.panel.closed { width: 0; border: none; overflow: hidden; }
.panel-scroll { flex: 1; overflow-y: auto; }
.panel-ft {
  padding: 10px 12px;
  border-top: 1px solid var(--b1);
  display: flex; gap: 6px; flex-wrap: wrap;
  flex-shrink: 0;
}

.pd-hd {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--b1);
}
.pd-num  { font-family: var(--mono); font-size: 10px; color: var(--tx3); margin-bottom: 2px; }
.pd-name { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.pd-dates { font-family: var(--mono); font-size: 10px; color: var(--tx3); margin-bottom: 8px; }
.pd-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.pd-sec { border-bottom: 1px solid var(--b1); }
.pd-sec-hd {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px 10px 12px; cursor: pointer;
  border-left: 2px solid transparent;
}
.pd-sec-hd:hover { background: var(--s2); border-left-color: var(--b3); }
.pd-sec-lbl { font-family: var(--mono); font-size: 10px; font-weight: 700; color: var(--tx2); text-transform: uppercase; letter-spacing: .08em; }
.pd-sec-tog { font-size: 10px; color: var(--tx3); transition: transform .12s; }
.pd-sec.coll .pd-sec-tog  { transform: rotate(-90deg); }
.pd-sec.coll .pd-sec-body { display: none; }
.pd-sec-body { padding: 4px 14px 12px; }

.pd-row {
  display: flex; justify-content: space-between;
  padding: 3px 0;
  font-size: 11px;
  border-bottom: 1px solid var(--pd-row-bd);
}
.pd-row-l { color: var(--tx3); flex: 1; }
.pd-row-r { font-family: var(--mono); font-weight: 500; text-align: right; }
.pd-row-r.hi   { color: var(--acc);    font-size: 13px; font-weight: 700; }
.pd-row-r.warn { color: var(--warn); }
.pd-row-r.ok   { color: var(--ok); }

.pd-chip {
  display: inline-flex; align-items: center;
  font-family: var(--mono); font-size: 10px;
  padding: 2px 6px; border-radius: 3px;
  background: var(--s3); border: 1px solid var(--b2);
  color: var(--tx2); margin: 2px 2px 2px 0;
}

/* ══ PAGO CARD ══════════════════════════════════════════════════ */
.pago-card {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px;
  background: var(--s3); border: 1px solid var(--b2);
  border-radius: var(--r); margin-bottom: 5px;
}
.pago-monto { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--ok); }
.pago-meta  { font-family: var(--mono); font-size: 10px; color: var(--tx3); margin-top: 2px; }

/* ══ SETTINGS TABS ══════════════════════════════════════════════ */

/* Wrapper con fade lateral para indicar scroll */
.set-tabs-wrap {
  position: relative; flex-shrink: 0;
}
.set-tabs-wrap::after {
  content: '';
  position: absolute; top: 0; right: 0;
  width: 32px; height: 100%;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.set-tabs-wrap.has-overflow::after { opacity: 1; }

.set-tabs {
  display: flex; border-bottom: 1px solid var(--b1);
  overflow-x: auto; flex-shrink: 0;
  /* Scroll suave, sin scrollbar visible en la mayoría de browsers */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* IE/Edge */
}
.set-tabs::-webkit-scrollbar { display: none; } /* Chrome/Safari */

.set-tab {
  padding: 10px 16px;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  color: var(--tx3); cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all .12s; background: none; border-left: none; border-right: none; border-top: none;
}
.set-tab:hover { color: var(--tx); }
.set-tab.active {
  color: var(--acc); border-bottom-color: var(--acc);
  /* Auto-scroll para que la tab activa siempre sea visible */
}
.set-panel {
  display: none;
  padding: 18px;
  overflow-y: auto;
  overflow-x: auto;           /* ← scroll horizontal si el contenido es ancho */
  flex: 1;
  min-width: 0;               /* evita que el flex rompa el layout */
}
.set-panel.active { display: block; }

/* ── Scroll horizontal genérico para cualquier contenedor con overflow ─── */
/* Aplica a tablas, grids y paneles dentro de módulos */
.tbl-wrap, .module-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--b3) transparent;
}
.tbl-wrap::-webkit-scrollbar { height: 4px; }
.tbl-wrap::-webkit-scrollbar-track { background: transparent; }
.tbl-wrap::-webkit-scrollbar-thumb { background: var(--b3); border-radius: 2px; }

/* Fade derecho reutilizable: añadir .fade-right al wrapper */
.fade-right {
  position: relative;
}
.fade-right::after {
  content: '';
  position: absolute; top: 0; right: 0;
  width: 28px; height: 100%;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
  transition: opacity .2s;
}

/* ══ MOBILE NAV — base (hidden on desktop) ══════════════════════ */
.mobile-nav { display: none; }
#mob-backdrop { display: none; }

/* ══ MOBILE RESPONSIVE ══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Sidebar → drawer ──────────────────────────────────────── */
  .sidebar {
    position: fixed !important;
    left: -260px; top: 0; bottom: 0;
    width: 220px !important;
    z-index: 300;
    transition: left .25s cubic-bezier(.4,0,.2,1);
    border-right: 1px solid var(--b1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.mob-open { left: 0; }
  /* Always show labels in the mobile drawer */
  .sidebar .ni-lbl   { opacity: 1 !important; }
  .sidebar .sb-user-name { opacity: 1 !important; }
  .sb-toggle { display: none; }

  /* ── Backdrop ───────────────────────────────────────────────── */
  #mob-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 299;
    opacity: 0; pointer-events: none;
    transition: opacity .25s;
  }
  #mob-backdrop.show { opacity: 1; pointer-events: all; }

  /* ── Bottom nav ─────────────────────────────────────────────── */
  .mobile-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--s1);
    border-top: 1px solid var(--b1);
    z-index: 200;
  }
  .mn-item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    background: none; border: none;
    color: var(--tx3);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color .1s;
  }
  .mn-item:active { background: var(--s2); }
  .mn-item.active { color: var(--acc); }
  .mn-ic { display: flex; align-items: center; justify-content: center; }
  .mn-lbl { font-family: var(--mono); font-size: 9px; font-weight: 500; }

  /* ── Main area ──────────────────────────────────────────────── */
  .main-area { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }

  /* ── Topbar ─────────────────────────────────────────────────── */
  .topbar { padding: 0 12px; height: 44px; }

  /* ── Toasts: above bottom nav ───────────────────────────────── */
  #toasts { bottom: calc(64px + env(safe-area-inset-bottom)); right: 12px; }

  /* ── Modals: sheet from bottom ──────────────────────────────── */
  .overlay { align-items: flex-end; }
  .modal {
    max-width: 100vw;
    width: 100vw;
    max-height: 90vh;
    border-radius: var(--r2) var(--r2) 0 0;
    border-bottom: none;
  }

  /* ── Forms: single column ───────────────────────────────────── */
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: span 1; }

  /* ── Toolbar: horizontal scroll ─────────────────────────────── */
  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .tb-sep { display: none; }

  /* ── Module container: allow vertical scroll ─────────────────── */
  #module-container { overflow-y: auto; }

  /* ── User selector: single column on narrow screens ─────────── */
  .us-grid { grid-template-columns: repeat(3, 1fr); width: 280px; }

}
