@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;900&display=swap');

:root {
    --bg: #F5F7F5;
    --card: #FFFFFF;
    --ink: #1E2B28;
    --ink-soft: #5C6E69;
    --teal: #145C54;
    --teal-dark: #0D423C;
    --teal-tint: #E4EFEC;
    --amber: #C08533;
    --amber-tint: #F6ECDC;
    --line: #DEE6E2;
    --danger: #B14B3E;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Tajawal', 'Segoe UI', sans-serif;
    direction: rtl;
    text-align: right;
    font-size: 16px;
    line-height: 1.6;
}

.wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 20px 80px;
}

.wrap.wide {
    max-width: 980px;
}

header.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    gap: 12px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--teal);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 900;
    font-size: 18px;
    flex-shrink: 0;
}

.brand h1 {
    font-size: 19px;
    margin: 0;
    font-weight: 700;
    color: var(--teal-dark);
}

.brand span.sub {
    display: block;
    font-size: 12.5px;
    color: var(--ink-soft);
    font-weight: 400;
    margin-top: 2px;
}

nav.links a {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14.5px;
    margin-inline-start: 16px;
    border-bottom: 1px solid transparent;
}
nav.links a:hover { color: var(--teal); border-color: var(--teal); }

.intro-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px 22px;
    margin-bottom: 22px;
}
.intro-card p { margin: 0 0 8px; color: var(--ink-soft); font-size: 14.5px; }
.intro-card p:last-child { margin-bottom: 0; }

.q-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px 20px;
    margin-bottom: 14px;
}

.q-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 14px;
}

.q-num {
    color: var(--teal);
    font-weight: 900;
    font-size: 14px;
    flex-shrink: 0;
    min-width: 26px;
}

.q-text {
    font-weight: 500;
    font-size: 16px;
    color: var(--ink);
}

.scale {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.scale label {
    flex: 1 1 0;
    min-width: 0;
    cursor: pointer;
    display: flex;
}

.scale input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.scale .pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    padding: 9px 4px 8px;
    text-align: center;
    width: 100%;
    transition: border-color .12s, background .12s, transform .06s;
    background: #FBFCFB;
}

.pill .num {
    font-weight: 900;
    font-size: 15px;
    color: var(--teal-dark);
}
.pill .lbl {
    font-size: 10.5px;
    color: var(--ink-soft);
    line-height: 1.25;
    overflow-wrap: break-word;
    word-break: break-word;
}

.scale input[type="radio"]:checked + .pill {
    background: var(--teal);
    border-color: var(--teal);
}
.scale input[type="radio"]:checked + .pill .num,
.scale input[type="radio"]:checked + .pill .lbl {
    color: #fff;
}
.scale label:active .pill { transform: scale(.97); }
.scale input[type="radio"]:focus-visible + .pill {
    outline: 3px solid var(--amber);
    outline-offset: 1px;
}

.doctor-pick { margin-bottom: 22px; }
.doctor-pick .field-label { font-size: 14px; color: var(--ink-soft); margin-bottom: 8px; }
.doctor-options { display: flex; gap: 10px; flex-wrap: wrap; }
.doctor-options label { flex: 1 1 180px; cursor: pointer; display: flex; }
.doctor-options input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.doctor-pill {
    width: 100%;
    text-align: center;
    padding: 14px 10px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    font-weight: 700;
    color: var(--teal-dark);
    transition: border-color .12s, background .12s;
}
.doctor-options input[type="radio"]:checked + .doctor-pill {
    background: var(--teal);
    border-color: var(--teal);
    color: #fff;
}
.doctor-options input[type="radio"]:focus-visible + .doctor-pill {
    outline: 3px solid var(--amber);
    outline-offset: 1px;
}

.doctor-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.doctor-tabs a {
    padding: 8px 16px;
    border: 1.5px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}
.doctor-tabs a:hover { border-color: var(--teal); color: var(--teal); }
.doctor-tabs a.active { background: var(--teal); border-color: var(--teal); color: #fff; }

.field-row {
    display: flex;
    gap: 14px;
    margin-bottom: 0;
}
.field-row .field {
    flex: 1 1 0;
    min-width: 0;
}

.field {
    margin-bottom: 20px;
}
.field label.field-label {
    display: block;
    font-size: 14px;
    color: var(--ink-soft);
    margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="password"] {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    background: #fff;
    color: var(--ink);
}
.field input[type="text"],
.field input[type="password"]:focus {
    outline: none;
    border-color: var(--teal);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--teal);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 13px 26px;
    font-family: inherit;
    font-size: 15.5px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}
