/* ==========================================================================
   Salah Testing Dashboard — design system
   One stylesheet for the whole app. Replaces the three clashing inline
   <style> blocks the old dashboard carried.
   ========================================================================== */

:root {
    /* Neutral scale */
    --bg:            #f1f3f7;
    --surface:       #ffffff;
    --surface-2:     #f7f8fb;
    --surface-3:     #eceff5;
    --border:        #dde1ea;
    --border-strong: #c5cbd8;

    --text:          #1a1f2e;
    --text-muted:    #626b80;
    --text-faint:    #8b93a5;

    /* Brand + semantic */
    --accent:        #3b5bdb;
    --accent-hover:  #2f4bc4;
    --accent-soft:   #e7ecfd;
    --accent-text:   #2f4bc4;

    --success:       #17915d;
    --success-soft:  #dff5e9;
    --warning:       #b26a00;
    --warning-soft:  #fdf0d9;
    --danger:        #cc3344;
    --danger-soft:   #fdeaec;
    --info:          #0d7ea8;
    --info-soft:     #ddf1f9;

    /* Sidebar */
    --nav-bg:        #171c2b;
    --nav-bg-2:      #212840;
    --nav-text:      #a8b0c4;
    --nav-text-active: #ffffff;

    /* Spacing scale (8px base) */
    --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
    --s5: 24px; --s6: 32px; --s7: 48px;

    --radius:    10px;
    --radius-sm: 6px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

    --sidebar-w: 232px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 650; line-height: 1.3; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; }
p  { margin: 0 0 var(--s3); }
a  { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted    { color: var(--text-muted); }
.faint    { color: var(--text-faint); }
.small    { font-size: .8rem; }
.tiny     { font-size: .72rem; }
.mono     { font-family: var(--mono); font-size: .82em; }
.nowrap   { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden   { display: none !important; }
.text-right  { text-align: right; }
.text-center { text-align: center; }

.stack   { display: flex; flex-direction: column; gap: var(--s3); }
.row-flex{ display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.spacer  { flex: 1; }

/* ==========================================================================
   Layout
   ========================================================================== */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--nav-bg);
    color: var(--nav-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: var(--s5) var(--s4) var(--s4);
    color: #fff;
    font-weight: 650;
    font-size: .95rem;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.sidebar__brand:hover { text-decoration: none; color: #fff; }
.sidebar__brand-icon {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    background: var(--accent);
    border-radius: var(--radius-sm);
    font-size: 1rem;
}
.sidebar__brand-sub { display: block; font-size: .7rem; font-weight: 400; color: var(--nav-text); }

.sidebar__nav { padding: var(--s3) var(--s2); display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: 9px var(--s3);
    border-radius: var(--radius-sm);
    color: var(--nav-text);
    font-weight: 500;
    font-size: .87rem;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--nav-bg-2); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--accent); color: #fff; }
.nav-item i { width: 16px; text-align: center; font-size: .9rem; }
.nav-item__count {
    margin-left: auto;
    font-size: .7rem;
    background: rgba(255, 255, 255, .12);
    padding: 1px 7px;
    border-radius: 20px;
    font-variant-numeric: tabular-nums;
}

.sidebar__footer {
    padding: var(--s3) var(--s4);
    border-top: 1px solid rgba(255, 255, 255, .07);
    font-size: .72rem;
    color: #6d768e;
}
.sidebar__status { display: flex; align-items: center; gap: 6px; }
.sidebar__dot { width: 7px; height: 7px; border-radius: 50%; background: #3ecf8e; }
.sidebar__dot.is-down { background: var(--danger); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.page-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--s4) var(--s5);
    display: flex;
    align-items: center;
    gap: var(--s4);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 20;
}
.page-header__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-header__sub { font-size: .8rem; color: var(--text-muted); }
.page-header__actions { display: flex; gap: var(--s2); margin-left: auto; flex-wrap: wrap; }

.page-body { padding: var(--s5); flex: 1; }
.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Cards & panels
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s4); }
.card__header {
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--s3);
    flex-wrap: wrap;
}
.card__header h2, .card__header h3 { font-size: .95rem; }
.card__body   { padding: var(--s4); }
.card__body--flush { padding: 0; }
.card__footer {
    padding: var(--s3) var(--s4);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
}

