/* Reset & base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --green: #16a34a;
    --red: #dc2626;
    --orange: #ea580c;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
}

/* Header */
header {
    background: var(--primary);
    padding: 1rem;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

header .logo {
    color: white;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Main */
main {
    max-width: 600px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
}

/* Card grid (home) */
.card-grid {
    display: grid;
    gap: 0.75rem;
}

.card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text);
    transition: box-shadow 0.15s;
}

.card:active,
.card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card h2 {
    font-size: 1.1rem;
}

/* Chapter list */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.chapter-item.select-all {
    background: var(--bg);
    border-style: dashed;
    font-weight: 600;
}

.chapter-item input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--primary);
    flex-shrink: 0;
}

/* Question count */
.question-count {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.question-count label {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
}

.question-count .form-input {
    width: 5rem;
    text-align: center;
}

/* Button */
.btn {
    display: block;
    width: 100%;
    padding: 0.875rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    margin-top: 1rem;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:active,
.btn-primary:hover {
    background: var(--primary-hover);
}

/* PDF link button */
.btn-pdf {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    background: #eef2ff;
    border: 1px solid var(--primary);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
    text-decoration: none;
    vertical-align: middle;
    white-space: nowrap;
}

.btn-pdf:hover {
    background: var(--primary);
    color: white;
}

/* Quiz header row (progress + PDF link) */
.quiz-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

/* Progress bar */
.quiz-header {
    margin-bottom: 1.25rem;
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-light);
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* Question card */
.question-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.question-card h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.question-image {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 1rem;
}

/* Propositions */
.propositions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.proposition {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.proposition input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--primary);
    flex-shrink: 0;
}

/* Results */
.results-summary {
    text-align: center;
    margin-bottom: 2rem;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1rem auto;
    border: 6px solid;
}

.score-circle.good {
    border-color: var(--green);
    color: var(--green);
}

.score-circle.ok {
    border-color: var(--orange);
    color: var(--orange);
}

.score-circle.bad {
    border-color: var(--red);
    color: var(--red);
}

.score-pct {
    font-size: 2rem;
    font-weight: 700;
}

.score-detail {
    color: var(--text-light);
}

/* Results breakdown */
.results-breakdown {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.result-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.result-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.question-score {
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.prop-results {
    list-style: none;
}

.prop-results li {
    display: flex;
    gap: 0.5rem;
    padding: 0.375rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.prop-results li:last-child {
    border-bottom: none;
}

.prop-results .icon {
    flex-shrink: 0;
    font-weight: 700;
    width: 1.25rem;
    text-align: center;
}

.prop-results .correct .icon {
    color: var(--green);
}

.prop-results .wrong .icon {
    color: var(--red);
}

li.correct .icon {
    color: var(--green);
}

li.wrong .icon {
    color: var(--red);
}

.prop-answer {
    font-size: 0.8rem;
    color: var(--text-light);
    width: 100%;
    padding-left: 1.75rem;
}

.prop-correction {
    font-size: 0.85rem;
    color: var(--text);
    background: var(--bg);
    border-left: 3px solid var(--primary);
    margin: 0.4rem 0 0.2rem 1.75rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0 4px 4px 0;
}

/* Empty state */
.empty {
    text-align: center;
    color: var(--text-light);
    padding: 2rem 1rem;
}

/* Admin link on home page */
.admin-link {
    display: block;
    text-align: center;
    margin-top: 2rem;
    font-size: 0.85rem;
    color: var(--text-light);
    text-decoration: none;
}

.admin-link:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* Admin form */
.admin-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.admin-form label {
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.admin-form .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    cursor: pointer;
}

.admin-form .checkbox-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text);
}

.form-input:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

select.form-input {
    appearance: auto;
}

.form-error {
    background: #fef2f2;
    color: var(--red);
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.9rem;
}

/* Success banner */
.success-banner {
    background: #f0fdf4;
    color: var(--green);
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 1rem;
}

/* Proposition fields */
.proposition-field {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.prop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.prop-remove {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.prop-remove:hover {
    color: var(--red);
}

/* Secondary button */
.btn-secondary {
    background: transparent;
    color: var(--text-light);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 0.75rem;
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Fieldset reset */
.admin-form fieldset {
    border: none;
    padding: 0;
}

.admin-form legend {
    font-size: 1rem;
    font-weight: 700;
    margin-top: 0.75rem;
}

/* Analytics dashboard */
.analytics-subtitle {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.analytics-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
}

.analytics-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.analytics-section h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

/* Bar charts */
.analytics-bar-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bar-label {
    font-size: 0.8rem;
    width: 5rem;
    flex-shrink: 0;
    text-align: right;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    flex: 1;
    height: 1.25rem;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    min-width: 2px;
    transition: width 0.3s;
}

.bar-fill.bar-good { background: var(--green); }
.bar-fill.bar-ok { background: var(--orange); }
.bar-fill.bar-bad { background: var(--red); }
.bar-fill.bar-primary { background: var(--primary); }

.bar-count {
    font-size: 0.8rem;
    font-weight: 600;
    width: 2.5rem;
    text-align: right;
}

/* Device split */
.device-split {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.device-bar {
    height: 1.5rem;
    background: var(--primary);
    border-radius: 6px;
    overflow: hidden;
}

.device-mobile {
    height: 100%;
    background: var(--green);
}

.device-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-light);
}

/* Hourly chart */
.hourly-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 100px;
}

.hourly-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}

.hourly-bar {
    width: 100%;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
}

.hourly-label {
    font-size: 0.55rem;
    color: var(--text-light);
    margin-top: 4px;
    height: 0.75rem;
}

/* Analytics table */
.analytics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.analytics-table th {
    text-align: left;
    font-weight: 600;
    padding: 0.4rem 0.5rem;
    border-bottom: 2px solid var(--border);
}

.analytics-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.analytics-table td:last-child,
.analytics-table th:last-child {
    text-align: right;
}
