:root {
    --sidebar-bg: #1a2332;
    --sidebar-text: #c8d1dc;
    --sidebar-active: #ffffff;
    --sidebar-hover: #253347;
    --content-bg: #f5f6fa;
    --card-bg: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --accent: #3b6cf5;
    --accent-hover: #2b55cc;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #e5e7eb;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--content-bg);
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--sidebar-active);
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.nav-section {
    padding: 16px 16px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(200,209,220,0.5);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-active); }
.nav-item.active { background: var(--sidebar-hover); color: var(--sidebar-active); font-weight: 500; }
.nav-item.disabled { opacity: 0.35; pointer-events: none; }

.nav-icon { font-size: 10px; width: 16px; text-align: center; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 8px 0;
}

.sidebar-user {
    padding: 12px 16px 8px;
    font-size: 13px;
    color: rgba(200,209,220,0.6);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logout-link {
    color: rgba(200,209,220,0.4);
    text-decoration: none;
    font-size: 12px;
}
.logout-link:hover { color: var(--danger); }

/* --- Content --- */

.content {
    margin-left: 240px;
    flex: 1;
    padding: 32px;
    min-height: 100vh;
}

/* --- Page Header --- */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Cards --- */

.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.card h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h2 { margin-bottom: 0; }

/* --- Stats --- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stats-grid-small {
    grid-template-columns: repeat(3, 1fr);
}

.stat-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    border: 1px solid var(--border);
}

.stat-mini { padding: 14px 16px; }

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-mini .stat-value { font-size: 22px; }

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.stat-danger .stat-value { color: var(--danger); }

/* --- Dashboard --- */

.dashboard-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.dashboard-col {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px;
    border: 1px solid var(--border);
}

.dashboard-col h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* --- Tables --- */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.table tbody tr:hover { background: rgba(59,108,245,0.03); }

.table a { color: var(--accent); text-decoration: none; }
.table a:hover { text-decoration: underline; }

.table-compact th, .table-compact td { padding: 8px 10px; font-size: 13px; }

.actions { white-space: nowrap; text-align: right; }
.actions form { display: inline; }

/* --- Forms --- */

.form-group {
    margin-bottom: 16px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--card-bg);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,108,245,0.1);
}

.form-group textarea { resize: vertical; }

.form-group-small { max-width: 200px; }

.form-row {
    display: flex;
    gap: 16px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.settings-form .card { margin-bottom: 24px; }

/* --- Filters --- */

.filters { margin-bottom: 16px; }

.filter-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.filter-form input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    width: 260px;
}

.filter-form select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--card-bg);
}

.filter-form input:focus,
.filter-form select:focus {
    outline: none;
    border-color: var(--accent);
}

/* --- Buttons --- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, opacity 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: #d1d5db; }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); }

.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* --- Status / Type labels --- */

.status, .type-label {
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

.status-draft { color: var(--text-secondary); }
.status-sent { color: var(--warning); }
.status-paid, .status-accepted { color: var(--success); }
.status-overdue, .status-rejected { color: var(--danger); }
.status-cancelled { color: var(--text-secondary); text-decoration: line-through; }

.type-client { color: var(--accent); }
.type-prospect { color: var(--warning); }
.type-partner { color: var(--success); }
.type-supplier { color: var(--text-secondary); }

/* --- Detail page --- */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-list { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; }

.detail-list dt {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.detail-list dd {
    font-size: 14px;
    color: var(--text-primary);
}

.detail-list dd a { color: var(--accent); text-decoration: none; }
.detail-list dd a:hover { text-decoration: underline; }

/* --- Empty state --- */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.empty-state a { color: var(--accent); text-decoration: none; }

/* --- Flash messages --- */

.flash-messages { margin-bottom: 16px; }

.flash-msg {
    padding: 10px 16px;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 8px;
}

.flash-error {
    background: #fee2e2;
    color: #991b1b;
}

/* --- Inline form --- */

.inline-form { display: inline; }

/* --- Login --- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.login-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 22px;
    font-weight: 600;
}

.login-card .form-group { margin-bottom: 20px; }

.login-card .btn { margin-top: 8px; padding: 10px; font-size: 15px; }

/* --- Invoice form --- */

.line-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--card-bg);
}

.line-input:focus {
    outline: none;
    border-color: var(--accent);
}

.invoice-totals {
    margin-top: 16px;
    border-top: 2px solid var(--border);
    padding-top: 12px;
    max-width: 360px;
    margin-left: auto;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 14px;
}

.totals-grand {
    border-top: 2px solid var(--text-primary);
    margin-top: 4px;
    padding-top: 8px;
    font-weight: 700;
    font-size: 16px;
}

/* --- Invoice document (printable view) --- */

.invoice-document {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 40px;
    max-width: 800px;
}

.invoice-header-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 32px;
}

.invoice-company h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.invoice-company div { font-size: 13px; line-height: 1.6; }

.invoice-meta { font-size: 12px; color: var(--text-secondary); }

.invoice-info { text-align: right; }
.invoice-info h2 { font-size: 20px; margin-bottom: 8px; color: var(--accent); }

.invoice-info-list { display: grid; grid-template-columns: auto auto; gap: 2px 12px; }
.invoice-info-list dt { font-size: 13px; color: var(--text-secondary); text-align: right; }
.invoice-info-list dd { font-size: 13px; text-align: right; }

.invoice-client {
    margin-bottom: 24px;
    font-size: 14px;
    line-height: 1.6;
}

.invoice-lines-table { margin-bottom: 0; }

.invoice-footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
}

.invoice-notes { margin-top: 8px; font-style: italic; }

/* --- Print --- */

@media print {
    .sidebar, .page-header, .flash-messages { display: none !important; }
    .content { margin-left: 0 !important; padding: 0 !important; }
    .invoice-document { border: none; box-shadow: none; padding: 20px; max-width: none; }
    body { background: white; }
}
