:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #1e293b;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --info: #0891b2;
    --info-soft: #cffafe;
    --purple: #7c3aed;
    --purple-soft: #ede9fe;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
}
.sidebar__brand {
    padding: 20px 20px 16px;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: .3px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar__brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--primary); }
.sidebar__section { padding: 14px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; font-weight: 600; }
.sidebar__nav { padding: 4px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar__link {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background .12s, color .12s;
}
.sidebar__link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar__link.active { background: var(--primary); color: #fff; }
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__footer { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar__user { color: #fff; font-weight: 600; margin-bottom: 2px; }

.main { flex: 1; margin-left: 240px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px;
    position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 18px; font-weight: 650; }
.topbar__actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 24px 28px 60px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600;
    cursor: pointer;
    transition: background .12s, border .12s, box-shadow .12s;
    background: var(--surface); color: var(--text);
    line-height: 1;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); }
.btn--default { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--default:hover { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #b91c1c; }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: #15803d; }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; }
.btn--icon { padding: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card__header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 650; font-size: 15px;
}
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat__label { color: var(--text-muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.stat__meta { font-size: 12.5px; color: var(--text-faint); margin-top: 4px; }
.stat__icon { position: absolute; top: 16px; right: 16px; width: 38px; height: 38px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.stat__icon svg { width: 20px; height: 20px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
    text-align: left; padding: 11px 16px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .muted { color: var(--text-muted); }
.row-link { cursor: pointer; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 1.4;
    white-space: nowrap;
}
.badge .bdot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--gray { background: #f1f5f9; color: #475569; }
.badge--blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge--green { background: var(--success-soft); color: #15803d; }
.badge--amber { background: var(--warning-soft); color: #b45309; }
.badge--red { background: var(--danger-soft); color: #b91c1c; }
.badge--cyan { background: var(--info-soft); color: #0e7490; }
.badge--purple { background: var(--purple-soft); color: #6d28d9; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field label .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--text-faint); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], input[type=url], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px; font-family: inherit;
    background: var(--surface); color: var(--text);
    transition: border .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; cursor: pointer; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.input-error { border-color: var(--danger) !important; }
.error-text { color: var(--danger); font-size: 12.5px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-weight: 500; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; }
.alert--success { background: var(--success-soft); color: #15803d; }
.alert--error { background: var(--danger-soft); color: #b91c1c; }
.alert--info { background: var(--info-soft); color: #0e7490; }

/* ---------- Misc ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.page-head .sub { color: var(--text-muted); margin-top: 3px; font-size: 13.5px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .search { flex: 1; max-width: 340px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs a { padding: 9px 16px; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty svg { width: 44px; height: 44px; color: var(--border-strong); margin-bottom: 12px; }
.empty h3 { font-size: 16px; color: var(--text); margin-bottom: 4px; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; font-size: 14px; }
.dl dt { color: var(--text-muted); font-weight: 500; }
.dl dd { color: var(--text); font-weight: 500; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 22px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.pagination { display: flex; gap: 4px; margin-top: 18px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border-radius: 6px; font-size: 13px; border: 1px solid var(--border); color: var(--text-muted); background: var(--surface); }
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination .active span { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled span { opacity: .4; }

/* ---------- Totals box ---------- */
.totals { margin-left: auto; width: 320px; font-size: 14px; }
.totals .row { display: flex; justify-content: space-between; padding: 7px 0; }
.totals .row.grand { border-top: 2px solid var(--border-strong); margin-top: 6px; padding-top: 12px; font-size: 17px; font-weight: 700; }
.totals .row.grand .amount { color: var(--primary); }

/* ---------- Line editor ---------- */
.lines-table { width: 100%; border-collapse: collapse; }
.lines-table th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--text-muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
.lines-table td { padding: 6px 5px; vertical-align: top; border-bottom: 1px solid var(--border); }
.lines-table input, .lines-table select, .lines-table textarea { padding: 7px 8px; font-size: 13.5px; }
.lines-table textarea { min-height: 34px; }
.lines-table .col-drag { width: 24px; color: var(--text-faint); cursor: grab; text-align: center; }
.lines-table .col-total { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; padding-top: 14px; }
.lines-table .col-del { width: 34px; }
.line-remove { color: var(--text-faint); cursor: pointer; background: none; border: none; padding: 6px; border-radius: 6px; }
.line-remove:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); padding: 20px; }
.auth__card { background: var(--surface); border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); width: 100%; max-width: 400px; padding: 36px 34px; }
.auth__brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth__brand .dot { width: 12px; height: 12px; border-radius: 4px; background: var(--primary); }
.auth__sub { color: var(--text-muted); margin-bottom: 26px; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s; z-index: 50; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .two-col { grid-template-columns: 1fr; }
    .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
    .totals { width: 100%; }
    .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }
