/* =====================================================================
   Renewly — application styles
   Theme variables (--primary, --accent, --sidebar, --font, --font-heading,
   --fs, --radius) are injected from Settings → Branding.
   ===================================================================== */

:root {
  --primary: #1570EF;
  --accent: #12C2B9;
  --sidebar: #0B1A3A;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Plus Jakarta Sans', var(--font);
  --fs: 14px;
  --radius: 10px;

  --primary-600: color-mix(in srgb, var(--primary) 88%, #000);
  --primary-50: color-mix(in srgb, var(--primary) 8%, #fff);
  --primary-100: color-mix(in srgb, var(--primary) 15%, #fff);
  --primary-ring: color-mix(in srgb, var(--primary) 28%, transparent);
  --accent-50: color-mix(in srgb, var(--accent) 12%, #fff);

  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-3: #EEF2F7;
  --border: #E4E8EF;
  --border-strong: #D0D6E0;
  --text: #101828;
  --text-2: #475467;
  --text-3: #8A93A5;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .06);

  --success: #079455; --success-bg: #E7F8EF; --success-fg: #067647;
  --warning: #DC6803; --warning-bg: #FEF4E6; --warning-fg: #B54708;
  --danger: #D92D20;  --danger-bg: #FEECEB;  --danger-fg: #B42318;
  --info: #1570EF;    --info-bg: #EAF2FE;    --info-fg: #175CD3;
  --muted-bg: #F0F2F5; --muted-fg: #475467;

  --sidebar-w: 252px;
  --topbar-h: 64px;
}

[data-theme="dark"] {
  --bg: #0B1120;
  --surface: #111827;
  --surface-2: #151E2E;
  --surface-3: #1C2738;
  --border: #243044;
  --border-strong: #334155;
  --text: #EEF2F7;
  --text-2: #B4BECD;
  --text-3: #7C8899;
  --primary-50: color-mix(in srgb, var(--primary) 16%, #111827);
  --primary-100: color-mix(in srgb, var(--primary) 26%, #111827);
  --accent-50: color-mix(in srgb, var(--accent) 18%, #111827);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 3px rgba(0, 0, 0, .35);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .55);
  --success-bg: rgba(7, 148, 85, .16); --success-fg: #47CD89;
  --warning-bg: rgba(220, 104, 3, .16); --warning-fg: #FDB022;
  --danger-bg: rgba(217, 45, 32, .16);  --danger-fg: #F97066;
  --info-bg: rgba(21, 112, 239, .18);   --info-fg: #84ADFF;
  --muted-bg: #1F2A3C; --muted-fg: #B4BECD;
  color-scheme: dark;
}

/* ------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--fs); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 1rem; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}
h1, h2, h3, h4, h5 { font-family: var(--font-heading); color: var(--text); margin: 0; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.08rem; font-weight: 650; }
h4 { font-size: .98rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; background: var(--surface-3); padding: .12em .4em; border-radius: 5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.icon { flex-shrink: 0; vertical-align: middle; }
::selection { background: var(--primary-100); }

/* ------------------------------------------------------------- layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--sidebar); color: rgba(255, 255, 255, .72);
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, .04);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 18px 20px 14px; color: #fff; }
.sidebar-brand img { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; background: rgba(255, 255, 255, .96); padding: 3px; }
.sidebar-brand .name { font-family: var(--font-heading); font-weight: 700; font-size: 1.12rem; letter-spacing: -0.01em; color: #fff; line-height: 1.1; }
.sidebar-brand .brand-tag { font-size: .72rem; color: rgba(255, 255, 255, .5); margin-top: 2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: rgba(255, 255, 255, .38); font-weight: 600; padding: 16px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 8.5px 11px; border-radius: 8px;
  color: rgba(255, 255, 255, .72); font-weight: 500; font-size: .935rem; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: color-mix(in srgb, var(--primary) 85%, transparent); color: #fff; box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--primary) 70%, transparent); }
.nav-item .count { margin-left: auto; background: rgba(255, 255, 255, .12); color: #fff; font-size: .7rem; font-weight: 600; padding: 1px 7px; border-radius: 10px; }
.nav-item .count.alert { background: #F04438; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .06); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; color: #fff; }
.user-chip:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.user-chip .meta { min-width: 0; flex: 1; }
.user-chip .meta div:first-child { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .meta div:last-child { font-size: .74rem; color: rgba(255, 255, 255, .5); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .78rem; color: #fff; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}
.avatar.sm { width: 28px; height: 28px; font-size: .7rem; }
.avatar.lg { width: 48px; height: 48px; font-size: 1rem; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 28px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px); -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.topbar-search { position: relative; flex: 1; max-width: 420px; }
.topbar-search input[type=search] { padding-left: 38px; background: var(--surface-2); border-color: transparent; }
.topbar-search input[type=search]:focus { background: var(--surface); }
.topbar-search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.topbar-search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: .7rem; color: var(--text-3); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; background: var(--surface); font-family: var(--font); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: 420px; overflow-y: auto; display: none; z-index: 60; }
.search-results.open { display: block; }
.search-results a { display: flex; gap: 10px; align-items: center; padding: 9px 14px; color: var(--text); border-bottom: 1px solid var(--border); }
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a.focus { background: var(--surface-2); }
.search-results .sr-type { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-left: auto; }
.search-results .sr-empty { padding: 16px; color: var(--text-3); text-align: center; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 26px 28px 48px; max-width: 1480px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .crumbs { font-size: .82rem; color: var(--text-3); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.page-head .crumbs a { color: var(--text-3); }
.page-head .crumbs a:hover { color: var(--primary); }
.page-head .sub { color: var(--text-2); margin-top: 4px; font-size: .93rem; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------- cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px); box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 18px; }
.grid > .card + .card, .grid > * > .card + .card:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 1rem; }
.card-head .sub { font-size: .82rem; color: var(--text-3); margin-top: 2px; }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 calc(var(--radius) + 2px) calc(var(--radius) + 2px); }
.card.flush .card-body { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.grid-main-wide { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.stack > * + * { margin-top: 18px; }

/* KPI tiles */
.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.kpi .kpi-label { font-size: .82rem; color: var(--text-2); font-weight: 500; }
.kpi .kpi-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.kpi .kpi-value { font-family: var(--font-heading); font-size: 1.62rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi .kpi-foot { font-size: .8rem; color: var(--text-3); margin-top: 6px; }
.kpi a.stretched::after { content: ''; position: absolute; inset: 0; }
.tone-primary { background: var(--primary-50); color: var(--primary); }
.tone-success { background: var(--success-bg); color: var(--success-fg); }
.tone-warning { background: var(--warning-bg); color: var(--warning-fg); }
.tone-danger { background: var(--danger-bg); color: var(--danger-fg); }
.tone-accent { background: var(--accent-50); color: color-mix(in srgb, var(--accent) 70%, #000); }
[data-theme="dark"] .tone-accent { color: var(--accent); }

/* ------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: calc(var(--radius) - 2px);
  font: 600 .9rem/1 var(--font); letter-spacing: 0; white-space: nowrap;
  border: 1px solid transparent; cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
  text-decoration: none; user-select: none;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-ring); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .1), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--primary-600); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); color: #fff; }
.btn-danger-soft { background: var(--danger-bg); color: var(--danger-fg); }
.btn-danger-soft:hover { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); color: var(--danger-fg); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: color-mix(in srgb, var(--success) 85%, #000); color: #fff; }
.btn-wa { background: #25D366; color: #fff; }
.btn-wa:hover { background: #1DA851; color: #fff; }
.btn-ai { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; }
.btn-ai:hover { filter: brightness(1.06); color: #fff; }
.btn-sm { height: 32px; padding: 0 11px; font-size: .84rem; gap: 6px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: .78rem; gap: 4px; border-radius: 6px; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
.btn-xs.btn-icon { width: 26px; }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }
.btn-group { display: inline-flex; }
.btn-group .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.btn-group .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; font-weight: 500; }

/* ------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px 18px; }
.col-12 { grid-column: span 12; } .col-9 { grid-column: span 9; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-5 { grid-column: span 5; } .col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; }
.field label, label.label { display: block; font-size: .84rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field .hint { font-size: .78rem; color: var(--text-3); margin-top: 5px; }
.field .req { color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=tel], input[type=search], input[type=color], select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: calc(var(--radius) - 2px);
  background: var(--surface); color: var(--text); font: 400 .935rem var(--font); transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
textarea { height: auto; min-height: 92px; padding: 10px 12px; line-height: 1.55; resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .84rem; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A93A5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type=color] { padding: 3px; width: 52px; cursor: pointer; }
input[readonly] { background: var(--surface-2); }
.input-group { display: flex; }
.input-group > :first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > :last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.input-addon { display: inline-flex; align-items: center; padding: 0 12px; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-2); font-size: .88rem; border-radius: calc(var(--radius) - 2px); white-space: nowrap; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: .92rem; }
.check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--primary); flex-shrink: 0; }
.check .check-text small { display: block; color: var(--text-3); font-size: .8rem; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: .92rem; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 38px; height: 22px; border-radius: 22px; background: var(--border-strong); position: relative; transition: background .2s; flex-shrink: 0; }
.switch .track::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 4px var(--primary-ring); }
.form-section { padding: 22px 0; border-bottom: 1px solid var(--border); }
.form-section:first-child { padding-top: 0; }
.form-section:last-child { border-bottom: 0; padding-bottom: 0; }
.form-section-head { margin-bottom: 14px; }
.form-section-head h4 { margin-bottom: 2px; }
.form-section-head p { color: var(--text-3); font-size: .85rem; margin: 0; }
.seg { display: inline-flex; background: var(--surface-3); padding: 3px; border-radius: 9px; gap: 2px; }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: inline-block; padding: 6px 14px; border-radius: 7px; font-size: .86rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .73rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 600; padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table .nowrap { white-space: nowrap; }
.table .primary-cell { font-weight: 600; color: var(--text); }
.table .primary-cell a { color: var(--text); }
.table .primary-cell a:hover { color: var(--primary); }
.table .sub { font-size: .8rem; color: var(--text-3); }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { opacity: .75; }
.table tr:hover .actions .btn { opacity: 1; }
.table-compact td { padding: 9px 14px; }
.table tfoot td { font-weight: 600; background: var(--surface-2); }
.row-link { cursor: pointer; }

/* ------------------------------------------------------------- badges & misc */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: .74rem; font-weight: 600; line-height: 1.6; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.no-dot::before { display: none; }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-muted { background: var(--muted-bg); color: var(--muted-fg); }
.badge-primary { background: var(--primary-50); color: var(--primary); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: .76rem; font-weight: 500; }
.text-muted { color: var(--text-3); } .text-2 { color: var(--text-2); }
.text-success { color: var(--success-fg); } .text-danger { color: var(--danger-fg); } .text-warning { color: var(--warning-fg); }
.text-sm { font-size: .86rem; } .text-xs { font-size: .78rem; } .text-lg { font-size: 1.1rem; }
.fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mt-4 { margin-top: 26px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; } .gap-1 { gap: 6px; } .gap-2 { gap: 12px; } .gap-3 { gap: 18px; } .wrap { flex-wrap: wrap; }
.ml-auto { margin-left: auto; } .w-100 { width: 100%; } .hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--radius); border: 1px solid; font-size: .92rem; margin-bottom: 16px; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 25%, transparent); color: var(--success-fg); }
.alert-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 25%, transparent); color: var(--danger-fg); }
.alert-warning { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 25%, transparent); color: var(--warning-fg); }
.alert-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 25%, transparent); color: var(--info-fg); }
.alert a { color: inherit; text-decoration: underline; font-weight: 600; }

.toasts { position: fixed; right: 20px; top: 76px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); box-shadow: var(--shadow-lg); padding: 12px 14px; border-radius: var(--radius); font-size: .9rem; animation: toastIn .25s ease; }
.toast.success { border-left-color: var(--success); } .toast.success .icon { color: var(--success); }
.toast.danger { border-left-color: var(--danger); } .toast.danger .icon { color: var(--danger); }
.toast.warning { border-left-color: var(--warning); } .toast.warning .icon { color: var(--warning); }
.toast .close { margin-left: auto; background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.empty-state { text-align: center; padding: 56px 24px; }
.empty-state .empty-icon { width: 64px; height: 64px; border-radius: 16px; background: var(--primary-50); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.empty-state h3 { margin-bottom: 6px; }
.empty-state p { color: var(--text-2); max-width: 440px; margin: 0 auto 18px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button { padding: 10px 14px; font-weight: 600; font-size: .9rem; color: var(--text-2); border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; display: inline-flex; gap: 7px; align-items: center; font-family: var(--font); }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { background: var(--surface-3); color: var(--text-2); font-size: .72rem; padding: 0 7px; border-radius: 10px; }
.tab-panel { display: none; } .tab-panel.active { display: block; }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.filters input[type=search], .filters input[type=text] { max-width: 280px; }
.filters select { width: auto; min-width: 150px; }
.chip-filter { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-filter a { padding: 5px 12px; border-radius: 20px; font-size: .84rem; font-weight: 600; color: var(--text-2); background: var(--surface-3); }
.chip-filter a:hover { color: var(--text); }
.chip-filter a.active { background: var(--text); color: var(--surface); }
.chip-filter a .n { opacity: .6; margin-left: 4px; font-weight: 500; }

.pager { display: flex; gap: 4px; justify-content: flex-end; padding: 14px 16px; border-top: 1px solid var(--border); }
.pager a { min-width: 32px; height: 32px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border-radius: 7px; color: var(--text-2); font-weight: 600; font-size: .86rem; border: 1px solid var(--border); background: var(--surface); }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-gap { padding: 0 4px; color: var(--text-3); align-self: center; }

/* dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 70; display: none; }
.dropdown.open .dropdown-menu { display: block; animation: toastIn .15s ease; }
.dropdown-menu.left { left: 0; right: auto; }
.dropdown-menu a, .dropdown-menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: var(--text); font: 500 .9rem var(--font); background: none; border: 0; cursor: pointer; text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); }
.dropdown-menu .icon { color: var(--text-3); }
.dropdown-menu .danger, .dropdown-menu .danger .icon { color: var(--danger-fg); }
.dropdown-menu .sep { height: 1px; background: var(--border); margin: 5px 2px; }
.dropdown-menu .menu-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); font-weight: 600; padding: 6px 10px 4px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 30, .55); backdrop-filter: blur(2px); z-index: 90; display: none; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: calc(var(--radius) + 4px); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; animation: toastIn .2s ease; }
.modal.lg { max-width: 820px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 1.05rem; }
.modal-body { padding: 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 calc(var(--radius) + 4px) calc(var(--radius) + 4px); }

/* line items editor */
.items-editor { width: 100%; border-collapse: separate; border-spacing: 0; }
.items-editor th { font-size: .73rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 600; text-align: left; padding: 0 6px 8px; }
.items-editor td { padding: 5px 6px; vertical-align: top; }
.items-editor .drag { color: var(--text-3); cursor: grab; padding-top: 14px; width: 18px; }
.items-editor .line-amount { padding-top: 14px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items-editor textarea.details { min-height: 34px; height: 34px; margin-top: 6px; font-size: .84rem; padding: 7px 10px; }
.items-editor tr.dragging { opacity: .4; }
.items-editor .opts { display: flex; gap: 12px; margin-top: 6px; font-size: .8rem; color: var(--text-2); }
.items-editor .opts label { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.items-editor .opts input { accent-color: var(--primary); }
.totals-box { margin-left: auto; width: 100%; max-width: 360px; }
.totals-box .row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; font-size: .93rem; gap: 12px; }
.totals-box .row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; font-size: 1.15rem; font-weight: 700; font-family: var(--font-heading); }
.totals-box input { height: 32px; width: 110px; text-align: right; }

/* document preview */
.doc-frame { background: var(--surface-3); border-radius: calc(var(--radius) + 2px); padding: 26px; overflow-x: auto; }
.doc-paper { width: 794px; margin: 0 auto; transform-origin: top left; background: #fff; box-shadow: 0 2px 6px rgba(16,24,40,.08), 0 18px 40px -12px rgba(16,24,40,.25); border-radius: 4px; overflow: hidden; color: #1f2633; }

/* key-value list */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 9px 14px; font-size: .9rem; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); font-weight: 500; word-break: break-word; }

/* lists */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: .92rem; color: var(--text); }
.list-item .li-sub { font-size: .8rem; color: var(--text-3); }
.list-item .li-end { text-align: right; flex-shrink: 0; }
.date-chip { width: 44px; text-align: center; border-radius: 9px; background: var(--surface-3); padding: 5px 0; flex-shrink: 0; line-height: 1.1; }
.date-chip .d { font-weight: 700; font-size: 1.05rem; font-family: var(--font-heading); }
.date-chip .m { font-size: .66rem; text-transform: uppercase; color: var(--text-3); font-weight: 600; letter-spacing: .05em; }
.date-chip.danger { background: var(--danger-bg); color: var(--danger-fg); }
.date-chip.warning { background: var(--warning-bg); color: var(--warning-fg); }

/* chart */
.chart { width: 100%; height: 240px; }
.chart .bar-a { fill: var(--primary); }
.chart .bar-b { fill: var(--accent); }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.legend { display: flex; gap: 16px; font-size: .82rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.progress { height: 6px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 6px; }

/* settings layout */
.settings-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-h) + 20px); display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; font-size: .92rem; }
.settings-nav a:hover { background: var(--surface); color: var(--text); }
.settings-nav a.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); font-weight: 600; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.swatch:hover { transform: scale(1.08); }
.theme-preset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; cursor: pointer; display: flex; gap: 10px; align-items: center; background: var(--surface); font-size: .86rem; font-weight: 600; }
.theme-preset:hover { border-color: var(--primary); }
.theme-preset .pv { display: flex; width: 54px; height: 34px; border-radius: 6px; overflow: hidden; flex-shrink: 0; }
.theme-preset .pv i { flex: 1; }
.logo-box { width: 100%; height: 96px; border: 1px dashed var(--border-strong); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; background: repeating-conic-gradient(var(--surface-3) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px; padding: 10px; }
.logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-box.dark { background: var(--sidebar); }
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table input { width: 17px; height: 17px; accent-color: var(--primary); }

.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: ui-monospace, Menlo, monospace; font-size: .82rem; }
pre.code-block { background: #0B1220; color: #D7E1F0; padding: 14px 16px; border-radius: var(--radius); font-size: .82rem; overflow-x: auto; line-height: 1.6; margin: 0; white-space: pre-wrap; word-break: break-all; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 14px; font-size: .88rem; }
.timeline-item::before { content: ''; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline-item.ok::before { border-color: var(--success); }
.timeline-item.bad::before { border-color: var(--danger); }
.timeline-item .t { color: var(--text-3); font-size: .78rem; }

.ai-panel { border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border)); background: linear-gradient(180deg, var(--primary-50), var(--surface) 70%); }
.ai-badge { display: inline-flex; gap: 6px; align-items: center; font-size: .75rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .06em; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
.spinner.dark { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* auth pages */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: var(--sidebar); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side::before { content: ''; position: absolute; width: 560px; height: 560px; border-radius: 50%; right: -180px; bottom: -200px; background: radial-gradient(circle, color-mix(in srgb, var(--primary) 55%, transparent), transparent 70%); }
.auth-side::after { content: ''; position: absolute; width: 380px; height: 380px; border-radius: 50%; left: -120px; top: -140px; background: radial-gradient(circle, color-mix(in srgb, var(--accent) 35%, transparent), transparent 70%); }
.auth-side > * { position: relative; z-index: 1; }
.auth-side h2 { color: #fff; font-size: 2rem; line-height: 1.2; max-width: 420px; }
.auth-side ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 12px; }
.auth-side li { display: flex; gap: 10px; align-items: center; color: rgba(255,255,255,.82); }
.auth-side li .icon { color: var(--accent); }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .logo { max-height: 64px; max-width: 220px; margin-bottom: 26px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 6px; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .grid-main-wide { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 20px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .sidebar-overlay.open { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .topbar-search kbd { display: none; }
}
@media (max-width: 640px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid > [class*="col-"] { grid-column: span 12; }
  .page-head { align-items: flex-start; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .hide-sm { display: none !important; }
  .doc-frame { padding: 0; background: none; }
  .topbar-search { max-width: none; }
}

@media print {
  .sidebar, .topbar, .page-head, .no-print, .toasts { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .doc-frame { padding: 0; background: none; }
  .doc-paper { box-shadow: none; width: 100%; }
  body { background: #fff; }
}

/* items editor column sizing */
.items-editor td:nth-child(2) { min-width: 260px; }
.items-editor td:nth-child(3) input { width: 76px; }
.items-editor td:nth-child(4) input { width: 124px; }

.table .primary-cell { white-space: nowrap; }
