:root {
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #1e40af;
    --primary-light: #93c5fd;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --radius: 6px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* Nav */
.main-nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); }
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { background: var(--primary); color: #fff; }
.nav-controls {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.nav-controls select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: #fff;
}
.year-arrow {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1;
}
.year-arrow:hover { background: var(--bg); color: var(--text); }

/* Content */
.content { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.3rem; font-weight: 600; }

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.card h3 { font-size: 0.95rem; margin-bottom: 0.75rem; color: var(--text-muted); }

/* Buttons */
.btn {
    padding: 0.4rem 0.85rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.15rem 0.45rem; font-size: 0.75rem; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.form-group input, .form-group select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.form-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: end; }

/* Tables */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.data-table th, .data-table td {
    padding: 0.35rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.03em;
}
.notes-cell { color: var(--text-muted); max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country-badge {
    display: inline-block;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
}
.table-controls { margin-bottom: 0.5rem; font-size: 0.8rem; color: var(--text-muted); }

/* Calendar grid */
.calendar-year-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}
.calendar-month {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem;
}
.month-header {
    font-weight: 600;
    font-size: 0.85rem;
    text-align: center;
    padding: 0.25rem 0 0.4rem;
    color: var(--text);
}
.day-names {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
}
.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
}
.day-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    border-radius: 2px;
    cursor: pointer;
    transition: opacity 0.1s;
    font-weight: 500;
}
.day-cell:hover { opacity: 0.8; }
.day-cell.empty { cursor: default; }
.day-cell.out-of-range { background: #f1f5f9; color: #cbd5e1; cursor: default; }
.day-cell.today { outline: 2px solid var(--text); outline-offset: -1px; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }
.legend-item { display: flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; }
.legend-swatch { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.calendar-stats {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Modal */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--card-bg);
    border-radius: 8px;
    width: 380px;
    max-width: 90vw;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.95rem; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* Stats cards */
.stats-cards {
    display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    min-width: 120px;
}
.stat-card.home { border-left: 3px solid var(--primary); }
.stat-card.benchmark { border-left: 3px solid var(--warning); }
.stat-card.warning { border-left: 3px solid var(--danger); background: #fef2f2; }
.stat-value { font-size: 1.3rem; font-weight: 700; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* Rules cards */
.rules-cards {
    display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.5rem;
}
.rule-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    min-width: 240px;
    flex: 1;
    max-width: 400px;
}
.rule-card.rule-exceeded { border-left: 3px solid var(--danger); background: #fef2f2; }
.rule-card.rule-warn { border-left: 3px solid var(--warning); }
.rule-card.rule-ok { border-left: 3px solid var(--success); }
.rule-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.4rem;
}
.rule-country { font-weight: 600; font-size: 0.9rem; }
.rule-fraction { font-size: 0.8rem; color: var(--text-muted); }
.rule-bar-bg {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.3rem;
}
.rule-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.rule-footer {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.7rem;
}
.rule-exceeded-text { color: var(--danger); font-weight: 600; }
.rule-remaining-text { color: var(--text-muted); }
.rule-pct { color: var(--text-muted); font-weight: 500; }

/* Pivot table */
.pivot-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.pivot-table th, .pivot-table td {
    padding: 0.3rem 0.5rem;
    text-align: center;
    border: 1px solid var(--border);
    min-width: 45px;
}
.pivot-table th { background: #f1f5f9; font-size: 0.7rem; font-weight: 600; }
.pivot-table td.month-label { text-align: left; font-weight: 500; white-space: nowrap; }
.pivot-table td.total-cell { font-weight: 600; background: #f8fafc; }
.pivot-table td.abroad-cell { background: #fef9c3; }
.pivot-table tr.grand-total { background: #f1f5f9; }
.pivot-table tr.grand-total td { border-top: 2px solid var(--text); }

/* Charts */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.chart-card { min-height: 300px; }
.chart-card canvas { max-height: 350px; }

/* Import */
code { background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.8rem; }

/* View controls (Days page) */
.view-controls {
    display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center;
}
.view-filters { display: flex; gap: 0.25rem; }
.view-btn { border: 1px solid var(--border); background: var(--bg); color: var(--text-muted); }
.view-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.view-nav {
    display: flex; gap: 0.5rem; align-items: center;
    font-size: 0.85rem; font-weight: 500;
}
.view-shortcuts { display: flex; gap: 0.25rem; }
.selection-bar {
    display: flex; gap: 0.75rem; align-items: center;
    margin-top: 0.75rem; padding: 0.5rem 0.75rem;
    background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius);
    font-size: 0.8rem; font-weight: 500;
}

/* Hidden */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
    .main-nav { flex-wrap: wrap; gap: 0.5rem; }
    .nav-controls { margin-left: 0; }
    .calendar-year-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .charts-row { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .stats-cards { gap: 0.5rem; }
    .stat-card { min-width: 80px; }
}
