/* Card Manager — follows ~/design-reference/DESIGN.md (owner's design language). */
:root {
  --bg: #F4F5FA; --surface: #FFFFFF; --surface-2: #F0F1F7; --border: #E6E8F0;
  --text: #151A2D; --text-muted: #5F6678;
  --accent: #6C5CE7; --accent-ink: #5B4BD5; --accent-2: #4F7CFF; --accent-soft: #ECEAFD; --on-accent: #FFFFFF;
  --success: #15803D; --success-soft: #DCFCE7; --warning: #B45309; --warning-soft: #FEF3C7;
  --danger: #DC2626; --danger-soft: #FEE2E2; --info: #0E7490; --info-soft: #CFFAFE;
  --radius: 16px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --chart-mark: #6C5CE7; --grid: #E9EAF2;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0B0E1A; --surface: #141829; --surface-2: #1C2136; --border: #262C45;
  --text: #F3F4F8; --text-muted: #9AA2BC;
  --accent: #6655E8; --accent-ink: #A99FFF;  /* fill under white text (5.2:1); charts use --chart-mark */ --accent-2: #5B8CFF; --accent-soft: rgba(123,108,255,.16); --on-accent: #FFFFFF;
  --success: #4ADE80; --success-soft: rgba(74,222,128,.14); --warning: #FBBF24; --warning-soft: rgba(251,191,36,.14);
  --danger: #F87171; --danger-soft: rgba(248,113,113,.14); --info: #22D3EE; --info-soft: rgba(34,211,238,.14);
  --shadow: none; --chart-mark: #7B6CFF; --grid: #232942;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num, .money, .value { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 14px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #7B6CFF, #4F7CFF); }
.nav-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); margin: 16px 12px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-muted); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
.side-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, #7B6CFF, #4F7CFF); flex: none; }
.who { min-width: 0; flex: 1; }
.who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; padding: 24px 28px 48px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.topbar h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: -.01em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; }

