/* Dyslexia-friendly base styles:
   - Off-white background (reduces glare)
   - Generous line-height and letter-spacing
   - Sans-serif with good distinction between letters
   - Soft, non-aggressive highlight for errors
*/

:root {
    --bg: #fdfaf3;
    --panel-bg: #ffffff;
    --text: #2a2a2a;
    --muted: #6b6b6b;
    --accent: #2a6fa6;
    --accent-hover: #225d8c;
    --border: #d8d4cc;
    --highlight: #fff3b0;
    --highlight-border: #d4a40a;
    --success: #2e7d32;
    --error: #b71c1c;
    --radius: 10px;

    --topbar-h: 56px;
    --page-padding: 1.5rem;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Verdana", "Tahoma", "Trebuchet MS", system-ui, sans-serif;
    line-height: 1.6;
    letter-spacing: 0.02em;
    min-height: 100vh;
    height: 100%;
}

h1, h2, h3 { font-weight: 600; letter-spacing: 0.01em; }
.muted { color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.04);
}
.login-card h1 { margin: 0 0 0.25rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1.25rem; }
.login-card label { display: flex; flex-direction: column; font-size: 0.92rem; gap: 0.35rem; }
.login-card input {
    font: inherit;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(42,111,166,0.15);
}

button {
    font: inherit;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
}
button.secondary:hover { background: #f0ece2; }

.flash {
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.92rem;
    margin-top: 1rem;
}
.flash-error { background: #fdecea; color: var(--error); }
.flash-success { background: #eaf6ec; color: var(--success); }

/* ---------- App layout ---------- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--page-padding);
    height: var(--topbar-h);
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 1.1rem; }
.user-info { display: flex; align-items: center; gap: 1rem; font-size: 0.92rem; }
.link-btn {
    color: var(--accent);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    /* Reset native button styling for <button class="link-btn"> elements */
    background: transparent;
    font: inherit;
    font-size: 0.92rem;
    cursor: pointer;
    line-height: 1.4;
}
.link-btn:hover { background: #f0ece2; }

/* Main grid: two equal-height panels filling the remaining viewport */
.app-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    padding: var(--page-padding);
    max-width: 1400px;
    margin: 0 auto;
    height: calc(100vh - var(--topbar-h));
}
@media (max-width: 800px) {
    .app-main {
        grid-template-columns: 1fr;
        /* On mobile, allow page to scroll between two stacked panels */
        height: auto;
        min-height: calc(100vh - var(--topbar-h));
    }
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    min-height: 0; /* important: lets children with overflow actually scroll */
    position: relative;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.panel h3 { margin: 1rem 0 0.5rem; font-size: 0.95rem; color: var(--muted); }

/* Panel header row: title on the left, controls on the right */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}
.panel-header h2 { margin: 0; }

/* Icon button (used for copy-to-clipboard) */
.icon-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    position: relative;
}
.icon-btn:hover:not(:disabled) {
    background: #f0ece2;
    color: var(--accent);
    border-color: var(--accent);
}
.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.icon-btn .icon {
    width: 18px;
    height: 18px;
    display: block;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
/* Check icon is hidden by default; shown when .copied is set */
.icon-btn .icon-check {
    position: absolute;
    opacity: 0;
    transform: scale(0.6);
}
.icon-btn.copied {
    color: var(--success);
    border-color: var(--success);
    background: #eaf6ec;
}
.icon-btn.copied .icon-copy {
    opacity: 0;
    transform: scale(0.6);
}
.icon-btn.copied .icon-check {
    opacity: 1;
    transform: scale(1);
}

/* Input textarea fills the input panel */
#input-text {
    flex: 1;
    min-height: 180px;
    width: 100%;
    font: inherit;
    line-height: 1.7;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    resize: vertical;
}
#input-text:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(42,111,166,0.15);
}

.actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.9rem;
    flex-wrap: wrap;
}
.status { color: var(--muted); font-size: 0.9rem; }
.status.error { color: var(--error); }

