:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --bg-hover: #334155;
    --surface: #ffffff;
    --surface-hover: #f8fafc;
    --muted: #64748b;
    --muted-light: #94a3b8;
    --line: #e2e8f0;
    --line-light: #f1f5f9;
    --text: #0f172a;
    --text-soft: #334155;
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --primary-bg: #eff6ff;
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #0891b2;
    --info-bg: #ecfeff;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.03);
    --shadow-md: 0 2px 8px rgba(15,23,42,.08), 0 8px 32px rgba(15,23,42,.04);
    --shadow-lg: 0 4px 16px rgba(15,23,42,.1), 0 16px 48px rgba(15,23,42,.06);
    --transition: .2s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--line-light);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

/* ── Sidebar ───────────────────────────── */
.sidebar {
    width: 250px;
    flex: 0 0 250px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
    border-right: 1px solid rgba(255,255,255,.06);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar .brand {
    padding: 20px 22px 16px;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.01em;
    border-bottom: 1px solid rgba(255,255,255,.06);
    background: linear-gradient(135deg, rgba(37,99,235,.15) 0%, rgba(37,99,235,.05) 100%);
}
.sidebar .brand small {
    display: block;
    font-weight: 400;
    color: #64748b;
    font-size: 11px;
    margin-top: 3px;
    letter-spacing: .03em;
}

.sidebar nav { padding: 8px 0; flex: 1; }

.sidebar .nav-group {
    padding: 16px 22px 6px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #475569;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar .nav-group::after {
    content: '';
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #475569;
    transition: transform var(--transition);
}
.sidebar .nav-group.collapsed::after {
    transform: rotate(-90deg);
}
.sidebar .nav-group.collapsed + .nav-items {
    display: none !important;
}

.sidebar a {
    display: block;
    padding: 8px 22px;
    color: #94a3b8;
    font-size: 13px;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    margin: 1px 8px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.sidebar a:hover {
    background: rgba(255,255,255,.06);
    color: #e2e8f0;
    text-decoration: none;
}
.sidebar a.active {
    background: rgba(37,99,235,.18);
    border-left-color: var(--primary-light);
    color: #fff;
    font-weight: 500;
}

/* ── Main ──────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 26px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 3px rgba(15,23,42,.04);
}
.topbar .actions { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.topbar .user {
    color: var(--muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.content { padding: 24px 28px; flex: 1; }

/* ── Cards ─────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card .card-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card .card-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.card .card-body { padding: 20px; }

/* ── Stats ─────────────────────────────── */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: all var(--transition);
}
.stat:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.stat::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
    border-radius: 4px 0 0 4px;
}
.stat.blue::before { background: var(--primary); }
.stat.green::before { background: var(--success); }
.stat.orange::before { background: var(--warning); }
.stat.red::before { background: var(--danger); }
.stat.cyan::before { background: var(--info); }
.stat .label {
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
}
.stat .value {
    font-size: 24px;
    font-weight: 800;
    margin-top: 6px;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
}

/* ── Grid ──────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }

/* ── Tables ────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line-light);
}
th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    background: var(--surface-hover);
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 1;
}
tbody tr {
    transition: background var(--transition);
}
tbody tr:hover { background: var(--primary-bg); }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:nth-child(even):hover { background: var(--primary-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Forms ─────────────────────────────── */
.form-row { margin-bottom: 16px; }
label {
    display: block;
    font-weight: 600;
    font-size: 12.5px;
    margin-bottom: 5px;
    color: var(--text-soft);
}
label .req { color: var(--danger); }
input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="password"], input[type="time"], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: all var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
    background: #fff;
}
input::placeholder, textarea::placeholder { color: var(--muted-light); }
textarea { min-height: 80px; resize: vertical; }

.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; accent-color: var(--primary); }