.grid { display: grid; gap: var(--s4); }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--2     { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid--split { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }

/* Stat tiles */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--s4);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat__label {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.stat__value {
    font-size: 1.85rem;
    font-weight: 680;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
}
.stat__meta { font-size: .76rem; color: var(--text-muted); }
.stat--accent  .stat__value { color: var(--accent-text); }
.stat--success .stat__value { color: var(--success); }
.stat--warning .stat__value { color: var(--warning); }
.stat--danger  .stat__value { color: var(--danger); }

.meter { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: var(--s2); }
.meter__fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width .3s ease; }
.meter__fill.is-success { background: var(--success); }
.meter__fill.is-warning { background: var(--warning); }
.meter__fill.is-danger  { background: var(--danger); }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .85rem;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); text-decoration: none; color: var(--text); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn--success { background: var(--success); border-color: var(--success); color: #fff; }
.btn--success:hover:not(:disabled) { background: #127a4d; border-color: #127a4d; color: #fff; }
.btn--danger  { background: var(--surface); border-color: var(--border-strong); color: var(--danger); }
.btn--danger:hover:not(:disabled)  { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn--ghost   { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn--sm { padding: 4px 10px; font-size: .78rem; }
.btn--icon { padding: 6px 8px; }
.btn--block { width: 100%; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); z-index: 1; }

/* ==========================================================================
   Forms
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field__label { font-size: .78rem; font-weight: 600; color: var(--text-muted); }
.field__hint  { font-size: .74rem; color: var(--text-faint); }
.field__error { font-size: .74rem; color: var(--danger); display: none; }
.field.is-invalid .field__error { display: block; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--danger); }
.field__req { color: var(--danger); }

.input, .select, .textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .85rem;
    transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
.textarea--code { font-family: var(--mono); font-size: .8rem; }
.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23626b80' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    padding-right: 26px;
}
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: var(--surface-3);
    outline: none;
    cursor: pointer;
    margin: 9px 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

input[type="file"] { padding: 6px 10px; cursor: pointer; }
input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    font: inherit;
    font-size: .8rem;
    cursor: pointer;
}

.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; font-size: .85rem; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; margin: 0; }

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
    gap: var(--s3);
    align-items: end;
}

.search-input { position: relative; }
.search-input i {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-faint); font-size: .8rem; pointer-events: none;
}
.search-input .input { padding-left: 30px; }

/* ==========================================================================
   Badges, chips, tags
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
    background: var(--surface-3);
    color: var(--text-muted);
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent-text); }
.badge--outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: .74rem;
    font-weight: 500;
}
.tag button {
    border: 0; background: none; padding: 0; cursor: pointer;
    color: var(--text-faint); font-size: .9em; line-height: 1;
}
.tag button:hover { color: var(--danger); }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* Accuracy pill — one consistent read of "how good was this run" */
.acc {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    font-size: .82rem;
    padding: 2px 8px;
    border-radius: 20px;
}
.acc--high { background: var(--success-soft); color: var(--success); }
.acc--mid  { background: var(--warning-soft); color: var(--warning); }
.acc--low  { background: var(--danger-soft);  color: var(--danger); }
.acc--none { background: var(--surface-3);    color: var(--text-faint); }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.table th {
    text-align: left;
    padding: 9px var(--s3);
    font-size: .72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}
.table th.is-sortable { cursor: pointer; user-select: none; }
.table th.is-sortable:hover { color: var(--text); }
.table th i { margin-left: 4px; opacity: .55; font-size: .85em; }
.table th.is-sorted { color: var(--accent-text); }
.table th.is-sorted i { opacity: 1; }
.table td { padding: 10px var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-selected { background: var(--accent-soft); }
.table tbody tr.is-clickable { cursor: pointer; }
.table td.col-check, .table th.col-check { width: 34px; padding-right: 0; }
.table--compact td { padding: 6px var(--s3); }

/* Records table: version columns grouped under one heading, so it is obvious
   the V1/V2/V3 columns are all the same measure. */
.table .th-group {
    background: var(--surface-3);
    border-bottom: 1px solid var(--border);
    font-size: .68rem;
    letter-spacing: .05em;
    color: var(--text-muted);
    padding: 5px var(--s3);
    top: 0;
}
.table .th-group + .th-group,
.table .th-group:not(:first-child) { border-left: 2px solid var(--surface); }
.table thead tr:nth-child(2) th { top: 27px; }

.table .col-version { background: var(--surface-2); }
.table .col-version.is-best { background: var(--success-soft); }
.table tbody tr:hover .col-version { background: var(--surface-3); }
.table tbody tr:hover .col-version.is-best { background: #cdeedd; }
.table th.col-version { font-family: var(--mono); text-transform: none; letter-spacing: 0; }
.table .col-best { border-left: 2px solid var(--surface-3); }
.table .col-production { border-right: 2px solid var(--surface-3); }

/* Transcript beside the rakat extracted from it — the two halves of one run */
.run__panes {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: var(--s4);
    align-items: start;
}
@media (max-width: 900px) {
    .run__panes { grid-template-columns: 1fr; }
}

/* Per-record rakat comparison: ground truth is the reference column, every
   other column is graded against it. */
.rakat-matrix th { vertical-align: bottom; }
.rakat-matrix th.col-truth { background: var(--accent-soft); color: var(--accent-text); }
.rakat-matrix td.col-truth { background: var(--accent-soft); }
.rakat-matrix__n {
    font-size: .72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-faint);
    white-space: nowrap;
    vertical-align: top;
}
.rakat-matrix__cell { vertical-align: top; min-width: 150px; border-left: 3px solid transparent; }
.rakat-matrix__cell.is-clean   { border-left-color: var(--success); }
.rakat-matrix__cell.is-partial { border-left-color: var(--warning); }
.rakat-matrix__cell.is-wrong   { border-left-color: var(--danger); }
.rakat-matrix__surah { font-weight: 600; font-size: .88rem; }
.rakat-matrix .ayat-diff { margin-top: 5px; max-width: 260px; }

/* Matrix footer: the per-version totals stay readable while rows scroll */
.table tfoot .matrix-foot td {
    background: var(--surface-2);
    border-top: 1px solid var(--border-strong);
    font-size: .8rem;
}
.table tfoot .matrix-foot:first-child td { border-top: 2px solid var(--border-strong); }
.table tfoot .matrix-foot td.col-version { background: var(--surface-3); }

.table th.col-production { text-transform: none; letter-spacing: 0; }

.pagination {
    display: flex;
    align-items: center;
    gap: var(--s2);
    justify-content: space-between;
    flex-wrap: wrap;
}
.pagination__pages { display: flex; gap: 3px; align-items: center; }

/* ==========================================================================
   Empty / loading states
   ========================================================================== */

.empty { padding: var(--s7) var(--s4); text-align: center; color: var(--text-muted); }
.empty__icon {
    width: 46px; height: 46px; margin: 0 auto var(--s3);
    display: grid; place-items: center;
    background: var(--surface-3); border-radius: 50%;
    color: var(--text-faint); font-size: 1.15rem;
}
.empty__title { font-weight: 600; color: var(--text); margin-bottom: 3px; }
.empty__body  { font-size: .85rem; margin-bottom: var(--s4); }

.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, #f4f6fa 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.3s infinite;
    border-radius: var(--radius-sm);
    height: 12px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton-row { display: flex; gap: var(--s3); padding: 11px var(--s3); border-bottom: 1px solid var(--border); }
.skeleton-row .skeleton:nth-child(1) { flex: 2; }
.skeleton-row .skeleton:nth-child(2) { flex: 1; }
.skeleton-row .skeleton:nth-child(3) { flex: 1; }
.skeleton-row .skeleton:nth-child(4) { flex: 1.4; }

.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-host {
    position: fixed;
    bottom: var(--s5);
    right: var(--s5);
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    z-index: 200;
    max-width: min(400px, calc(100vw - 32px));
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--s3);
    padding: var(--s3) var(--s4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: .85rem;
    animation: toast-in .2s ease;
}
.toast.is-success { border-left-color: var(--success); }
.toast.is-error   { border-left-color: var(--danger); }
.toast.is-warning { border-left-color: var(--warning); }
.toast__icon { margin-top: 2px; }
.toast.is-success .toast__icon { color: var(--success); }
.toast.is-error   .toast__icon { color: var(--danger); }
.toast.is-warning .toast__icon { color: var(--warning); }
.toast.is-info    .toast__icon { color: var(--accent); }
.toast__body  { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast__title { font-weight: 600; }
.toast__close { border: 0; background: none; cursor: pointer; color: var(--text-faint); padding: 0; font-size: .9rem; }
.toast.is-leaving { animation: toast-out .18s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ==========================================================================
   Modals
   ========================================================================== */

.modal-host {
    position: fixed;
    inset: 0;
    background: rgba(16, 20, 32, .5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--s5) var(--s4);
    overflow-y: auto;
    z-index: 150;
    animation: fade .14s ease;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    margin: auto;
    animation: modal-in .18s ease;
}
.modal--wide  { max-width: 900px; }
.modal--large { max-width: 1120px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px) scale(.99); } to { opacity: 1; transform: none; } }

.modal__header {
    padding: var(--s4) var(--s5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--s3);
}
.modal__title { flex: 1; }
.modal__body   { padding: var(--s5); }
.modal__footer {
    padding: var(--s3) var(--s5);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--s2);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-wrap: wrap;
}

/* Tabs (used in the Add Record modal and the record detail) */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--s4); overflow-x: auto; }
.tab {
    padding: 8px 14px;
    border: 0;
    background: none;
    color: var(--text-muted);
    font: inherit;
    font-size: .85rem;
    font-weight: 550;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent-text); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ==========================================================================
   Record detail
   ========================================================================== */

.detail-head {
    display: flex;
    align-items: flex-start;
    gap: var(--s4);
    flex-wrap: wrap;
    margin-bottom: var(--s4);
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--s4); font-size: .84rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.audio-player { width: 100%; margin-top: var(--s2); border-radius: var(--radius-sm); }

.arabic {
    direction: rtl;
    text-align: right;
    font-size: 1.15rem;
    line-height: 2;
    font-family: "Traditional Arabic", "Scheherazade New", serif;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s3);
    overflow-y: auto;
    max-height: 60vh;
}
/* Collapsed by default when long, with a fade so it reads as "there is more" */
.arabic.is-clamped {
    max-height: 150px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 60%, transparent 100%);
}

