:root {
    --bg: #f4f4f5;
    --surface: #ffffff;
    --text: #1f1f1f;
    --muted: #666;
    --border: #d4d4d8;
    --primary: #1f4b99;
    --primary-text: #fff;
    --danger: #9b1c1c;
    --danger-bg: #fee2e2;
    --info-bg: #e0f2fe;
    --ok: #166534;
    --warn: #9a3412;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
    line-height: 1.7;
}

a {
    color: var(--primary);
}

.admin-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.admin-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: #111827;
    color: #fff;
    flex-wrap: wrap;
}

.admin-brand {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
}

.admin-nav {
    display: flex;
    gap: 1rem;
    flex: 1;
    flex-wrap: wrap;
}

.admin-nav a {
    color: #e5e7eb;
    text-decoration: none;
}

.admin-nav a.active {
    color: #fff;
    text-decoration: underline;
}

.admin-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.admin-user-email {
    color: #fff;
    font-weight: 600;
}

.admin-user-roles {
    color: #9ca3af;
    font-size: 0.85rem;
}

.admin-signout {
    background: transparent;
    border-color: #4b5563;
    color: #e5e7eb;
}

.admin-signout:hover {
    border-color: #9ca3af;
    color: #fff;
}

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-panel {
    width: 100%;
    max-width: 26rem;
    margin: 0;
}

.login-panel h1 {
    margin-top: 0;
}

.admin-main {
    padding: 1.25rem;
    max-width: 1400px;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.page-header h1 {
    margin: 0.25rem 0;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

.analyze-action {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-width: 18rem;
}

.analyze-hint {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.35;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.panel-danger {
    border-color: #f0b4b4;
    background: #fff8f8;
}

.panel-danger h2 {
    color: var(--danger);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.panel h2, .panel h3 {
    margin: 0 0 0.75rem;
}

.muted {
    color: var(--muted);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th, td {
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0.6rem;
    text-align: right;
    vertical-align: top;
}

th {
    background: #fafafa;
}

.btn {
    display: inline-block;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    padding: 0.35rem 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
}

.btn-secondary {
    background: #fff;
}

.btn-danger {
    color: var(--danger);
    border-color: #f0b4b4;
}

.btn-small {
    padding: 0.15rem 0.4rem;
    font-size: 0.85rem;
}

.banner {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.banner-error {
    background: var(--danger-bg);
    color: var(--danger);
}

.banner-info {
    background: var(--info-bg);
}

.banner ul {
    margin: 0.3rem 0 0;
}

.status-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
}

.status-uploaded { background: #f4f4f5; }
.status-draft { background: #fef3c7; color: var(--warn); }
.status-approved { background: #dbeafe; }
.status-busy { background: #ede9fe; }
.status-done { background: #dcfce7; color: var(--ok); }
.status-failed { background: var(--danger-bg); color: var(--danger); }

.form-grid {
    display: grid;
    gap: 0.85rem;
    max-width: 40rem;
    margin-bottom: 1rem;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

input, select, textarea, .input-title {
    font: inherit;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.input-narrow {
    width: 5.5rem;
}

.inline-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
}

.editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(16rem, 0.9fr);
    gap: 1rem;
    align-items: start;
}

@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }
}

.node-tree {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.node-block {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem;
    background: #fff;
}

.node-selected {
    outline: 2px solid var(--primary);
}

.node-invalid {
    border-color: var(--danger);
    background: #fff8f8;
}

.node-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    cursor: pointer;
}

.node-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.input-title {
    min-width: 12rem;
    flex: 1;
}

.node-pdf {
    font-size: 0.85rem;
}

.node-errors {
    color: var(--danger);
    margin: 0.35rem 0 0;
}

.preview-pane {
    position: sticky;
    top: 0.75rem;
}

.preview-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.75rem;
}

.page-image {
    width: 100%;
    height: auto;
    border: 1px solid var(--border);
}

.progress-track {
    height: 0.6rem;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
    margin: 0.4rem 0 0.75rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
}

.row-failed {
    background: #fff1f1;
}

.content-block {
    border-top: 1px solid var(--border);
    padding: 0.75rem 0;
}

.pre-wrap {
    white-space: pre-wrap;
}

.question-list {
    padding-right: 1.2rem;
}

.question-item {
    margin-bottom: 1rem;
}

.question-item pre {
    white-space: pre-wrap;
    background: #fafafa;
    padding: 0.5rem;
    border: 1px solid var(--border);
}

.lookup-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.lookup-list li {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.subject-icon {
    width: 1.5rem;
    height: 1.5rem;
    object-fit: contain;
    vertical-align: middle;
    margin-left: 0.35rem;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    left: 0.75rem;
    top: 0.5rem;
}

/* Teacher pages */
.attention-band {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.attention-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    color: inherit;
    text-align: center;
}

.attention-card-active {
    outline: 2px solid var(--primary);
}

.attention-card-danger .attention-count {
    color: var(--danger);
}

.attention-count {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.attention-label {
    font-size: 0.9rem;
    color: var(--muted);
}

.attention-filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 1rem;
}

.stuck-lessons-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stuck-lessons-list p {
    margin: 0;
}

.stuck-lesson-book {
    font-size: 0.9rem;
    margin-top: 0.15rem;
}

.join-code-display {
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    color: var(--primary);
    margin: 0.5rem 0 0.75rem;
    user-select: all;
}

.join-code-closed {
    font-weight: 600;
    margin: 0.5rem 0 0.75rem;
}

.join-code-hint {
    margin: 0.75rem 0 0.5rem;
}

.auto-approve-toggle {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    cursor: pointer;
}

.auto-approve-toggle input {
    width: auto;
    margin: 0;
}

.saved-indicator {
    font-size: 0.85rem;
    margin-right: 0.5rem;
}

.roster-search {
    margin-bottom: 0.75rem;
    max-width: 20rem;
}

.never-started {
    color: var(--danger);
}

.num-cell {
    text-align: left;
}

.pupil-headline {
    font-size: 15px;
    margin: 0 0 1rem;
    line-height: 1.7;
}

.activity-strip-wrap {
    margin-bottom: 1rem;
}

.activity-strip {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 3rem;
}

.activity-bar {
    flex: 1;
    min-width: 4px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
    min-height: 4px;
}

.activity-bar-zero {
    background: #e5e7eb;
    height: 4px;
}

.activity-strip-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.35rem;
    font-size: 0.85rem;
}

.next-step-panel {
    border-inline-start: 4px solid var(--primary);
    border-radius: 0;
}

.pupil-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.pupil-card h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.pupil-card-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.score-ok {
    color: var(--ok);
}

.score-warn {
    color: var(--warn);
}

.pupil-points {
    font-size: 0.9rem;
    margin: 0;
}

@media (max-width: 700px) {
    .teacher-table thead {
        display: none;
    }

    .teacher-table,
    .teacher-table tbody,
    .teacher-table tr,
    .teacher-table td {
        display: block;
        width: 100%;
    }

    .teacher-table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 6px;
        margin-bottom: 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    .teacher-table td {
        border: none;
        padding: 0.35rem 0;
        text-align: right;
    }

    .teacher-table td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: 0.85rem;
        color: var(--muted);
        margin-bottom: 0.15rem;
    }

    .teacher-table td:last-child {
        padding-top: 0.5rem;
    }

    .teacher-table td:last-child::before {
        display: none;
    }

    .teacher-table .num-cell {
        text-align: right;
    }
}