.btn:hover { background: var(--teal-dark); }
.btn.secondary {
    background: transparent;
    color: var(--teal);
    border: 1.5px solid var(--teal);
}
.btn.secondary:hover { background: var(--teal-tint); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8f3b30; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.submit-row {
    display: flex;
    justify-content: center;
    margin-top: 26px;
}

.progress-note {
    text-align: center;
    font-size: 13px;
    color: var(--ink-soft);
    margin-top: 10px;
}

/* Result page */
.score-card {
    background: linear-gradient(180deg, var(--teal) 0%, var(--teal-dark) 100%);
    color: #fff;
    border-radius: var(--radius);
    padding: 34px 24px;
    text-align: center;
    margin-bottom: 22px;
}
.score-card .score-number {
    font-size: 56px;
    font-weight: 900;
    line-height: 1;
}
.score-card .score-max {
    font-size: 16px;
    opacity: .85;
    margin-top: 6px;
}
.score-card .score-caption {
    margin-top: 14px;
    font-size: 14.5px;
    opacity: .92;
    max-width: 440px;
    margin-inline: auto;
}

.breakdown {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 22px;
}
.breakdown-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    font-size: 14.5px;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .txt { color: var(--ink); }
.breakdown-row .val {
    flex-shrink: 0;
    min-width: 30px;
    text-align: center;
    font-weight: 900;
    color: var(--teal-dark);
    background: var(--teal-tint);
    border-radius: 8px;
    padding: 2px 9px;
}

/* Admin */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
}
table.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14.5px;
}
table.admin-table th, table.admin-table td {
    padding: 12px 16px;
    text-align: right;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.admin-table th {
    background: var(--teal-tint);
    color: var(--teal-dark);
    font-weight: 700;
    font-size: 13px;
}
table.admin-table tr:last-child td { border-bottom: none; }
table.admin-table .muted { color: var(--ink-soft); font-size: 13px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions form { display: inline; }

/* Response charts (admin dashboard) */
.charts-section {
    margin-bottom: 26px;
}
.charts-section h2 {
    font-size: 17px;
    color: var(--teal-dark);
    margin: 0 0 14px;
}
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}
.chart-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px 16px;
}
.chart-card.wide {
    grid-column: 1 / -1;
}
.chart-card h3 {
    font-size: 14.5px;
    margin: 0 0 3px;
    color: var(--ink);
}
.chart-card .chart-sub {
    font-size: 12px;
    color: var(--ink-soft);
    margin: 0 0 14px;
}
.chart-card canvas {
    max-width: 100%;
}
.chart-canvas-wrap {
    position: relative;
    height: 230px;
    width: 100%;
}
.chart-legend-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-top: 14px;
    font-size: 12.5px;
    color: var(--ink-soft);
}
.chart-legend-list .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-inline-end: 6px;
    vertical-align: -1px;
}
.chart-download {
    margin-top: 14px;
    text-align: center;
}
.chart-download button {
    background: transparent;
    border: 1.5px solid var(--line);
    color: var(--ink-soft);
    border-radius: 8px;
    padding: 7px 16px;
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .12s, color .12s;
}
.chart-download button:hover {
    border-color: var(--teal);
    color: var(--teal);
}
.chart-empty {
    text-align: center;
    color: var(--ink-soft);
    padding: 36px 10px;
    font-size: 13.5px;
    background: var(--card);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.badge.active { background: var(--teal-tint); color: var(--teal-dark); }
.badge.inactive { background: #F1F1EF; color: var(--ink-soft); }

.stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 22px;
}
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
}
.stat .n { font-size: 28px; font-weight: 900; color: var(--teal-dark); }
.stat .l { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }

.login-card {
    max-width: 380px;
    margin: 60px auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 30px 26px;
}
.login-card h1 { font-size: 20px; margin-top: 0; color: var(--teal-dark); }

.alert {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert.error { background: #FBEAE7; color: var(--danger); }
.alert.success { background: var(--teal-tint); color: var(--teal-dark); }

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--ink-soft);
}

footer.site-footer {
    text-align: center;
    color: var(--ink-soft);
    font-size: 12.5px;
    margin-top: 40px;
}
footer.site-footer strong {
    color: var(--teal-dark);
    font-weight: 700;
}

@media (max-width: 480px) {
    .field-row { flex-direction: column; gap: 0; }
    .chart-card { padding: 14px 12px 12px; }
    .chart-canvas-wrap { height: 190px; }
    .wrap { padding-left: 10px; padding-right: 10px; }
    .q-card { padding: 14px 10px 12px; }
    .score-card .score-number { font-size: 44px; }
    .scale { gap: 3px; }
    .pill { padding: 6px 1px 6px; border-radius: 8px; gap: 2px; }
    .pill .num { font-size: 13px; }
    .pill .lbl { font-size: 8.3px; line-height: 1.15; }
    .stat-row { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
    .wrap { padding-left: 6px; padding-right: 6px; }
    .q-card { padding: 12px 6px 10px; }
    .scale { gap: 2px; }
    .pill { padding: 5px 1px 5px; }
    .pill .num { font-size: 12px; }
    .pill .lbl { font-size: 7.8px; }
}