/* Right rail follows you down the page instead of leaving 1000px of dead space */
.detail__rail { align-self: start; position: sticky; top: calc(var(--s4) + 68px); }
.detail__sublabel {
    display: flex;
    align-items: baseline;
    gap: var(--s2);
    font-size: .78rem;
    color: var(--text-muted);
    margin-bottom: var(--s2);
}
.kv.tiny { font-size: .76rem; }
.kv.tiny dd { overflow-wrap: anywhere; }

@media (max-width: 1100px) {
    .detail__rail { position: static; }
}

/* Rakat rendering — human-readable, replaces the raw <pre> JSON dumps */
.rakat-list { display: flex; flex-direction: column; gap: var(--s2); }
.rakat {
    display: flex;
    align-items: baseline;
    gap: var(--s3);
    padding: var(--s2) var(--s3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .84rem;
}
.rakat__n {
    flex: 0 0 auto;
    font-weight: 650;
    font-size: .72rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.rakat__surah { font-weight: 600; }
.rakat__ayat  { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rakat.is-match    { border-left: 3px solid var(--success); }
.rakat.is-mismatch { border-left: 3px solid var(--danger); }

.ayat-diff { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.ayah {
    display: inline-block;
    min-width: 22px;
    text-align: center;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: .72rem;
    font-variant-numeric: tabular-nums;
    background: var(--surface-3);
    color: var(--text-muted);
}
.ayah.is-hit    { background: var(--success-soft); color: var(--success); }
.ayah.is-missed { background: var(--danger-soft);  color: var(--danger); }
.ayah.is-extra  { background: var(--warning-soft); color: var(--warning); text-decoration: line-through; }

/* Comments */
.comment-list { display: flex; flex-direction: column; gap: var(--s3); }
.comment {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s3);
}
.comment__head {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-bottom: 5px;
    font-size: .78rem;
}
.comment__author { font-weight: 650; }
.comment__actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.comment:hover .comment__actions, .comment:focus-within .comment__actions { opacity: 1; }
.comment__text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .87rem; }

.avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-text);
    display: grid; place-items: center;
    font-size: .72rem; font-weight: 650;
    flex: 0 0 auto;
}

