:root {
    --bg: #f5f7f4;
    --panel: #ffffff;
    --panel-alt: #eef3ec;
    --border: #d7ddd2;
    --text: #1e2a22;
    --muted: #59665d;
    --accent: #166534;
    --accent-soft: #e4f3e8;
    --danger: #b42318;
    --danger-soft: #fee4e2;
    --warning: #b54708;
    --warning-soft: #ffead5;
    --shadow: 0 8px 30px rgba(26, 41, 32, 0.06);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

body {
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(200px, 1.2fr) minmax(0, 2fr) auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #1f3623;
    color: #fff;
}

.brand-link {
    display: inline-flex;
    gap: 0.85rem;
    align-items: center;
    min-width: 0;
}

.brand-link strong,
.brand-link small {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-link small {
    color: #d6e3d7;
    font-size: 0.8rem;
}

.brand-badge {
    width: 2.7rem;
    height: 2.7rem;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: #a7f3d0;
    color: #14532d;
    font-weight: 700;
}

.topbar__status,
.topbar__user {
    justify-self: end;
}

.status-pill,
.user-chip,
.badge,
.inline-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 0.875rem;
}

.status-pill--open {
    background: #0d9488;
}

.status-pill--closed {
    background: #475467;
}

.menu-bar {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.menu-bar::-webkit-scrollbar {
    display: none; /* Safari and Chrome */
}

.menu-bar a {
    padding: 0.7rem 0.95rem;
    border-radius: var(--radius) var(--radius) 0 0;
    background: #dce5d9;
    color: #203329;
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
}

.menu-bar a.is-active {
    background: var(--panel);
    box-shadow: var(--shadow);
}

.menu-bar--student a {
    border-radius: var(--radius);
}

.page {
    padding: 1.5rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.page-header h1,
.page-header h2,
.section-heading {
    margin: 0;
}

.page-header p,
.section-note,
.muted {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.stats-grid,
.cards-grid,
.split-grid,
.report-grid,
.question-grid {
    display: grid;
    gap: 1rem;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.split-grid {
    grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
}

.cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.report-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.question-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.panel,
.metric-card,
.list-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    padding: 1.2rem;
    margin-bottom: 1rem;
}

.metric-card {
    padding: 1rem;
}

.metric-card span {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
}

.metric-card strong {
    display: block;
    margin-top: 0.3rem;
    font-size: 1.7rem;
}

.stack {
    display: grid;
    gap: 1rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

.toolbar--end {
    justify-content: flex-end;
}

.toolbar form,
.inline-form {
    display: inline-flex;
    gap: 0.65rem;
    align-items: center;
    flex-wrap: wrap;
    max-width: 100%;
}

.toolbar form select,
.toolbar form input,
.inline-form select,
.inline-form input {
    flex: 1 1 120px;
    min-width: 0;
}

.toolbar form button,
.inline-form button {
    flex: 0 0 auto;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.92rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 0.72rem 0.78rem;
    border-radius: var(--radius);
    border: 1px solid #bfc9bc;
    background: #fff;
    color: var(--text);
    font: inherit;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.button,
button,
input[type="submit"] {
    border: 0;
    border-radius: var(--radius);
    padding: 0.74rem 0.95rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
}

.button--secondary {
    background: #344e41;
}

.button--ghost {
    background: #e2e8e0;
    color: #203329;
}

.button--danger {
    background: var(--danger);
}

.button--warning {
    background: var(--warning);
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
}

.alert {
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert--success {
    background: var(--accent-soft);
    border-color: #afd9bb;
    color: #0f5132;
}

.alert--error {
    background: var(--danger-soft);
    border-color: #f0b5b0;
    color: #7a271a;
}

.alert--warning {
    background: var(--warning-soft);
    border-color: #f3c38a;
    color: #8a3b04;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th,
td {
    padding: 0.8rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    font-size: 0.88rem;
    color: var(--muted);
    background: var(--panel-alt);
}

tbody tr:hover {
    background: #f8fbf7;
}

.score-scale {
    display: grid;
    gap: 0.45rem;
}

.score-options {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.65rem;
}

.score-option {
    position: relative;
}

.score-option input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.score-option span {
    display: grid;
    gap: 0.25rem;
    padding: 0.75rem 0.45rem;
    text-align: center;
    border: 1px solid #bfc9bc;
    border-radius: var(--radius);
    background: #fff;
    min-height: 72px;
    align-content: center;
}

.score-option strong {
    font-size: 1.1rem;
}

.score-option input:checked + span {
    border-color: #166534;
    background: var(--accent-soft);
    box-shadow: 0 0 0 1px rgba(22, 101, 52, 0.15);
}

.detail-list,
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.badge,
.inline-badge {
    color: #203329;
    background: #e2ece1;
}

.badge--danger {
    background: var(--danger-soft);
    color: #912018;
}

.badge--success {
    background: var(--accent-soft);
    color: #166534;
}

.badge--warning {
    background: var(--warning-soft);
    color: #9a3412;
}

.empty-state {
    padding: 1.2rem;
    border: 1px dashed #bac7bc;
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.55);
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.login-card {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.9fr);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.login-card__intro {
    padding: 2rem;
    background: linear-gradient(135deg, #1f3623, #2b4c2f);
    color: #fff;
}

.login-card__form {
    padding: 2rem;
}

.hero-actions,
.subtle-list {
    display: grid;
    gap: 0.75rem;
}

.subtle-list {
    padding-left: 1rem;
}

.subtle-list li {
    color: #e5efe6;
}

.rank {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: #203329;
    color: #fff;
    font-weight: 700;
}

.comment-item,
.group-card {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.group-card h3,
.comment-item h4 {
    margin-top: 0;
    margin-bottom: 0.4rem;
}

.flex {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.justify-between {
    justify-content: space-between;
}

.mini-stat {
    font-size: 0.92rem;
    color: var(--muted);
}

.section-divider {
    border-top: 1px solid var(--border);
    margin: 1rem 0;
    padding-top: 1rem;
}

@media (max-width: 960px) {
    .topbar {
        grid-template-columns: 1fr auto;
    }
    
    .topbar__status {
        grid-column: 1 / -1;
        justify-self: start;
    }
    
    .topbar__user {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
    }

    .login-card,
    .split-grid,
    .report-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .page,
    .topbar,
    .menu-bar {
        padding: 1rem;
    }
    
    .menu-bar {
        padding-top: 0.5rem;
        padding-bottom: 0;
    }

    .page-header {
        flex-direction: column;
    }

    .score-options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* removed table min-width to ensure horizontal scrolling inside table-wrap */
}

@media (max-width: 480px) {
    .score-options {
        grid-template-columns: 1fr;
    }
}
