:root {
    --color-ok: #e6f4ea;
    --color-breach: #fce8e6;
    --color-warning: #fff3cd;
    --color-text: #222;
    --color-border: #ddd;
    --color-muted: #666;
    --max-width: 900px;
}
body {
    font-family: system-ui, sans-serif;
    max-width: var(--max-width);
    margin: 40px auto;
    padding: 0 20px;
    color: var(--color-text);
}
h1 { font-size: 1.4em; margin-bottom: 8px; }
h2 { font-size: 1.1em; margin: 0 0 12px; }
.intro {
    font-size: 0.9em;
    color: var(--color-muted);
    line-height: 1.5;
    margin: 0 0 6px;
}
.intro:last-of-type { margin-bottom: 24px; }
section { margin-bottom: 28px; }

/* Qualifying period */
.qp-row {
    display: flex;
    gap: 16px;
    align-items: end;
}
.qp-info {
    font-size: 0.9em;
    color: var(--color-muted);
    margin-top: 8px;
}
.progress-bar {
    height: 8px;
    background: #eee;
    border-radius: 4px;
    margin-top: 8px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: #4a90d9;
    border-radius: 4px;
    transition: width 0.3s;
}

/* Form */
.absence-form {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
}
label {
    display: flex;
    flex-direction: column;
    font-size: 0.85em;
    gap: 4px;
    position: relative;
    padding-bottom: 1.2em;
}
.absence-form > button {
    margin-bottom: 1.2em;
}
input[type="date"], input[type="text"] {
    padding: 6px;
    font-size: 0.95em;
    height: 36px;
    box-sizing: border-box;
}
input[type="text"] { width: 180px; }
.checkbox-label {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    padding-bottom: 6px;
}
button {
    padding: 6px 16px;
    font-size: 0.95em;
    cursor: pointer;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}
th, td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
}
th { font-weight: 600; }
.entry-gap-row { background: #f0f0f0; color: var(--color-muted); font-style: italic; }
.btn-icon {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 4px;
}
.btn-icon:hover { color: #333; }
.btn-icon.remove:hover { color: #c00; }

.edit-row input[type="date"],
.edit-row input[type="text"] {
    padding: 3px 4px;
    font-size: 0.9em;
}
.edit-row input[type="text"] { width: 120px; }
.btn-sm {
    padding: 2px 10px;
    font-size: 0.85em;
    margin-right: 4px;
}

/* Dashboard */
.dashboard {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.stat-card {
    flex: 1;
    min-width: 160px;
    padding: 16px;
    border-radius: 8px;
    background: #f7f8fa;
    border: 1px solid var(--color-border);
}
.stat-card .stat-value {
    font-size: 2em;
    font-weight: 700;
    line-height: 1.1;
}
.stat-card .stat-label {
    font-size: 0.8em;
    color: var(--color-muted);
    margin-top: 4px;
}
.stat-card .stat-detail {
    font-size: 0.8em;
    color: var(--color-muted);
    margin-top: 2px;
}
.stat-card.ok .stat-value { color: #1a7f37; }
.stat-card.warning .stat-value { color: #b35900; }
.stat-card.breach .stat-value { color: #c00; }

/* Warnings */
.warning-box {
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 0.9em;
    margin-bottom: 8px;
}
.warning-box.warn { background: var(--color-warning); }
.warning-box.error { background: var(--color-breach); }

/* Result */
#result {
    padding: 16px;
    border-radius: 6px;
    font-size: 0.95em;
}
#result:empty { padding: 0; }
#result.ok { background: var(--color-ok); }
#result.breach { background: var(--color-breach); }

/* Timeline */
.timeline-container { margin-top: 8px; }
.timeline-years {
    display: flex;
    justify-content: space-between;
    font-size: 0.75em;
    color: var(--color-muted);
    margin-bottom: 2px;
}
.timeline-bar {
    position: relative;
    height: 32px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}
.timeline-absence {
    position: absolute;
    top: 4px;
    height: 24px;
    background: #4a90d9;
    border-radius: 2px;
    opacity: 0.85;
    cursor: default;
}
.timeline-tooltip {
    position: fixed;
    background: #333;
    color: #fff;
    font-size: 0.8em;
    padding: 6px 10px;
    border-radius: 4px;
    white-space: pre-line;
    pointer-events: none;
    z-index: 100;
    display: none;
}
.timeline-absence.entry-gap {
    background: #999;
    opacity: 0.6;
}
.timeline-today {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e00;
    z-index: 2;
}
.timeline-year-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: #ccc;
}

/* Actions section */
#actions-section { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Toggle switch */
.toggle-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: var(--color-muted);
    cursor: pointer;
    user-select: none;
    margin-left: 8px;
    padding-bottom: 0;
}
.toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: #ccc;
    border-radius: 10px;
    transition: background 0.2s;
}
.toggle-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-input { display: none; }
.toggle-input:checked + .toggle-track {
    background: #4a90d9;
}
.toggle-input:checked + .toggle-track::after {
    transform: translateX(16px);
}

/* Field validation errors */
.field-error {
    position: absolute;
    bottom: 0;
    left: 0;
    color: #c00;
    font-size: 0.8em;
    white-space: nowrap;
}
input.invalid {
    border: 1.5px solid #c00;
}

/* Print */
@media print {
    #absence-form-section,
    #actions-section,
    .toggle-label,
    .btn-icon,
    .btn-sm,
    .edit-row,
    #uk-entry-date,
    button {
        display: none !important;
    }
    body {
        max-width: 100%;
        margin: 0;
        padding: 20px;
        font-size: 11pt;
        color: #000;
    }
    section { margin-bottom: 16px; }
    .stat-card {
        border: 1px solid #999;
        background: none !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    .stat-card .stat-value { color: #000 !important; }
    .stat-card.breach .stat-value { color: #000 !important; font-weight: 900; }
    table { page-break-inside: auto; }
    tr { page-break-inside: avoid; }
    .timeline-bar {
        background: #eee !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    .timeline-absence {
        background: #666 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    #result {
        border: 1px solid #333;
        background: none !important;
    }
    #result.breach { border: 2px solid #000; }
    .warning-box { border: 1px solid #666; background: none !important; }
}
