/* Mark X Initial Assessment — shared styles for the admin panel and the student exam. */

:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --text: #1b2236;
    --muted: #647089;
    --border: #e2e6f0;
    --brand: #3847c9;
    --brand-dark: #2b379f;
    --brand-soft: #eceefb;
    --good: #0f7a55;
    --good-soft: #e3f5ee;
    --ok: #1d5fd1;
    --ok-soft: #e6effd;
    --warn: #a55a06;
    --warn-soft: #fdf1df;
    --bad: #be3327;
    --bad-soft: #fce9e7;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 28, 55, .06), 0 4px 14px rgba(20, 28, 55, .05);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Malayalam", "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
small, .small { font-size: .84rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem .95rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
    cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; border-color: #cfd5e4; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .opt:focus-visible, .pal-btn:focus-visible {
    outline: 3px solid rgba(56, 71, 201, .35); outline-offset: 1px;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--bad); border-color: #efc4bf; }
.btn-danger:hover { background: var(--bad-soft); border-color: #e5a9a2; }
.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-good:hover { background: #0b6546; border-color: #0b6546; }
.btn-sm { padding: .32rem .6rem; font-size: .84rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.02rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.inline-form { display: inline; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 550; margin-bottom: .3rem; font-size: .9rem; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=search], input[type=file], select, textarea {
    width: 100%; padding: .55rem .7rem; border: 1px solid #cfd5e4; border-radius: 8px;
    background: #fff; color: var(--text); font: inherit;
}
textarea { min-height: 5.5rem; resize: vertical; }
.field { margin-bottom: 1rem; }
.field .hint { color: var(--muted); font-size: .83rem; margin-top: .25rem; }
.field .err { color: var(--bad); font-size: .85rem; margin-top: .25rem; font-weight: 550; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(12, 1fr); }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; }
.check { display: flex; align-items: flex-start; gap: .55rem; font-weight: 500; margin: 0; }
.check input { margin-top: .22rem; width: 1.05rem; height: 1.05rem; flex: none; accent-color: var(--brand); }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }

/* ---------- Cards, tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.15rem 1.25rem; margin-bottom: 1.1rem; }
.card > h2 { margin-bottom: .85rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .85rem; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 1rem 1.25rem 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .62rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfe; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 2.2rem 1rem; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: .14rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 650; white-space: nowrap; background: #eef0f6; color: #4a5570; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.easy { background: var(--good-soft); color: var(--good); }
.badge.medium { background: var(--warn-soft); color: var(--warn); }
.badge.hard { background: var(--bad-soft); color: var(--bad); }

.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert.success { background: var(--good-soft); color: #0a5a3f; border-color: #bfe6d6; }
.alert.error { background: var(--bad-soft); color: #8f251c; border-color: #f2c6c1; }
.alert.info { background: var(--ok-soft); color: #174a9f; border-color: #c6d9f8; }
.alert.warn { background: var(--warn-soft); color: #7c4304; border-color: #f3dcb4; }
.alert ul { margin: .35rem 0 0; padding-left: 1.2rem; }

/* ---------- Admin shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: #171d33; color: #c9cfe3; padding: 1.1rem .8rem; display: flex; flex-direction: column; gap: .2rem; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: .3rem .6rem 1rem; letter-spacing: .01em; }
.brand span { display: block; font-size: .74rem; font-weight: 500; color: #8f98b8; letter-spacing: .05em; text-transform: uppercase; }
.sidebar a.nav { display: block; padding: .55rem .7rem; border-radius: 8px; color: #c9cfe3; font-weight: 550; }
.sidebar a.nav:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.sidebar a.nav.active { background: var(--brand); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: .6rem .7rem .3rem; font-size: .84rem; color: #8f98b8; }
.sidebar .logout { background: none; border: 0; color: #c9cfe3; font: inherit; font-weight: 550; padding: .55rem .7rem; cursor: pointer; text-align: left; width: 100%; border-radius: 8px; }
.sidebar .logout:hover { background: rgba(255, 255, 255, .07); }
.main { padding: 1.5rem 1.75rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head .sub { color: var(--muted); margin-top: .2rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: .86rem; color: var(--muted); margin-bottom: .35rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; margin-bottom: 1.1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .95rem 1.05rem; box-shadow: var(--shadow); }
.stat .k { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.stat .v { font-size: 1.65rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat .n { font-size: .82rem; color: var(--muted); }

.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .f { min-width: 130px; flex: 1 1 130px; max-width: 240px; }
.filters .f.grow { max-width: none; flex: 2 1 220px; }
.filters label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.pager { display: flex; gap: .35rem; align-items: center; justify-content: flex-end; padding: .8rem 1rem; flex-wrap: wrap; }
.pager .info { margin-right: auto; color: var(--muted); font-size: .86rem; }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; }
.tabs a { padding: .55rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem 1.2rem; margin: 0; }
dl.facts dt { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
dl.facts dd { margin: .1rem 0 0; font-weight: 550; overflow-wrap: anywhere; }

.linkbox { display: flex; gap: .5rem; align-items: stretch; flex-wrap: wrap; }
.linkbox input { flex: 1 1 280px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; background: var(--surface-2); }

/* ---------- Score bars ---------- */
.bar { height: 9px; border-radius: 999px; background: #e8ebf3; overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.bar.good > i { background: var(--good); } .bar.ok > i { background: var(--ok); }
.bar.warn > i { background: #d98a17; } .bar.bad > i { background: var(--bad); }
.scoreline { display: grid; grid-template-columns: minmax(120px, 1.3fr) 2fr auto; gap: .8rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.scoreline:last-child { border-bottom: 0; }
.scoreline .lbl { font-weight: 550; overflow-wrap: anywhere; }
.scoreline .val { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; min-width: 5.5rem; text-align: right; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.two-col > .card { margin-bottom: 0; }
.two-col { margin-bottom: 1.1rem; }

.bigscore { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.ring { --p: 0; width: 108px; height: 108px; border-radius: 50%; flex: none; display: grid; place-items: center;
    background: conic-gradient(var(--ring, var(--brand)) calc(var(--p) * 1%), #e8ebf3 0); }
.ring > div { width: 84px; height: 84px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 750; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.ring.good { --ring: var(--good); } .ring.ok { --ring: var(--ok); } .ring.warn { --ring: #d98a17; } .ring.bad { --ring: var(--bad); }

/* ---------- Question review / bank ---------- */
.q { padding: .9rem 0; border-bottom: 1px solid var(--border); }
.q:last-child { border-bottom: 0; }
.q-meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .82rem; color: var(--muted); margin-bottom: .35rem; }
.q-text { font-weight: 550; margin-bottom: .45rem; overflow-wrap: anywhere; }
.q-opts { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .9rem; }
.q-opts li { padding: .28rem .55rem; border-radius: 6px; border: 1px solid transparent; overflow-wrap: anywhere; }
.q-opts li.correct { background: var(--good-soft); border-color: #bfe6d6; color: #0a5a3f; font-weight: 600; }
.q-opts li.wrong { background: var(--bad-soft); border-color: #f2c6c1; color: #8f251c; font-weight: 600; }
.q-opts .k { font-weight: 700; margin-right: .35rem; }
.q-note { margin-top: .45rem; font-size: .86rem; color: var(--muted); }
.q-flag { margin-top: .45rem; font-size: .86rem; background: var(--warn-soft); color: #7c4304; border-radius: 6px; padding: .4rem .6rem; }

.matrix td, .matrix th { text-align: center; white-space: nowrap; }
.matrix td:first-child, .matrix th:first-child { text-align: left; font-weight: 650; }
.matrix .cell { font-variant-numeric: tabular-nums; font-size: .86rem; }
.matrix .cell b { font-weight: 650; }
.matrix .e { color: var(--good); } .matrix .m { color: var(--warn); } .matrix .h { color: var(--bad); }
.matrix .zero { color: #b6bccd; }
.matrix td.thin { background: #fffaf0; }

/* ---------- AI report ---------- */
.report h3 { margin: 1.15rem 0 .5rem; font-size: 1rem; }
.report h3:first-child { margin-top: 0; }
.report p { white-space: pre-line; }
.report ul { margin: 0 0 .5rem; padding-left: 1.15rem; }
.report li { margin-bottom: .3rem; }
.report .item { border: 1px solid var(--border); border-radius: 8px; padding: .7rem .85rem; margin-bottom: .55rem; background: var(--surface-2); }
.report .item .t { font-weight: 650; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.report .item p { margin: .3rem 0 0; }
.spinner { width: 1rem; height: 1rem; border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login / standalone pages ---------- */
.centered { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.panel { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 1.8rem 1.6rem; }
.panel.wide { max-width: 640px; }
.panel h1 { margin-bottom: .3rem; }
.logo { font-weight: 750; color: var(--brand); letter-spacing: .01em; margin-bottom: 1rem; font-size: 1.05rem; }

/* ---------- Student exam ---------- */
.exam-body { background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: 860px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: .75rem; }
.topbar .who { flex: 1; min-width: 0; }
.topbar .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who span { font-size: .8rem; color: var(--muted); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: .35rem .7rem; border-radius: 8px; background: var(--brand-soft); color: var(--brand-dark); white-space: nowrap; }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.progress { height: 4px; background: #e8ebf3; }
.progress > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }
.exam-wrap { max-width: 860px; margin: 0 auto; padding: 1rem 1rem 6.5rem; }
.qcard { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 1.2rem 1.15rem 1.3rem; }
.qcard .q-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; margin-bottom: .8rem; flex-wrap: wrap; }
.qcard .q-num { font-weight: 700; color: var(--brand-dark); }
.qcard .q-body { font-size: 1.12rem; font-weight: 550; line-height: 1.55; margin-bottom: 1rem; overflow-wrap: anywhere; }
.qcard img { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin: 0 0 1rem; }
.opts { display: grid; gap: .6rem; }
.opt { display: flex; align-items: flex-start; gap: .7rem; width: 100%; text-align: start; padding: .8rem .9rem; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); font: inherit; font-size: 1.02rem; color: var(--text); cursor: pointer; transition: border-color .1s, background .1s; }
.opt:hover { border-color: #c3c9de; }
.opt .k { flex: none; width: 1.9rem; height: 1.9rem; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: #eef0f6; color: #4a5570; }
.opt .t { padding-top: .12rem; overflow-wrap: anywhere; min-width: 0; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .k { background: var(--brand); color: #fff; }
.q-tools { display: flex; justify-content: space-between; gap: .5rem; margin-top: .9rem; flex-wrap: wrap; }
.linklike { background: none; border: 0; padding: .3rem 0; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.linklike[disabled] { color: #b6bccd; cursor: default; text-decoration: none; }
.save-state { font-size: .82rem; color: var(--muted); min-height: 1.2rem; margin-top: .6rem; }
.save-state.bad { color: var(--bad); font-weight: 600; }

.botbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--border); padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom)); }
.botbar-in { max-width: 860px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; gap: .6rem; }
.botbar .btn { padding: .7rem .8rem; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 40, .5); z-index: 40; display: grid; place-items: end center; }
.sheet { background: var(--surface); width: 100%; max-width: 620px; max-height: 86vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 1.1rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom)); }
.sheet h2 { margin-bottom: .2rem; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .7rem; }
.pal-subject { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; margin: .9rem 0 .45rem; }
.pal { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: .45rem; }
.pal-btn { height: 44px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface); font: inherit; font-weight: 650; cursor: pointer; color: var(--text); position: relative; }
.pal-btn.done { background: var(--good-soft); border-color: #a9dcc8; color: #0a5a3f; }
.pal-btn.mark::after { content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #d98a17; }
.pal-btn.cur { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(56, 71, 201, .25); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 1rem; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: .35rem; vertical-align: -1px; border: 2px solid var(--border); background: var(--surface); }
.legend i.done { background: var(--good-soft); border-color: #a9dcc8; }
.legend i.mark { background: #d98a17; border-color: #d98a17; border-radius: 50%; }
.sheet-actions { display: flex; gap: .6rem; margin-top: 1.1rem; }
.sheet-actions .btn { flex: 1; }

.student-wrap { max-width: 720px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.student-head { text-align: center; padding: 1rem 0 1.2rem; }
.student-head .logo { margin-bottom: .4rem; }
.rules { margin: 0; padding-left: 1.2rem; }
.rules li { margin-bottom: .45rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .7rem; margin: 1rem 0; }
.kv > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .65rem .8rem; }
.kv .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.kv .v { font-weight: 700; font-size: 1.1rem; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; padding: .6rem .8rem; gap: .15rem; }
    .brand { padding: .2rem .6rem .2rem .3rem; }
    .brand span, .sidebar .who, .sidebar .spacer { display: none; }
    .sidebar a.nav, .sidebar .logout { padding: .4rem .6rem; width: auto; }
    .sidebar form { margin-left: auto; }
    .main { padding: 1rem .9rem 2.5rem; }
    .two-col { grid-template-columns: 1fr; }
    .col-8, .col-6, .col-4, .col-3 { grid-column: span 12; }
    .q-opts { grid-template-columns: 1fr; }
    .scoreline { grid-template-columns: 1fr auto; }
    .scoreline .bar { grid-column: 1 / -1; order: 3; }
}
@media (max-width: 480px) {
    .qcard .q-body { font-size: 1.05rem; }
    .topbar .who span { display: none; }
}

/* ---------- Print (assessment report) ---------- */
@media print {
    body { background: #fff; font-size: 12px; }
    .sidebar, .no-print, .pager, .filters, .tabs { display: none !important; }
    .shell { display: block; }
    .main { padding: 0; }
    .card, .stat { box-shadow: none; break-inside: avoid; }
    .two-col { break-inside: avoid; }
    .q { break-inside: avoid; }
    a { color: inherit; }
}