/* ---------- Corrected output (scrollable) ---------- */
.scrollable {
    overflow-y: auto;
    /* Custom scrollbar styling for nicer feel */
    scrollbar-width: thin;
    scrollbar-color: #c9c4b8 transparent;
}
.scrollable::-webkit-scrollbar { width: 8px; }
.scrollable::-webkit-scrollbar-thumb { background: #c9c4b8; border-radius: 4px; }
.scrollable::-webkit-scrollbar-track { background: transparent; }

.corrected {
    /* Roughly 55% of the panel height; rest is for error list */
    flex: 1 1 55%;
    min-height: 120px;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.corrected mark {
    background: var(--highlight);
    border-bottom: 2px solid var(--highlight-border);
    padding: 0 2px;
    border-radius: 3px;
    cursor: help;
    position: relative;
}
.corrected mark:hover { background: #ffe580; }

/* Cursor hint for highlighted words */
.corrected mark[data-tip] {
    cursor: help;
}

/* Portal-rendered tooltip — appended to <body> by app.js, positioned via JS.
   Lives outside any scrolling container so it never gets clipped. */
.tooltip {
    position: fixed;
    background: #222;
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: "Verdana", "Tahoma", "Trebuchet MS", system-ui, sans-serif;
    line-height: 1.4;
    letter-spacing: normal;
    max-width: 280px;
    width: max-content;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Arrow on the tooltip. Default: tooltip is below the word, so arrow points up.
   When .tooltip is given .above, the arrow flips to point down. */
.tooltip::after {
    content: "";
    position: absolute;
    left: var(--arrow-left, 50%);
    transform: translateX(-50%);
    border: 5px solid transparent;
}
.tooltip:not(.above)::after {
    bottom: 100%;
    border-bottom-color: #222;
}
.tooltip.above::after {
    top: 100%;
    border-top-color: #222;
}

.errors-heading { flex: 0 0 auto; }

/* ---------- Error list (scrollable) ---------- */
.error-list {
    flex: 1 1 45%;
    min-height: 80px;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.error-list:empty { display: none; }

.error-item {
    background: #fff8e6;
    border: 1px solid #f0deaa;
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    font-size: 0.92rem;
}
.error-item .swap { font-weight: 600; }
.error-item .original { text-decoration: line-through; color: #a14a1f; }
.error-item .arrow { margin: 0 0.4rem; color: var(--muted); }
.error-item .correction { color: var(--success); }
.error-item .explanation {
    margin-top: 0.3rem;
    color: var(--muted);
    font-style: italic;
}
.error-item .meta {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--muted);
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}
.error-item .meta .tag {
    display: inline-block;
    background: #efe9d8;
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
}

.no-errors {
    background: #eaf6ec;
    border: 1px solid #c3e0c8;
    color: var(--success);
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    font-weight: 600;
}

/* ---------- Spinner ---------- */
.spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(2px);
    border-radius: var(--radius);
    z-index: 20;
    opacity: 1;
    transition: opacity 0.18s ease;
}
.spinner.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner-ring {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid #ece6d6;
    border-top-color: var(--accent);
    border-right-color: var(--accent);
    animation: spinner-rotate 1.1s linear infinite;
}

.spinner-letter {
    position: relative;
    width: 78px;
    height: 78px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0;
    /* Flip animation each time the letter changes */
    animation: spinner-flip 0.4s ease;
    will-change: transform, opacity;
}
.spinner-letter.flipping {
    animation: spinner-flip 0.32s ease;
}

@keyframes spinner-rotate {
    to { transform: rotate(360deg); }
}

@keyframes spinner-flip {
    0%   { transform: rotateY(-90deg); opacity: 0; }
    50%  { opacity: 1; }
    100% { transform: rotateY(0);      opacity: 1; }
}

/* Reduced motion: simpler spinner */
@media (prefers-reduced-motion: reduce) {
    .spinner-ring { animation-duration: 2.4s; }
    .spinner-letter { animation: none; }
}

/* ============================================================
 * Stats page
 * ============================================================ */

.brand a {
    color: inherit;
    text-decoration: none;
}
.brand a:hover { color: var(--accent); }

.stats-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem var(--page-padding);
}

.stats-header {
    margin-bottom: 2rem;
}
.stats-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.6rem;
    letter-spacing: -0.01em;
}
.stats-header .muted {
    margin: 0;
    font-size: 0.95rem;
}

/* ---------- Empty state ---------- */
.empty-state {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.empty-state h2 { margin: 0 0 0.5rem; font-size: 1.3rem; }
.empty-state p  { margin: 0 0 1.5rem; color: var(--muted); }
.cta-btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 0.7rem 1.4rem;
    border-radius: 8px;
    font-weight: 500;
    transition: background 0.15s;
}
.cta-btn:hover { background: var(--accent-hover); }

/* ---------- Headline cards ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 900px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
    .cards { grid-template-columns: 1fr; }
}

.card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
/* Left accent stripe colours each card */
.card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
}
.card-blue::before   { background: #2a6fa6; }
.card-amber::before  { background: #c97b3a; }
.card-teal::before   { background: #2e7d77; }
.card-purple::before { background: #6b4f8a; }

.card-value {
    font-size: 2.2rem;
    font-weight: 600;
    line-height: 1.1;
    color: var(--text);
    font-feature-settings: "tnum" 1;  /* tabular numerals */
}
.card-label {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

/* ---------- Two-column layout for charts ---------- */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 900px) {
    .two-col { grid-template-columns: 1fr; }
}

/* Override the .panel rules from the main app for this page (smaller, lighter) */
.stats-main .panel {
    min-height: 0;
    padding: 1.25rem 1.4rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}
.stats-main .panel h2 {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
}
.stats-main .panel .muted.small {
    font-size: 0.82rem;
    margin: 0 0 1rem;
}

/* ---------- Bar list (top words / top patterns) ---------- */
.bar-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.bar-list li {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.bar-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.9rem;
    gap: 0.5rem;
}
.bar-label {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bar-original {
    text-decoration: line-through;
    color: #a14a1f;
    font-weight: 500;
}
.bar-arrow {
    color: var(--muted);
    margin: 0 0.3rem;
}
.bar-correction {
    color: var(--success);
    font-weight: 500;
}
.bar-count {
    color: var(--muted);
    font-size: 0.85rem;
    font-feature-settings: "tnum" 1;
    flex-shrink: 0;
}
.bar-track {
    background: #f0ece2;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}
.bar-blue  { background: linear-gradient(90deg, #2a6fa6, #4a8fc6); }
.bar-amber { background: linear-gradient(90deg, #c97b3a, #e09c5a); }

/* ---------- Donut chart ---------- */
.donut-panel { display: flex; flex-direction: column; }
.donut-wrap {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1.5rem;
    align-items: center;
    margin-top: 0.5rem;
}
@media (max-width: 500px) {
    .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
}
.donut {
    width: 160px;
    height: 160px;
    flex-shrink: 0;
}
.donut-num {
    font-size: 1.4rem;
    font-weight: 600;
    fill: var(--text);
    font-feature-settings: "tnum" 1;
}
.donut-sub {
    font-size: 0.5rem;
    fill: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.donut-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.donut-legend li {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.88rem;
}
.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}
.legend-label { color: var(--text); }
.legend-count {
    color: var(--muted);
    font-feature-settings: "tnum" 1;
}

/* ---------- Recent submissions ---------- */
.recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.recent-item {
    border-left: 3px solid #f0ece2;
    padding: 0.4rem 0.8rem;
    transition: border-color 0.15s;
}
.recent-item:hover {
    border-left-color: var(--accent);
}
.recent-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.2rem;
}
.recent-date {
    color: var(--muted);
    font-size: 0.8rem;
    font-feature-settings: "tnum" 1;
}
.recent-badge {
    background: #f0ece2;
    color: var(--muted);
    border-radius: 4px;
    padding: 0.1rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 500;
}
.recent-badge.recent-clean {
    background: #eaf6ec;
    color: var(--success);
}
.recent-snippet {
    color: var(--text);
    font-size: 0.88rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
 * Admin pages
 * ============================================================ */

.admin-tag {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 0.4rem;
}

.admin-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.75rem var(--page-padding) 3rem;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.admin-header h1 {
    margin: 0;
    font-size: 1.5rem;
}
.admin-header h1 code {
    background: #f0ece2;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
}
.admin-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-small, .btn-warning, .btn-danger {
    display: inline-block;
    border: 1px solid var(--border);
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    background: #fff;
    color: var(--text);
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    font-family: inherit;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary:hover { background: #f0ece2; }

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.82rem;
}
.btn-small:hover { background: #f0ece2; }

.btn-warning {
    color: #b8560a;
    border-color: #e9c79b;
}
.btn-warning:hover { background: #fdecdc; }

.btn-danger {
    color: var(--error);
    border-color: #f3b1b1;
}
.btn-danger:hover { background: #fdecea; }

/* ---------- Flash messages ---------- */
.flash-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

/* ---------- Table ---------- */
.admin-table-wrap {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    margin-bottom: 1rem;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-table thead {
    background: #f8f5ed;
    border-bottom: 2px solid var(--border);
}
.admin-table th {
    text-align: left;
    padding: 0.7rem 0.85rem;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.admin-table td {
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: #fcfaf3; }
.admin-table tr.row-deleted td {
    color: var(--muted);
    background: #faf7f0;
}
.admin-table tr.row-deleted td strong {
    text-decoration: line-through;
    color: var(--muted);
}

.role-badge {
    display: inline-block;
    background: #f0ece2;
    color: var(--muted);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.76rem;
    font-weight: 500;
}
.role-badge.role-super {
    background: #e6f0fa;
    color: var(--accent);
}
.role-badge.role-group {
    background: #faf0e6;
    color: #c97b3a;
}

.lang-pair {
    font-family: "SF Mono", "Menlo", monospace;
    font-size: 0.82rem;
    color: var(--muted);
}
.counts {
    color: var(--muted);
    font-feature-settings: "tnum" 1;
}

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.76rem;
    font-weight: 500;
}
.status-badge.status-active {
    background: #eaf6ec;
    color: var(--success);
}
.status-badge.status-deleted {
    background: #fdecea;
    color: var(--error);
}

.row-actions {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    align-items: center;
}
.inline-form {
    display: inline;
    margin: 0;
}
.self-note {
    color: var(--muted);
    font-style: italic;
    font-size: 0.85rem;
}

/* ---------- Danger zone (hard-delete dropdown) ---------- */
.danger-zone summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}
.danger-zone summary::-webkit-details-marker { display: none; }
.danger-zone[open] summary {
    background: #fdecea;
    border-color: var(--error);
}
.confirm-form {
    margin-top: 0.6rem;
    padding: 0.8rem;
    background: #fdecea;
    border: 1px solid #f3b1b1;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 280px;
}
.confirm-form .confirm-msg {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text);
}
.confirm-form code {
    background: #fff;
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
    font-size: 0.85em;
    border: 1px solid #f3b1b1;
}
.confirm-form input[type="text"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    font-size: 0.88rem;
}

/* ---------- Form (new/edit user) ---------- */
.admin-form {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 800px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 700px) {
    .form-row { grid-template-columns: 1fr; }
}
.form-row label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.88rem;
    font-weight: 500;
}
.form-row input, .form-row select {
    font: inherit;
    font-size: 0.94rem;
    font-weight: normal;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
.form-row input:focus, .form-row select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(42,111,166,0.15);
}
.form-row .hint {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: normal;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* ============================================================
 * Import jobs (admin)
 * ============================================================ */

.upload-form { display: flex; flex-direction: column; gap: 1rem; }
.file-drop {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: #fafaf5;
}
.file-drop:hover { border-color: var(--accent); background: #f4f0e4; }
.file-drop input[type="file"] {
    display: block;
    margin: 0.5rem auto 0;
}
.file-drop-text { color: var(--muted); font-size: 0.92rem; }

.admin-info {
    background: #f8f5ed;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.9rem;
    margin: 1rem 0;
    font-size: 0.88rem;
}
.admin-info summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--muted);
    padding: 0.3rem 0;
}
.admin-info[open] summary { color: var(--text); }
.admin-info ul { margin: 0.5rem 0; padding-left: 1.5rem; }
.admin-info li { margin: 0.25rem 0; }
.admin-info p { margin: 0.5rem 0 0; color: var(--muted); }

.import-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.5rem 1.5rem;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.4rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.import-meta strong { color: var(--muted); margin-right: 0.4rem; font-weight: 500; }

.progress-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.4rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}
.progress-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.progress-label { font-weight: 500; }
.progress-counts {
    display: flex;
    gap: 0.6rem;
    font-size: 0.88rem;
}
.count-good     { color: var(--success); }
.count-bad      { color: var(--error); }
.count-running  { color: var(--accent); }
.count-pending  { color: var(--muted); }
.progress-track {
    display: flex;
    height: 10px;
    background: #f0ece2;
    border-radius: 5px;
    overflow: hidden;
}
.progress-fill { height: 100%; transition: width 0.3s ease; }
.progress-done   { background: linear-gradient(90deg, #2e7d32, #4c9b51); }
.progress-failed { background: linear-gradient(90deg, #b71c1c, #d44a4a); }

.section-h { margin: 2rem 0 1rem; font-size: 1.1rem; }

.status-badge.status-running {
    background: #e6f0fa;
    color: var(--accent);
}
.status-badge.status-pending {
    background: #f0ece2;
    color: var(--muted);
}

.item-text {
    font-size: 0.88rem;
    max-width: 600px;
    word-break: break-word;
}
.item-result { font-size: 0.85rem; }

/* ============================================================
 * Teacher views (admin user-stats + group-stats)
 * ============================================================ */

.teacher-view-banner {
    background: #e6f0fa;
    border: 1px solid #b8d4ec;
    border-left: 4px solid var(--accent);
    border-radius: 6px;
    padding: 0.7rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
.teacher-view-banner strong { color: var(--accent); }
.teacher-view-banner a { color: var(--accent); }

/* Three-card variant for group stats (only 3 cards, not 4) */
.cards-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 700px) {
    .cards-3 { grid-template-columns: 1fr; }
}

/* Raw snake_case pattern hint shown next to friendly label */
.bar-raw {
    background: #f0ece2;
    color: var(--muted);
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    font-size: 0.75em;
    font-family: "SF Mono", "Menlo", monospace;
    font-weight: normal;
    margin-left: 0.3rem;
}

/* Member list in group stats */
.member-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.member-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--text);
    transition: background 0.12s;
    gap: 1rem;
}
.member-row:hover { background: #f4f0e4; }
.member-name { font-size: 0.92rem; }

/* Per-pattern student breakdown (collapsible) */
.pattern-breakdown {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    background: #fafaf5;
}
.pattern-breakdown summary {
    cursor: pointer;
    padding: 0.6rem 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.92rem;
    transition: background 0.12s;
}
.pattern-breakdown summary::-webkit-details-marker { display: none; }
.pattern-breakdown summary::before {
    content: "▸";
    color: var(--muted);
    transition: transform 0.15s;
    display: inline-block;
}
.pattern-breakdown[open] summary::before {
    transform: rotate(90deg);
}
.pattern-breakdown summary:hover { background: #f0ece2; }
.pattern-breakdown .pattern-name { font-weight: 500; flex: 1; }

.pattern-students {
    list-style: none;
    margin: 0;
    padding: 0.4rem 0.9rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border-top: 1px solid var(--border);
}
.pattern-students li {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.88rem;
}
.pattern-students a {
    color: var(--accent);
    text-decoration: none;
}
.pattern-students a:hover { text-decoration: underline; }

/* Form: full-width row (for the checkbox) */
.form-row-single { grid-template-columns: 1fr; }
.checkbox-label {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 0.6rem !important;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.checkbox-label > span:first-of-type {
    font-weight: 500;
}
.checkbox-label .hint {
    display: block;
    margin-top: 0.25rem;
    font-weight: normal;
}

/* Diagnostic cards (timer + LIX) — second-row variant under headline cards */
.cards-diag {
    grid-template-columns: 1fr 1fr;
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 700px) {
    .cards-diag { grid-template-columns: 1fr; }
}
.card-diagnostic::before { background: #6b6358; }  /* warm neutral stripe */
.card-diagnostic .card-value { font-size: 1.6rem; }
.card-diagnostic .card-sub {
    margin-top: 0.4rem;
    line-height: 1.3;
}

/* ============================================================
 * /write PWA — minimal layout
 * ============================================================ */

.write-body {
    min-height: 100vh;
    min-height: 100dvh;  /* dynamic viewport for mobile address bars */
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.write-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel-bg);
    flex-shrink: 0;
}

.write-icon {
    border-radius: 6px;
    display: block;
}

.write-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.write-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

@media (max-width: 800px) {
    .write-main {
        grid-template-columns: 1fr;
    }
}

.panel-write {
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

/* Accessible-but-invisible label headings — screen readers see them, sighted users don't */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Output header to hold the copy button on its own */
.output-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
    min-height: 32px;
}

/* ============================================================
 * /write/login — minimal centered card
 * ============================================================ */

.write-login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    min-height: 100vh;
    min-height: 100dvh;
}

.write-login-main {
    width: 100%;
    max-width: 400px;
}

.write-login-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.05);
    text-align: center;
}
.write-login-card h1 {
    margin: 0.5rem 0 1.5rem;
    font-size: 1.5rem;
    color: var(--accent);
}
.write-login-card form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
}
.write-login-card label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: var(--text);
}
.write-login-card input {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    font-size: 1rem;
}
.write-login-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(42,111,166,0.15);
}
.write-login-card button.primary {
    padding: 0.7rem 1.4rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 0.5rem;
}
.write-login-card button.primary:hover { background: var(--accent-hover); }
.write-login-icon { margin-top: 0.5rem; }

.write-login-install {
    margin-top: 1.5rem;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
}
.write-login-install button {
    color: var(--accent);
    font-weight: 500;
}

/* Install affordance on the main login page */
.login-install {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.88rem;
}
.login-install button { color: var(--accent); font-weight: 500; }

/* PWA install popover — Safari/no-beforeinstallprompt fallback when there's
 * no dedicated #install-instructions element to show inline */
.install-popover {
    position: fixed;
    z-index: 10000;
    background: #222;
    color: #fff;
    padding: 0.6rem 0.85rem;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.4;
    max-width: 280px;
    width: max-content;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    pointer-events: auto;
}