/* ── Buttons ───────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:hover {
    background: var(--primary-dark);
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(37,99,235,.3);
    transform: translateY(-1px);
}
.btn:active { transform: translateY(0); box-shadow: none; }
.btn.secondary {
    background: #fff;
    color: var(--text-soft);
    border-color: var(--line);
}
.btn.secondary:hover {
    background: var(--surface-hover);
    border-color: #cbd5e1;
    box-shadow: var(--shadow);
}
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; box-shadow: 0 2px 8px rgba(220,38,38,.3); }
.btn.success { background: var(--success); }
.btn.success:hover { background: #047857; }
.btn.small { padding: 5px 12px; font-size: 12px; border-radius: 5px; }
.btn.ghost {
    background: transparent;
    color: var(--primary);
    border-color: transparent;
}
.btn.ghost:hover {
    background: var(--primary-bg);
    box-shadow: none;
    transform: none;
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Alerts ────────────────────────────── */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    border: 1px solid;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert.success { background: var(--success-bg); border-color: #a7f3d0; color: #065f46; }
.alert.error { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.alert.warning { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }
.alert.info { background: var(--info-bg); border-color: #a5f3fc; color: #155e75; }

/* ── Badges ────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
}
.badge.open { background: #dbeafe; color: #1e40af; }
.badge.confirmed { background: #d1fae5; color: #065f46; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }
.badge.customer { background: #dcfce7; color: #166534; }
.badge.supplier { background: #fef3c7; color: #92400e; }

/* ── Toolbar ───────────────────────────── */
.toolbar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar .form-row { margin-bottom: 0; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* ── Pagination ────────────────────────── */
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 14px 20px;
    flex-wrap: wrap;
    border-top: 1px solid var(--line-light);
}
.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    background: #fff;
    font-weight: 500;
    transition: all var(--transition);
}
.pagination a:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}
.pagination .current {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}
.pagination .disabled {
    color: var(--muted-light);
    cursor: default;
}

/* ── Filter Bar ────────────────────────── */
.filter-bar {
    padding: 14px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 2px rgba(15,23,42,.03);
}
.filter-form { display: block; }
.filter-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-end;
}
.filter-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 120px;
}
.filter-field.wide {
    min-width: 150px;
    flex: 1;
}
.filter-field label {
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 0;
}
.filter-field input,
.filter-field select {
    padding: 7px 12px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--surface-hover);
    color: var(--text);
    outline: none;
    transition: all var(--transition);
}
.filter-field input:focus,
.filter-field select:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.filter-field input::placeholder { color: var(--muted-light); }
.filter-actions { min-width: auto; }
.filter-btn-row { display: flex; gap: 6px; }

/* ── Utilities ─────────────────────────── */
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-family: "SF Mono", "Cascadia Code", "Consolas", monospace; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }
.nowrap { white-space: nowrap; }
.empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--muted-light);
    font-size: 13.5px;
}
.link-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.link-list a {
    display: block;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    box-shadow: var(--shadow);
    transition: all var(--transition);
}
.link-list a:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
}
.link-list a strong { display: block; margin-bottom: 4px; font-size: 14px; }
.link-list a span { color: var(--muted); font-size: 12.5px; }

/* ── Auth ──────────────────────────────── */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e40af 50%, #2563eb 100%);
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(2,6,23,.4);
    padding: 36px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.auth-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: 13.5px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

/* ── Line Items ────────────────────────── */
.line-items th, .line-items td { padding: 7px 8px; }
.line-items input, .line-items select { padding: 6px 8px; font-size: 13px; }
.line-items td { vertical-align: middle; }

/* ── Print ─────────────────────────────── */
.print-body { background: #fff; color: #000; padding: 24px; font-size: 13px; }
.print-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #000; padding-bottom: 12px; margin-bottom: 16px; }
.print-head h1 { margin: 0 0 4px; font-size: 20px; }
.print-meta { text-align: right; font-size: 12.5px; }
.print-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.print-table th, .print-table td { border: 1px solid #94a3b8; padding: 6px 8px; }
.print-table th { background: #f1f5f9; }
.print-totals { width: 320px; margin-left: auto; }
.print-totals td { border: none; padding: 4px 8px; }
.print-totals tr:last-child td { border-top: 1px solid #000; font-weight: 700; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
}

.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Responsive ────────────────────────── */
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .sidebar { display: none; }
    .sidebar.open { display: flex; position: fixed; z-index: 40; }
    .content { padding: 16px; }
    .stats { grid-template-columns: 1fr 1fr; }
}