/* Test runs */
.run {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: var(--s3);
    overflow: hidden;
}
.run__head {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: var(--s3);
    background: var(--surface-2);
    flex-wrap: wrap;
}
.run__body { padding: var(--s3); border-top: 1px solid var(--border); }
.run__versions { font-family: var(--mono); font-size: .78rem; }
.run.is-pass   { border-left: 3px solid var(--success); }
.run.is-fail   { border-left: 3px solid var(--danger); }
.run.is-unsure { border-left: 3px solid var(--warning); }

.verdict-group .btn.is-active[data-verdict="pass"]   { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.verdict-group .btn.is-active[data-verdict="fail"]   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.verdict-group .btn.is-active[data-verdict="unsure"] { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }

/* ==========================================================================
   Testing view — run queue
   ========================================================================== */

.queue { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.queue__item {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: var(--s2) var(--s3);
    background: var(--surface);
    font-size: .84rem;
}
.queue__status { width: 18px; text-align: center; flex: 0 0 auto; }
.queue__item.is-running { background: var(--accent-soft); }
.queue__item.is-done    { background: var(--surface); }
.queue__item.is-error   { background: var(--danger-soft); }

.progress { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width .25s ease; }

/* ==========================================================================
   Charts
   ========================================================================== */

.chart-box { position: relative; width: 100%; height: 300px; }
.chart-box--tall  { height: 380px; }
.chart-box--short { height: 230px; }

.legend { display: flex; flex-wrap: wrap; gap: var(--s3); font-size: .78rem; color: var(--text-muted); }
.legend__item { display: flex; align-items: center; gap: 6px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }

/* Bar list — a lightweight alternative to a chart for short rankings */
.bar-list { display: flex; flex-direction: column; gap: var(--s3); }
.bar-list__row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto; gap: var(--s3); align-items: center; font-size: .83rem; }
/* Both are <span>s — without display:block the width/height are ignored and
   the bar renders as an empty track. */
.bar-list__track { display: block; height: 20px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar-list__fill  { display: block; height: 100%; border-radius: 4px; transition: width .3s ease; min-width: 2px; }
.bar-list__value { font-variant-numeric: tabular-nums; font-weight: 650; min-width: 54px; text-align: right; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1100px) {
    .grid--split { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex: none;
        height: auto;
        position: sticky;
        top: 0;
    }
    .sidebar__brand { padding: var(--s3) var(--s4); border-bottom: 0; }
    .sidebar__brand-sub { display: none; }
    .sidebar__nav {
        flex-direction: row;
        overflow-x: auto;
        padding: 0 var(--s2) var(--s2);
        gap: var(--s1);
    }
    .nav-item { padding: 7px 11px; font-size: .8rem; }
    .nav-item__count { display: none; }
    .sidebar__footer { display: none; }
    .page-header { padding: var(--s3) var(--s4); position: static; }
    .page-body { padding: var(--s4); }
    .stat__value { font-size: 1.5rem; }
    .toast-host { left: var(--s3); right: var(--s3); bottom: var(--s3); max-width: none; }
    .modal-host { padding: var(--s3); }
    .bar-list__row { grid-template-columns: 1fr; gap: 4px; }
    .bar-list__value { text-align: left; }
}

@media (max-width: 520px) {
    .filters { grid-template-columns: 1fr 1fr; }
    .page-header__actions { width: 100%; margin-left: 0; }
    .page-header__actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
