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

body {
    font-family: 'Segoe UI', sans-serif;
    background: #f4f6f9;
    color: #333;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s, transform 0.1s;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary   { background: #4f46e5; color: #fff; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-success   { background: #16a34a; color: #fff; }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-warning   { background: #d97706; color: #fff; }
.btn-full      { width: 100%; text-align: center; padding: 11px; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }

/* ── Alerts ── */
.alert {
    padding: 10px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert.error   { background: #fee2e2; color: #b91c1c; border-left: 4px solid #dc2626; }
.alert.success { background: #dcfce7; color: #15803d; border-left: 4px solid #16a34a; }

/* ── Forms ── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.form-group label { font-size: 14px; font-weight: 500; color: #374151; }
.form-group input,
.form-group textarea,
.form-group select {
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus { border-color: #4f46e5; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.required { color: #dc2626; }
.form-card {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    margin-bottom: 24px;
}
.form-card h3 { margin-bottom: 16px; font-size: 16px; color: #111827; }

/* ── Auth Page ── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f4f6f9;
    padding: 16px;
}
.auth-card {
    background: #fff;
    padding: 40px 36px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
}
.auth-card h1 { font-size: 24px; color: #111827; margin-bottom: 4px; }
.auth-card .subtitle { font-size: 14px; color: #6b7280; margin-bottom: 24px; }

/* ── Quiz Page ── */
.quiz-page { background: #f4f6f9; padding: 24px 16px; }
.quiz-container { max-width: 720px; margin: 0 auto; }

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    padding: 14px 20px;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    margin-bottom: 16px;
}
.quiz-title { font-size: 18px; font-weight: 600; color: #111827; }
.quiz-overall-timer { font-size: 14px; color: #6b7280; }
.quiz-overall-timer span { font-weight: 700; color: #4f46e5; font-size: 16px; }

/* Progress Bar */
.progress-bar-wrap {
    background: #e5e7eb;
    border-radius: 99px;
    height: 6px;
    margin-bottom: 6px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: #4f46e5;
    border-radius: 99px;
    transition: width 0.4s ease;
    width: 0%;
}
.progress-label { font-size: 13px; color: #6b7280; margin-bottom: 20px; }

/* Question Card */
.question-card { display: none; }
.question-card.active { display: block; }

.question-card {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

/* Per-question circular timer */
.q-timer-wrap {
    position: relative;
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    margin-left: 16px;
}

.question-card.active {
    display: flex;
    flex-direction: column;
}

.question-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}
.q-timer-svg { transform: rotate(-90deg); width: 60px; height: 60px; }
.q-timer-bg {
    fill: none;
    stroke: #e5e7eb;
    stroke-width: 3;
}
.q-timer-fill {
    fill: none;
    stroke: #4f46e5;
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dasharray 0.9s linear;
}
.q-timer-text {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: 600;
    color: #4f46e5;
}

.question-text {
    font-size: 16px;
    font-weight: 500;
    color: #111827;
    margin-bottom: 0;
    line-height: 1.6;
    flex: 1;
}

/* Options */
.options-list { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; margin-bottom: 24px; }
.option-label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    font-size: 14px;
}
.option-label:hover { border-color: #4f46e5; background: #f5f3ff; }
.option-label input[type="radio"] { accent-color: #4f46e5; width: 16px; height: 16px; }
.option-label input[type="radio"]:checked + span { color: #4f46e5; font-weight: 500; }

/* Question Nav */
.q-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

/* ── Result Page ── */
.result-page { background: #f4f6f9; padding: 24px 16px; }
.result-container { max-width: 720px; margin: 0 auto; }

.score-card {
    background: #fff;
    border-radius: 10px;
    padding: 32px 24px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    margin-bottom: 24px;
}
.score-card h2 { font-size: 20px; color: #111827; margin-bottom: 20px; }
.score-circle {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: #f5f3ff;
    border: 5px solid #4f46e5;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}
.score-pct { font-size: 28px; font-weight: 700; color: #4f46e5; }
.score-text { font-size: 15px; color: #6b7280; margin-bottom: 20px; }

/* Review */
.review-section h3 { font-size: 17px; margin-bottom: 16px; color: #111827; }
.review-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    border-left: 4px solid #e5e7eb;
}
.review-card.correct { border-left-color: #16a34a; }
.review-card.wrong   { border-left-color: #dc2626; }
.review-card.skipped { border-left-color: #9ca3af; }

.review-q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.q-num { font-weight: 700; color: #4f46e5; font-size: 14px; }
.q-status { font-size: 13px; font-weight: 500; }
.review-q-text { font-size: 15px; font-weight: 500; margin-bottom: 12px; color: #111827; }

.review-options { display: flex; flex-direction: column; gap: 8px; }
.review-options li {
    padding: 9px 14px;
    border-radius: 6px;
    font-size: 14px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 8px;
}
.review-options li.opt-correct { background: #dcfce7; border-color: #16a34a; color: #15803d; }
.review-options li.opt-wrong   { background: #fee2e2; border-color: #dc2626; color: #b91c1c; }

.tag {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 99px;
    background: rgba(0,0,0,0.08);
    font-weight: 600;
    margin-left: auto;
}
.explanation {
    margin-top: 12px;
    padding: 10px 14px;
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    font-size: 13px;
    color: #92400e;
    line-height: 1.5;
}

/* ── Admin Page ── */
.admin-page { background: #f4f6f9; padding: 24px 16px; }
.admin-container { max-width: 960px; margin: 0 auto; }

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.admin-header h1 { font-size: 22px; color: #111827; }
.admin-header-actions { display: flex; gap: 10px; }

.admin-section { margin-bottom: 32px; }
.admin-section h2 { font-size: 17px; margin-bottom: 14px; color: #111827; }
.admin-section h3 { font-size: 16px; margin-bottom: 14px; color: #111827; }

/* Table */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.admin-table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    font-size: 14px;
}
.admin-table th {
    background: #f9fafb;
    padding: 11px 14px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
}
.admin-table td {
    padding: 11px 14px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* Inline form */
.inline-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.inline-form input {
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}
.inline-form input:focus { border-color: #4f46e5; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-grey  { background: #f3f4f6; color: #6b7280; }

.attempt-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 13px;
}

/* Option input rows (manage_quiz) */
.option-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.option-input-row input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}
.option-input-row input[type="text"]:focus { border-color: #4f46e5; }
.option-input-row input[type="radio"] { accent-color: #4f46e5; width: 16px; height: 16px; }

/* Question list cards */
.q-list-card {
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.q-list-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
    font-size: 14px;
    color: #111827;
}
.q-list-options { display: flex; flex-direction: column; gap: 6px; }
.q-list-options li {
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 5px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 8px;
}
.q-list-options li.opt-correct { background: #dcfce7; border-color: #16a34a; color: #15803d; }

/* Misc */
.muted { color: #9ca3af; font-size: 13px; }

/* ── Responsive ── */
@media (max-width: 600px) {
    .form-row { flex-direction: column; }
    .quiz-header { flex-direction: column; gap: 8px; align-items: flex-start; }
    .admin-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .inline-form { flex-direction: column; }
    .inline-form input { width: 100%; }
    .inline-form .btn { width: 100%; text-align: center; }
    .admin-table { font-size: 13px; }
    .admin-table th, .admin-table td { padding: 9px 10px; }
    .auth-card { padding: 28px 20px; }
    .question-card { padding: 16px; }
    .q-timer-wrap { width: 48px; height: 48px; }
    .q-timer-svg { width: 48px; height: 48px; }
    .q-timer-text { font-size: 10px; }
    .score-circle { width: 90px; height: 90px; }
    .score-pct { font-size: 22px; }
    .action-btns { flex-direction: column; }
    .attempt-row { flex-wrap: wrap; }
}

/* ── Quiz List Page ── */
.quiz-list-section { margin-top: 8px; }

.quiz-list-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}
.quiz-list-info { flex: 1; }
.quiz-list-info h3 { font-size: 16px; color: #111827; margin-bottom: 4px; }
.quiz-list-info .muted { margin-bottom: 8px; }
.quiz-meta {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 13px;
    color: #6b7280;
}
.quiz-list-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 110px;
    text-align: center;
}

@media (max-width: 600px) {
    .quiz-list-card { flex-direction: column; align-items: flex-start; }
    .quiz-list-action { align-items: flex-start; min-width: unset; width: 100%; }
    .quiz-list-action .btn { width: 100%; text-align: center; }
}
