/* ========================================
   CSS Custom Properties (Design Tokens)
   ======================================== */
:root {
    --color-primary: #2c3e50;
    --color-primary-light: #34495e;
    --color-accent: #3498db;
    --color-accent-hover: #2980b9;
    --color-success: #27ae60;
    --color-success-light: #d4edda;
    --color-warning: #f39c12;
    --color-warning-light: #fff3cd;
    --color-danger: #e74c3c;
    --color-danger-light: #f8d7da;
    --color-info: #17a2b8;
    --color-info-light: #cce5ff;
    --color-secondary: #6c757d;
    --color-secondary-light: #e2e3e5;
    --color-bg: #f5f6fa;
    --color-card: #ffffff;
    --color-border: #dee2e6;
    --color-text: #333333;
    --color-text-muted: #6c757d;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --container-max: 1320px;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --transition: all 0.2s ease;
}

/* ========================================
   Reset and Base
   ======================================== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ========================================
   Layout
   ======================================== */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 24px 20px;
}

/* ========================================
   Navigation
   ======================================== */
nav {
    background: var(--color-primary);
    color: white;
    padding: 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}
.nav-container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    min-height: 56px;
    gap: 24px;
}
.nav-brand a {
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}
.nav-menu {
    list-style: none;
    display: flex;
    gap: 4px;
    flex: 1;
}
.nav-menu a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 16px 12px;
    display: block;
    font-size: 0.9rem;
    border-bottom: 3px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
}
.nav-menu a:hover,
.nav-menu a.active {
    color: white;
    border-bottom-color: var(--color-accent);
    text-decoration: none;
}
.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.8);
    white-space: nowrap;
}
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}
.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    margin: 5px 0;
    transition: var(--transition);
}

/* ========================================
   Grid System
   ======================================== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--color-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}
.card-header h2,
.card-header h3 {
    color: var(--color-primary);
    font-size: 1.15rem;
}

/* Stat Cards */
.stat-card {
    background: var(--color-card);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-accent);
}
.stat-card .stat-label {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.stat-card .stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--color-primary);
}
.stat-card.success { border-left-color: var(--color-success); }
.stat-card.success .stat-value { color: var(--color-success); }
.stat-card.warning { border-left-color: var(--color-warning); }
.stat-card.warning .stat-value { color: var(--color-warning); }
.stat-card.danger { border-left-color: var(--color-danger); }
.stat-card.danger .stat-value { color: var(--color-danger); }
.stat-card.info { border-left-color: var(--color-info); }
.stat-card.info .stat-value { color: var(--color-info); }

/* Financial Summary */
.financial-summary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
    color: white;
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}
.financial-summary .row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}
.financial-summary .row:last-child { border-bottom: none; }
.financial-summary .row.highlight {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 12px 0;
}
.financial-summary .row.positive .value { color: #2ecc71; }
.financial-summary .row.negative .value { color: #e74c3c; }

/* ========================================
   Tables
   ======================================== */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead th {
    background: var(--color-primary);
    color: white;
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
tbody tr:hover { background: #f8f9fc; }
tbody tr:last-child td { border-bottom: none; }
tfoot td {
    padding: 12px 14px;
    font-weight: 700;
    background: #f1f3f5;
    border-top: 2px solid var(--color-border);
}
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }

/* ========================================
   Forms
   ======================================== */
.form-group {
    margin-bottom: 18px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-primary);
}
.form-group label .required {
    color: var(--color-danger);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 18px;
}
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="url"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.95rem;
    transition: var(--transition);
    background: white;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* Radio/Checkbox groups */
.radio-group, .checkbox-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.radio-group label, .checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    cursor: pointer;
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.radio-group label:has(input:checked),
.checkbox-group label:has(input:checked) {
    border-color: var(--color-accent);
    background: rgba(52, 152, 219, 0.05);
}
.radio-group input, .checkbox-group input {
    width: auto;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
}
.btn:hover { text-decoration: none; opacity: 0.9; transform: translateY(-1px); }
.btn-primary { background: var(--color-accent); color: white; }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-success { background: var(--color-success); color: white; }
.btn-warning { background: var(--color-warning); color: white; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-secondary { background: var(--color-secondary); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--color-accent); color: var(--color-accent); }
.btn-outline:hover { background: var(--color-accent); color: white; }
.btn-outline-light { background: transparent; border: 1px solid rgba(255,255,255,0.5); color: white; padding: 5px 12px; font-size: 0.8rem; }
.btn-outline-light:hover { background: rgba(255,255,255,0.1); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { display: block; width: 100%; text-align: center; }

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ========================================
   Badges
   ======================================== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-success { background: var(--color-success-light); color: #155724; }
.badge-warning { background: var(--color-warning-light); color: #856404; }
.badge-danger { background: var(--color-danger-light); color: #721c24; }
.badge-info { background: var(--color-info-light); color: #004085; }
.badge-primary { background: #cce5ff; color: #004085; }
.badge-secondary { background: var(--color-secondary-light); color: #383d41; }

/* ========================================
   Alerts / Flash Messages
   ======================================== */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
    border-left: 4px solid;
}
.alert-success { background: var(--color-success-light); border-color: var(--color-success); color: #155724; }
.alert-warning { background: var(--color-warning-light); border-color: var(--color-warning); color: #856404; }
.alert-danger { background: var(--color-danger-light); border-color: var(--color-danger); color: #721c24; }
.alert-info { background: var(--color-info-light); border-color: var(--color-info); color: #004085; }

/* ========================================
   Filter Bar
   ======================================== */
.filter-bar {
    background: var(--color-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}
.filter-bar .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}
.filter-bar label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    display: block;
}
.filter-bar input,
.filter-bar select {
    padding: 8px 10px;
    font-size: 0.85rem;
}

/* ========================================
   Page Header
   ======================================== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    color: var(--color-primary);
    font-size: 1.5rem;
}

/* ========================================
   Detail / Info Grid
   ======================================== */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.detail-item .detail-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    margin-bottom: 2px;
}
.detail-item .detail-value {
    font-weight: 600;
    font-size: 1rem;
}

/* ========================================
   Amount Colors
   ======================================== */
.amount-positive { color: var(--color-success); font-weight: 600; }
.amount-negative { color: var(--color-danger); font-weight: 600; }
.amount-neutral { color: var(--color-text); font-weight: 600; }

/* ========================================
   Section Spacing
   ======================================== */
.section { margin-bottom: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

/* ========================================
   Flex Utilities
   ======================================== */
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }

/* ========================================
   Empty State
   ======================================== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--color-text-muted);
}
.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

/* ========================================
   Live Calculation Display
   ======================================== */
.calc-display {
    background: #f8f9fa;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
    margin-top: 16px;
}
.calc-display .calc-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.95rem;
}
.calc-display .calc-row.total {
    border-top: 2px solid var(--color-primary);
    margin-top: 8px;
    padding-top: 12px;
    font-weight: 700;
    font-size: 1.05rem;
}

/* ========================================
   Thumbnail
   ======================================== */
.thumbnail {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: #f0f0f0;
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    nav, .btn, .btn-group, .filter-bar, .nav-toggle, .no-print { display: none !important; }
    body { background: white; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    .container { max-width: 100%; padding: 0; }
    .financial-summary { color: black; background: #f5f5f5; }
}
