/* =====================================================================
   Trackly — design tokens (REDESIGN.md v2)
   ===================================================================== */
:root {
  --bg: #161b26;
  --rail: #1c2230;
  --card: #252d3d;
  --card-2: #2b3446;
  --line: #343e52;
  --text: #e7eaf0;
  --muted: #9aa4b6;
  --primary: #0d6efd;
  --primary-2: #0b5ed7;
  --pos: #22c55e;
  --neg: #ef4444;
  --warn: #f59e0b;
  --ok-bg: #16a34a;
  --input-bg: #1f2635;
  --hover: #2e3850;
  --track: #3a4559;
  --shadow: 0 14px 40px rgba(0, 0, 0, .45);
  --radius: 6px;
  --rail-w: 80px;
  /* legacy aliases (older page markup) */
  --bg2: var(--rail);
  --card2: var(--card-2);
  --border: var(--line);
  --green: var(--pos);
  --red: var(--neg);
  --yellow: var(--warn);
  --purple: #a855f7;
  --sidebar: var(--rail-w);
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #f2f4f8;
  --rail: #ffffff;
  --card: #ffffff;
  --card-2: #f1f4f9;
  --line: #e1e6ee;
  --text: #1b2333;
  --muted: #667189;
  --input-bg: #ffffff;
  --hover: #eaf0fb;
  --track: #d5dbe6;
  --shadow: 0 14px 40px rgba(20, 30, 60, .14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 13px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button, input, select, textarea { font-family: inherit; }
.boot { padding: 40px; color: var(--muted); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--track); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
svg { flex-shrink: 0; }

/* =====================================================================
   Shell: rail + topbar
   ===================================================================== */
.layout { min-height: 100vh; }
.rail { position: fixed; top: 0; bottom: 0; left: 0; width: var(--rail-w); background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 0 10px; z-index: 30; }
.rail-logo { display: grid; place-items: center; margin-bottom: 10px; }
.logo-mark { width: 42px; height: 42px; border-radius: 10px; background: linear-gradient(140deg, #0d6efd, #5b8cff); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(13, 110, 253, .35); flex-shrink: 0; }
.logo-mark svg { width: 24px; height: 24px; }
.rail-nav { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; overflow-y: auto; overflow-x: hidden; width: 100%; padding: 6px 0; scrollbar-width: none; }
.rail-nav::-webkit-scrollbar { display: none; }
.rail-foot { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); width: 100%; }
.rail-btn { width: 44px; height: 38px; border-radius: 7px; display: grid; place-items: center; color: var(--muted); background: transparent; border: 0; cursor: pointer; padding: 0; flex-shrink: 0; transition: background .12s, color .12s; }
.rail-btn svg { width: 19px; height: 19px; }
.rail-btn:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.rail-btn.active { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.rail-btn.active svg { color: var(--primary); }
.rail-tip { position: fixed; transform: translateY(-50%); background: #0f131b; color: #fff; font-size: 12px; font-weight: 500; padding: 5px 9px; border-radius: 5px; pointer-events: none; z-index: 1200; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.rail-tip::before { content: ""; position: absolute; left: -4px; top: 50%; margin-top: -4px; border: 4px solid transparent; border-left: 0; border-right-color: #0f131b; }
.rail-tip[hidden] { display: none; }

.plat-dot { width: 22px; height: 22px; border-radius: 6px; background: var(--pc, #64748b); color: #fff; font-size: 10.5px; font-weight: 700; display: inline-grid; place-items: center; flex-shrink: 0; letter-spacing: -.3px; }
.ads-flyout { position: fixed; left: calc(var(--rail-w) + 6px); z-index: 1100; width: 210px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 6px; animation: fin .12s ease; }
.ads-flyout[hidden] { display: none; }
.ads-flyout-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 6px 8px 8px; }
.ads-flyout a { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; color: var(--text); font-weight: 500; }
.ads-flyout a:hover { background: var(--hover); text-decoration: none; }
.ads-flyout a.active { background: var(--card-2); color: var(--primary); }

/* Expanded menu overlay */
.menu-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(5, 8, 14, 0); transition: background .18s ease; }
.menu-overlay[hidden] { display: none; }
.menu-overlay.show { background: rgba(5, 8, 14, .55); backdrop-filter: blur(2px); }
.menu-panel { position: absolute; top: 0; bottom: 0; left: 0; width: 270px; max-width: 86vw; background: var(--rail); border-right: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .18s ease; }
.menu-overlay.show .menu-panel { transform: none; }
.menu-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px 14px; font-size: 16px; }
.menu-head-sp { flex: 1; }
.menu-sec { font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); padding: 8px 18px 6px; }
.menu-nav { flex: 1; overflow-y: auto; padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.menu-foot { border-top: 1px solid var(--line); padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.menu-link { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.menu-link svg { width: 18px; height: 18px; }
.menu-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.menu-link.active { background: var(--card-2); color: var(--text); }
.menu-link.active svg { color: var(--primary); }
.menu-link.sub { padding: 6px 10px 6px 18px; gap: 10px; }
.menu-link.sub .plat-dot { width: 20px; height: 20px; font-size: 10px; }
.menu-group { display: flex; flex-direction: column; gap: 1px; margin: 2px 0; }
.menu-group-title { display: flex; align-items: center; gap: 12px; padding: 8px 10px; color: var(--muted); font-weight: 500; }
.menu-group-title svg { width: 18px; height: 18px; }

/* Main */
.main { margin-left: var(--rail-w); min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 20px; z-index: 20; margin: 20px 28px 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 14px; display: flex; align-items: center; gap: 12px; min-height: 58px; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.topbar::before { content: ""; position: absolute; left: -29px; right: -29px; top: -21px; height: 20px; background: var(--bg); }
.tb-left { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.tb-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.tb-icon { width: 30px; height: 30px; border-radius: 6px; display: inline-grid; place-items: center; background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 0; flex-shrink: 0; }
.tb-icon svg { width: 17px; height: 17px; }
.tb-icon:hover { background: var(--hover); color: var(--text); }
.tb-icon.on { color: var(--primary); }
.menu-btn { display: none; }

.lang-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--text); padding: 4px 8px; border-radius: 5px; letter-spacing: .2px; }
.flag-br { width: 18px; height: 13px; display: block; }

.goal-widget { display: flex; flex-direction: column; gap: 5px; width: 190px; color: var(--text); padding: 2px 0; }
.goal-widget:hover { text-decoration: none; }
.goal-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.goal-label { display: inline-flex; align-items: center; gap: 5px; color: var(--primary); }
.goal-label svg { width: 13px; height: 13px; }
.goal-val { color: var(--text); }
.goal-track { height: 6px; background: var(--track); border-radius: 4px; overflow: hidden; }
.goal-fill { height: 100%; background: var(--neg); border-radius: 4px; transition: width .4s ease; }
.goal-fill[data-level="mid"] { background: var(--warn); }
.goal-fill[data-level="done"] { background: var(--pos); }

.user-chip { display: flex; align-items: center; gap: 10px; color: var(--text); }
.user-chip:hover { text-decoration: none; }
.user-txt { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.user-name { font-weight: 600; font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10.5px; color: var(--muted); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0; }

.content { padding: 20px 28px 32px; width: 100%; min-width: 0; }

/* Dashboard switcher (topbar) */
.dash-switch { position: relative; min-width: 0; margin-right: 6px; }
.dash-current { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 0; color: var(--text); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px 6px; border-radius: 6px; max-width: 46vw; }
.dash-current:hover { background: var(--hover); }
.dash-label { white-space: nowrap; }
.dash-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.dash-caret { display: inline-grid; color: var(--muted); }
.dash-caret svg { width: 15px; height: 15px; }
.dash-menu { position: absolute; left: 0; top: calc(100% + 8px); z-index: 60; width: 280px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 6px; max-height: 60vh; overflow-y: auto; }
.dash-menu[hidden] { display: none; }
.dash-sec { padding: 4px 8px 6px; text-transform: uppercase; letter-spacing: .4px; font-size: 11px; font-weight: 600; }
.dash-item { display: flex; align-items: center; gap: 2px; border-radius: 6px; }
.dash-item:hover, .dash-item.active { background: var(--hover); }
.dash-menu button { background: transparent; border: 0; color: var(--text); font: inherit; cursor: pointer; border-radius: 6px; }
.dash-pick { flex: 1; text-align: left; padding: 7px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dash-item.active .dash-pick { color: var(--primary); font-weight: 600; }
.dash-act { padding: 5px 6px; color: var(--muted) !important; display: inline-grid; place-items: center; }
.dash-act svg { width: 14px; height: 14px; }
.dash-act:hover { color: var(--text) !important; background: var(--card-2) !important; }
.dash-del:hover { color: var(--neg) !important; }
.dash-new { width: 100%; text-align: left; padding: 8px; margin-top: 4px; border-top: 1px solid var(--line) !important; border-radius: 0 !important; color: var(--primary) !important; font-weight: 600; }

/* Sale notifications (bell) */
.notif-wrap { position: relative; }
.notif-bell { position: relative; background: transparent; border: 0; color: var(--muted); width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; cursor: pointer; padding: 0; }
.notif-bell:hover { color: var(--text); background: var(--hover); }
.notif-bell svg { width: 18px; height: 18px; }
.notif-count { position: absolute; top: -3px; right: -4px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--neg); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 17px; text-align: center; }
.notif-count[hidden] { display: none; }
.notif-panel { position: absolute; right: 0; top: calc(100% + 10px); width: 340px; max-width: calc(100vw - 24px); background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); z-index: 60; overflow: hidden; }
.notif-panel[hidden] { display: none; }
.notif-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card-2); }
.notif-toggle { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); color: var(--muted); cursor: pointer; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { padding: 9px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: rgba(13, 110, 253, .08); box-shadow: inset 3px 0 0 var(--primary); }
.notif-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notif-prod { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-val { font-weight: 600; color: var(--pos); white-space: nowrap; }
.notif-empty { padding: 16px 12px; text-align: center; }

/* Privacy mode: blur money (.money anywhere, KPI values, legacy card values) */
html.privacy .money, html.privacy .u-kpi-value, html.privacy .card-value, html.privacy .notif-val { filter: blur(7px); user-select: none; }

@media (max-width: 1100px) {
  .goal-widget { width: 150px; }
  .lang-pill span { display: none; }
}
@media (max-width: 900px) {
  .rail { display: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .topbar { margin: 8px 10px 0; padding: 8px 10px; gap: 8px; top: 8px; }
  .topbar::before { left: -11px; right: -11px; top: -9px; height: 8px; }
  .content { padding: 14px 10px 24px; }
  .goal-widget, .lang-pill, .user-txt { display: none; }
  .tb-right { gap: 8px; }
  .dash-current { font-size: 14px; max-width: 40vw; }
}
@media (max-width: 520px) {
  .dash-label { display: none; }
  [data-theme-toggle] { display: none !important; }
}

/* =====================================================================
   Shared "u-" components (REDESIGN.md)
   ===================================================================== */
.u-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.u-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; min-height: 30px; }
.u-head-side { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.u-title { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.u-subtitle { font-size: 12px; color: var(--muted); margin-top: 3px; }
.u-filter-card { padding: 0; margin-bottom: 16px; }
.u-filter-card > .u-card-head { padding: 12px 16px; margin: 0; border-bottom: 1px solid var(--line); }
.u-filter-card > .u-filters { padding: 12px 16px 14px; }
.u-filter-card > .u-more-filters { padding-top: 0; }
.u-more-link { display: flex; justify-content: flex-end; padding: 0 16px 10px; margin-top: -6px; }
.u-more-link button { background: none; border: 0; color: var(--muted); font-size: 11.5px; font-weight: 600; cursor: pointer; padding: 2px 0; }
.u-more-link button:hover { color: var(--text); }
.u-more-link .u-chev { display: inline-block; transition: transform .15s; }
.u-more-link.open .u-chev { transform: rotate(180deg); }

.u-filters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px 18px; }
.u-filters[hidden] { display: none; }
.u-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.u-field > label { font-size: 11px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-field > .u-select, .u-field > .u-input, .u-field > select, .u-field > input { width: 100%; }

.u-select, .u-input { height: 34px; background-color: var(--input-bg); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius); padding: 0 10px; font: inherit; font-size: 12.5px; font-weight: 500; outline: none; min-width: 0; }
.u-input::placeholder { color: var(--muted); opacity: .75; }
.u-select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 30px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa4b6' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 13px; }
.u-select option { background: var(--card); color: var(--text); }
.u-select:focus, .u-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 110, 253, .18); }
textarea.u-input { height: auto; padding: 8px 10px; }
.u-period-pop { position: fixed; z-index: 1300; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 290px; }
.u-period-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }

.u-refresh { display: flex; align-items: center; gap: 16px; white-space: nowrap; }
.u-refresh-text { color: var(--muted); font-size: 12px; }
.u-refresh .btn-primary { min-width: 98px; height: 32px; font-weight: 600; }

.u-info { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; border: 1.3px solid currentColor; color: var(--muted); font-size: 9px; font-weight: 700; font-style: normal; line-height: 1; cursor: help; flex-shrink: 0; font-family: Georgia, serif; text-transform: none; }

.u-kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; display: flex; flex-direction: column; gap: 6px; justify-content: center; min-height: 92px; }
.u-kpi-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; font-weight: 600; color: var(--text); }
.u-kpi-title > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-kpi-value { font-size: 18px; font-weight: 600; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.u-kpi.neg .u-kpi-title, .u-kpi.neg .u-kpi-value, .u-kpi.neg .u-info { color: var(--neg); }

.u-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 14px; align-items: end; }
.u-tab { display: flex; align-items: center; gap: 9px; background: var(--card); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; padding: 11px 16px; color: var(--text); font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-tab svg { width: 16px; height: 16px; color: var(--muted); }
.u-tab:hover { background: var(--card-2); text-decoration: none; }
.u-tab.active { background: var(--card-2); color: var(--primary); padding-top: 14px; padding-bottom: 14px; box-shadow: inset 0 -2px 0 var(--primary); }
.u-tab.active svg { color: var(--primary); }
.u-tabs + .u-card { border-top-left-radius: 0; border-top-right-radius: 0; }

.u-table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.u-card .u-table-wrap { border-radius: 0; border-left: 0; border-right: 0; }
.u-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.u-table th, .u-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.u-table td + td, .u-table th + th { border-left: 1px solid rgba(255, 255, 255, .035); }
html[data-theme="light"] .u-table td + td, html[data-theme="light"] .u-table th + th { border-left-color: rgba(0, 0, 0, .05); }
.u-table thead th { background: var(--card-2); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; z-index: 1; }
.u-table thead th .u-info { margin-left: 5px; vertical-align: -2px; }
.u-table tbody tr:hover td { background: rgba(255, 255, 255, .025); }
html[data-theme="light"] .u-table tbody tr:hover td { background: rgba(13, 110, 253, .04); }
.u-table tfoot td, .u-table tr.total td { background: var(--card-2); font-weight: 700; font-size: 11.5px; text-transform: uppercase; border-bottom: 0; }
.u-table .right, .u-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.u-table .center { text-align: center; }
.u-table th.sortable { cursor: pointer; user-select: none; }
.u-table th.sortable:hover { color: var(--text); }
.u-table td.wrap { white-space: normal; min-width: 140px; }

.u-switch { position: relative; display: inline-block; width: 34px; height: 19px; cursor: pointer; vertical-align: middle; flex-shrink: 0; }
.u-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.u-switch > span { position: absolute; inset: 0; background: #5b6478; border-radius: 20px; transition: background .18s; }
.u-switch > span::before { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .18s; }
.u-switch input:checked + span { background: var(--primary); }
.u-switch input:checked + span::before { transform: translateX(15px); }
.u-switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(13, 110, 253, .3); }
.u-switch.busy { opacity: .6; pointer-events: none; }

.u-badge-ok { display: inline-flex; align-items: center; gap: 5px; background: var(--ok-bg); color: #fff; font-size: 10.5px; font-weight: 600; padding: 3px 9px 3px 6px; border-radius: 999px; white-space: nowrap; }
.u-badge-ok::before { content: "✓"; display: inline-grid; place-items: center; width: 11px; height: 11px; border: 1.3px solid #fff; border-radius: 50%; font-size: 7.5px; font-weight: 800; }

.u-empty { color: var(--muted); font-size: 12px; font-weight: 500; padding: 14px 0; }
.u-table-wrap .u-empty, td .u-empty { text-align: center; padding: 28px 12px; }

.u-section-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: left; }
.u-section-toggle:hover { background: var(--card-2); }
.u-section-toggle::after { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-2px) rotate(45deg); transition: transform .15s; flex-shrink: 0; }
.u-section-toggle.open::after { transform: translateY(2px) rotate(-135deg); }

@media (max-width: 1200px) { .u-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 700px) {
  .u-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .u-card-head { flex-wrap: wrap; }
  .u-refresh-text { display: none; }
  .u-tabs { grid-auto-columns: minmax(120px, 1fr); overflow-x: auto; gap: 8px; }
}
@media (max-width: 440px) { .u-filters { grid-template-columns: 1fr; } }

/* =====================================================================
   Legacy / generic components restyled with the new tokens
   ===================================================================== */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-header h2 { font-size: 17px; }
.page-header p { margin: 4px 0 0; color: var(--muted); }
.section-title { font-size: 14px; font-weight: 600; margin: 22px 0 12px; color: var(--text); }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }
.span-2 { grid-column: span 2; }
@media (max-width: 700px) { .span-2 { grid-column: auto; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card-title { color: var(--text); font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-value { font-size: 18px; font-weight: 600; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.card.hero { background: var(--card-2); }
.card.hero .card-value { font-size: 24px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.card-head h3 { margin: 0; }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card-2); color: var(--text); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--track); background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); color: var(--text); border-color: transparent; }
.btn-danger { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); color: #f87171; }
.btn-danger:hover { background: rgba(239, 68, 68, .22); border-color: var(--neg); }
.btn-success { background: var(--ok-bg); border-color: var(--ok-bg); color: #fff; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }

.input, .select, textarea.input { background-color: var(--input-bg); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius); padding: 7px 10px; font: inherit; font-size: 12.5px; outline: none; min-width: 0; }
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 110, 253, .18); }
.input::placeholder { color: var(--muted); opacity: .75; }
.select { cursor: pointer; }
.u-select.select, .u-input.input { height: 34px; padding: 0 10px; }
.u-select.select { padding-right: 30px; }
textarea.u-input.input { height: auto; padding: 8px 10px; }
.select option { background: var(--card); color: var(--text); }
.label { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; margin-bottom: 5px; }
.form-row { display: flex; flex-direction: column; margin-bottom: 14px; }
.form-row .input, .form-row .select { width: 100%; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .3px; background: var(--card-2); position: sticky; top: 0; z-index: 1; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .arrow { font-size: 10px; margin-left: 4px; color: var(--primary); }
.table tbody tr:hover td { background: rgba(255, 255, 255, .025); }
html[data-theme="light"] .table tbody tr:hover td { background: rgba(13, 110, 253, .04); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; background: var(--card-2); border-top: 1px solid var(--line); border-bottom: 0; }
.table .right, .table td.right, .table th.right { text-align: right; }
.table .center { text-align: center; }
.table td.name { max-width: 340px; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--card-2); color: var(--muted); border: 1px solid transparent; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-approved, .badge-ACTIVE, .badge-active, .badge-ok { background: rgba(34, 197, 94, .14); color: var(--pos); }
.badge-pending, .badge-warn { background: rgba(245, 158, 11, .14); color: var(--warn); }
.badge-refunded { background: rgba(168, 85, 247, .16); color: #c084fc; }
.badge-chargeback, .badge-refused, .badge-err { background: rgba(239, 68, 68, .14); color: var(--neg); }
.badge-PAUSED, .badge-paused, .badge-inactive { background: rgba(154, 164, 182, .14); color: var(--muted); }

.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.small { font-size: 12px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.error-box { background: rgba(239, 68, 68, .08); border: 1px solid rgba(239, 68, 68, .35); color: #f87171; border-radius: var(--radius); padding: 14px 16px; }
.error-box pre { white-space: pre-wrap; font-size: 12px; margin: 8px 0 0; opacity: .85; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--track); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.code { position: relative; background: var(--input-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 44px 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text); word-break: break-all; white-space: pre-wrap; }
.code .copy-btn, [data-copy].copy-btn { position: absolute; top: 6px; right: 6px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 9px 14px; cursor: pointer; font: inherit; font-weight: 600; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast { background: var(--card); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--pos); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); min-width: 240px; max-width: 380px; font-weight: 500; animation: tin .2s ease; }
.toast.err { border-left-color: var(--neg); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(5, 8, 14, .6); display: grid; place-items: center; z-index: 1500; padding: 20px; animation: fin .15s ease; }
@keyframes fin { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 8px; width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card-2); border-radius: 8px 8px 0 0; }
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.switch { position: relative; display: inline-block; width: 34px; height: 19px; cursor: pointer; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #5b6478; border-radius: 20px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(15px); }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 12.5px; }
.bar-row .bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-val { text-align: right; color: var(--muted); }
.bar-row .bar-val b { color: var(--text); font-weight: 600; }
.bar-track { grid-column: 1 / -1; height: 6px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 480px at 15% -10%, rgba(13, 110, 253, .16), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 28px; box-shadow: var(--shadow); }
.logo { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.auth-card .logo { padding: 0 0 6px; justify-content: center; font-size: 22px; }
.auth-card .tagline { text-align: center; color: var(--muted); margin-bottom: 20px; }
.demo-hint { margin-top: 16px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-size: 12px; text-align: center; }
.demo-hint code { color: var(--text); }
.auth-switch { text-align: center; margin-top: 16px; color: var(--muted); }

.editable { cursor: pointer; border-bottom: 1px dashed var(--track); }
.editable:hover { color: var(--primary); }
.inline-input { width: 110px; padding: 4px 6px; font-size: 12.5px; }
.flex { display: flex; align-items: center; gap: 8px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