/* ---------- controls ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; font-weight: 500; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; cursor: pointer; color: var(--text-muted); font-weight: 500; min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
[data-theme="dark"] .seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 11px; padding: 0 16px; min-height: 42px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-ink); }
[data-theme="dark"] .btn-primary:hover { background: #5B4BD5; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
select.input, input.input, textarea.input { width: 100%; background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 12px; min-height: 42px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
label.field { display: grid; gap: 6px; font-weight: 500; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; margin: 0; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

/* ---------- layout grid & cards ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; } .span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; }
.card-sub { margin: 2px 0 0; }
.empty { padding: 28px 8px; text-align: center; color: var(--text-muted); }

.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.kpi .bubble { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); }
.kpi.hero { background: linear-gradient(135deg, #5B4BD5 0%, #4C51CF 55%, #3F5BCB 100%); border: 0; color: #fff; }
.kpi.hero .label, .kpi.hero .muted { color: rgba(255,255,255,.85); }
.kpi.hero .bubble { background: rgba(255,255,255,.18); color: #fff; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.wrap { white-space: normal; line-height: 1.35; border-radius: 10px; }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warning-soft); color: var(--warning); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.neutral { background: var(--surface-2); color: var(--text-muted); }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); }

.alerts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.alert { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; text-decoration: none; color: var(--text); border: 1px solid var(--border); background: var(--surface); }
.alert .dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.alert.danger .dot { background: var(--danger-soft); color: var(--danger); }
.alert.warn .dot { background: var(--warning-soft); color: var(--warning); }
.alert.info .dot { background: var(--info-soft); color: var(--info); }
.alert:hover { background: var(--surface-2); }

/* lists */
.list { display: grid; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--text-muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex: none; }
.logo { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 14px; }
.amount.in { color: var(--success); }
.group-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; margin: 14px 0 2px; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 600; padding: 10px 8px; background: var(--surface-2); white-space: nowrap; }
.table th:first-child { border-radius: 10px 0 0 10px; } .table th:last-child { border-radius: 0 10px 10px 0; }
.table td { padding: 12px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table td.num, .table th.num { text-align: right; }
.table tr:last-child td { border-bottom: 0; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.warn > span { background: var(--warning); } .progress.danger > span { background: var(--danger); }

/* charts */
.chart { position: relative; }
svg.bars { width: 100%; height: auto; display: block; overflow: visible; }
svg.bars .grid { stroke: var(--grid); stroke-width: 1; }
svg.bars .axis { fill: var(--text-muted); font-size: 11px; }
svg.bars .mark { fill: var(--chart-mark); }
svg.bars .hit { fill: transparent; }
svg.bars .bar.on .hit { fill: var(--accent-soft); }
svg.bars .bar:focus { outline: none; } svg.bars .bar:focus .hit { fill: var(--accent-soft); }
.tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: #151A2D; color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 12px; white-space: nowrap; pointer-events: none; font-weight: 600; }
[data-theme="dark"] .tip { background: #F3F4F8; color: #151A2D; }
.chart-table { margin-top: 8px; font-size: 12.5px; }
.chart-table summary { cursor: pointer; color: var(--text-muted); }
.chart-table table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.chart-table td, .chart-table th { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.chart-table .num { text-align: right; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) 2fr auto; align-items: center; gap: 10px; padding: 7px 0; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.hbar .track span { display: block; height: 100%; background: var(--chart-mark); border-radius: 999px; }

/* payment-card visual */
.cc { position: relative; border-radius: 18px; padding: 18px 20px; color: #fff; min-height: 170px; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
.cc::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; right: -70px; top: -90px; background: rgba(255,255,255,.12); }
.cc .cc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; position: relative; z-index: 1; }
.cc .cc-name { font-weight: 700; font-size: 16px; }
.cc .cc-num { font-size: 18px; letter-spacing: .14em; font-variant-numeric: tabular-nums; position: relative; z-index: 1; }
.cc .cc-foot { display: flex; justify-content: space-between; font-size: 12.5px; opacity: .92; position: relative; z-index: 1; }
.cc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.cc-card { display: grid; gap: 14px; align-content: start; }
.bill-controls { display: flex; align-items: center; gap: 12px; flex: none; }
.bonus { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--border); }
.bonus-top { display: flex; justify-content: space-between; gap: 8px; }

/* dialogs */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(11,14,26,.55); backdrop-filter: blur(2px); }
dialog form { padding: 22px; display: grid; gap: 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-error { color: var(--danger); font-weight: 500; min-height: 1em; margin: 0; }

/* auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent), var(--bg); }
.auth .card { width: min(420px, 100%); padding: 28px; }
.auth h1 { margin: 14px 0 4px; font-size: 22px; }
.auth form { display: grid; gap: 14px; margin-top: 18px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #151A2D; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 50; max-width: calc(100vw - 32px); }
[data-theme="dark"] .toast { background: #F3F4F8; color: #151A2D; }

.tabbar { display: none; }
.only-phone { display: none; }
.only-phone-list { display: none; }
.stack { display: grid; gap: 20px; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 12px; min-height: 120px; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- tablet: icon rail ---------- */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 18px 10px; align-items: center; }
  .brand span, .nav-label, .nav a span, .who, .side-foot .icon-btn { display: none; }
  .brand { padding: 4px 0 12px; }
  .nav a { justify-content: center; padding: 12px; }
  .side-foot { justify-content: center; }
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
  .span-3 { grid-column: span 6; }
}

/* ---------- phone: single column + bottom tab bar ---------- */
@media (max-width: 640px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 14px 16px 104px; }
  .topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); margin: -14px -16px 12px; padding: 14px 16px 10px; }
  .topbar h1 { font-size: 21px; }
  .grid { gap: 14px; }
  .span-3 { grid-column: span 6; }
  .kpi .value { font-size: 22px; }
  .card { padding: 16px; }
  .only-phone { display: grid; }
  .only-phone-list { display: grid; }
  .hide-phone { display: none !important; }
  .form-grid { grid-template-columns: 1fr; }
  .cc-grid { grid-template-columns: 1fr; }
  .alerts { grid-template-columns: 1fr; }
  .bill-row { flex-wrap: wrap; }
  .bill-row .bill-controls { width: 100%; padding-left: 50px; justify-content: space-between; }
  .bill-row .bill-controls .input { flex: 1; }
  .tabbar { display: flex; position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 20; justify-content: space-around; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 8px 6px; box-shadow: 0 10px 30px rgba(16,24,40,.14); }
  .tabbar a { display: grid; place-items: center; gap: 2px; min-width: 56px; min-height: 48px; border-radius: 14px; color: var(--text-muted); text-decoration: none; font-size: 11px; font-weight: 600; }
  .tabbar a[aria-current="page"] { color: var(--accent-ink); background: var(--accent-soft); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .seg { align-self: flex-start; }
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; }
}
