:root {
    --color-bg: #f6f7fb;
    --color-surface: #ffffff;
    --color-border: #e3e7ee;
    --color-border-strong: #cbd2dc;
    --color-text: #1d2433;
    --color-muted: #6b7280;
    --color-primary: #0d6efd;
    --color-primary-dark: #0a58ca;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-info: #0891b2;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
    --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    font-size: 14px;
    line-height: 1.5;
}

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

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: #0f172a;
    color: #e2e8f0;
    padding: 24px 16px;
    flex-shrink: 0;
}
.sidebar .brand {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}
.sidebar .brand-sub { font-size: 12px; color: #94a3b8; margin-bottom: 24px; }
.sidebar nav a {
    display: block;
    padding: 9px 12px;
    color: #cbd5e1;
    border-radius: 6px;
    margin-bottom: 2px;
    font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--color-primary); color: #fff; }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; color: #64748b; margin: 18px 12px 6px; letter-spacing: 0.06em; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 56px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.topbar .user .role-badge { background: #e0e7ff; color: #3730a3; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.content { padding: 24px; flex: 1; }

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page-header .subtitle { color: var(--color-muted); margin-top: 4px; font-size: 13px; }

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card + .card { margin-top: 16px; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--color-border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.card-body { padding: 18px; }

/* Stats grid */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}
.stat-card .label { color: var(--color-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; font-weight: 600; }
.stat-card .value { font-size: 24px; font-weight: 700; color: var(--color-text); }
.stat-card.primary .value { color: var(--color-primary); }
.stat-card.success .value { color: var(--color-success); }
.stat-card.danger .value { color: var(--color-danger); }
.stat-card.warning .value { color: var(--color-warning); }

/* Forms */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #374151; }
.form-control, .form-select, textarea.form-control {
    width: 100%;
    padding: 8px 11px;
    font-size: 14px;
    border: 1px solid var(--color-border-strong);
    border-radius: 6px;
    background: #fff;
    color: var(--color-text);
    font-family: inherit;
}
.form-control:focus, .form-select:focus, textarea.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}
textarea.form-control { resize: vertical; min-height: 70px; }
.form-help { font-size: 12px; color: var(--color-muted); margin-top: 4px; }
.form-error { color: var(--color-danger); font-size: 12px; margin-top: 4px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    background: #fff;
    color: var(--color-text);
    border-color: var(--color-border-strong);
    font-family: inherit;
}
.btn:hover { text-decoration: none; background: #f8fafc; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-success:hover { background: #15803d; border-color: #15803d; color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--color-border); font-size: 13px; vertical-align: middle; }
.data-table th { background: #f8fafc; font-weight: 600; color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table .text-right { text-align: right; }
.data-table .text-center { text-align: center; }
.data-table tfoot td { font-weight: 600; background: #f8fafc; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-confirmed { background: #dbeafe; color: #1e40af; }
.badge-invoiced { background: #ede9fe; color: #6d28d9; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-open { background: #fef3c7; color: #92400e; }
.badge-partial { background: #fed7aa; color: #9a3412; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-in_stock { background: #dcfce7; color: #166534; }
.badge-reserved { background: #fef3c7; color: #92400e; }
.badge-sold { background: #e2e8f0; color: #475569; }
.badge-written_off { background: #fee2e2; color: #991b1b; }

/* Alerts */
.alert { padding: 11px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert ul { margin: 4px 0 0 18px; padding: 0; }

/* Auth */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%); padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 12px; padding: 36px; box-shadow: 0 25px 60px rgba(15,23,42,0.25); }
.auth-card .brand { text-align: center; margin-bottom: 28px; }
.auth-card .brand h1 { margin: 0 0 4px; font-size: 28px; font-weight: 700; color: var(--color-text); letter-spacing: -0.02em; }
.auth-card .brand p { margin: 0; color: var(--color-muted); font-size: 13px; }

/* Utilities */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.text-muted { color: var(--color-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tag-list { display: flex; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--color-muted); font-weight: 600; }
.kv dd { margin: 0; }
.divider { height: 1px; background: var(--color-border); margin: 16px 0; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--color-muted); }
.empty-state strong { display: block; color: var(--color-text); margin-bottom: 4px; font-size: 15px; }

/* Print/PDF */
@media print {
    .no-print { display: none !important; }
}

/* Document layout (invoice/receipt) */
.doc {
    max-width: 820px;
    margin: 0 auto;
    background: #fff;
    padding: 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; padding-bottom: 18px; border-bottom: 2px solid var(--color-text); gap: 24px; flex-wrap: wrap; }
.doc-header .brand h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.doc-header .brand p { margin: 4px 0 0; color: var(--color-muted); font-size: 13px; }
.doc-header .meta { text-align: right; font-size: 13px; }
.doc-header .meta .doc-title { font-size: 22px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 22px; }
.doc-parties .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted); font-weight: 600; margin-bottom: 4px; }
.doc table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.doc table th { background: #f1f5f9; padding: 10px 12px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--color-border); }
.doc table td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 13px; }
.doc-totals { width: 320px; margin-left: auto; }
.doc-totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.doc-totals .row.grand { border-top: 2px solid var(--color-text); padding-top: 10px; margin-top: 6px; font-weight: 700; font-size: 16px; }
.doc-footer { margin-top: 32px; font-size: 12px; color: var(--color-muted); border-top: 1px solid var(--color-border); padding-top: 16px; text-align: center; }
