:root {
    --ink: #1c2834;
    --muted: #5c6b7a;
    --line: #d5dde6;
    --paper: #f3f6f8;
    --card: #ffffff;
    --navy: #16324f;
    --navy-2: #21486f;
    --accent: #0f6e56;
    --danger: #9d2c2c;
    --warn: #8a5a00;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
    font-size: 16px;
    line-height: 1.45;
}

a { color: var(--navy-2); }

.topbar {
    background: var(--navy);
    color: #fff;
    padding: 12px 16px;
}

.topbar-row, .nav-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.brand {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex: 0 0 auto;
    background: transparent;
}

.brand-name { line-height: 1.2; }

.account-menu { position: relative; }
.account-menu summary {
    list-style: none;
    cursor: pointer;
    color: #d5e4f2;
    font-size: .95rem;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary::after {
    content: "";
    display: inline-block;
    margin-left: 6px;
    border: 4px solid transparent;
    border-top-color: #d5e4f2;
    vertical-align: 2px;
}
.account-menu .menu-list {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 40;
    min-width: 190px;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(22, 50, 79, .16);
}
.account-menu .menu-list a,
.account-menu .menu-list button.linkish {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--ink);
    border: 0;
    border-radius: 6px;
    padding: 8px 10px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}
.account-menu .menu-list a:hover,
.account-menu .menu-list button.linkish:hover { background: var(--paper); }
.account-menu form { margin: 0; }

.nav-row { margin-top: 10px; }

.nav-row > a, .nav-row summary {
    color: #e7eef6;
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 6px;
}

.nav-row > a:hover, .nav-row > a.active, .nav-row summary:hover, .nav-row summary.active { background: var(--navy-2); }

.nav-row details.menu { position: relative; }

.nav-row summary {
    list-style: none;
    cursor: pointer;
}

.nav-row summary::-webkit-details-marker { display: none; }

.nav-row summary::after {
    content: "";
    display: inline-block;
    margin-left: 6px;
    border: 4px solid transparent;
    border-top-color: #e7eef6;
    vertical-align: 2px;
}

.nav-row .menu-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 30;
    min-width: 190px;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(22, 50, 79, .16);
}

.nav-row details.menu:last-child .menu-list { left: auto; right: 0; }

.nav-row .menu-list a {
    display: block;
    color: var(--ink);
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 6px;
}

.nav-row .menu-list a:hover, .nav-row .menu-list a.active { background: var(--paper); }

.topbar button.linkish {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 6px;
    padding: 6px 10px;
    font: inherit;
    cursor: pointer;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }

h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.muted { color: var(--muted); }
.lead { margin-top: 0; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.card, .panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
}

.card strong { display: block; font-size: 1.4rem; }
.card span { color: var(--muted); font-size: .9rem; }

.alert {
    background: #e7f6ef;
    border: 1px solid #b7e0cc;
    color: #145c40;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
}

.errors {
    background: #fdecec;
    border: 1px solid #f0c2c2;
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
}

label { display: block; font-weight: 600; margin: 12px 0 4px; }

input, select, textarea {
    width: 100%;
    max-width: 420px;
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

textarea { max-width: 640px; min-height: 80px; }

.inline input, .inline select { max-width: 180px; }

button, .button {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

button.secondary, .button.secondary { background: var(--navy); }
button.danger, .button.danger { background: var(--danger); }
button.quiet, .button.quiet { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); background: #f8fafb; }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label { margin: 0 0 4px; }
.filters input, .filters select { max-width: 240px; }

.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: #e7eef6; font-size: .85rem; }
.tag.left { background: #fdecec; color: var(--danger); }
.tag.current { background: #e7f6ef; color: #145c40; }

.login-card { max-width: 420px; margin: 48px auto; }

.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-form input { max-width: 160px; }
.row-form select { width: auto; max-width: 240px; }

input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    max-width: none;
    padding: 0;
    vertical-align: middle;
}

.tick {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    margin: 10px 0 0;
}

.tick-row { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 6px; }
.tick-row .tick { margin: 0; font-weight: 500; }

details.access {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 8px;
}

details.access summary { cursor: pointer; padding: 10px 12px; font-weight: 600; }
details.access .inside { padding: 0 12px 12px; }

.subject-line { padding: 8px 0; border-top: 1px solid var(--line); }
.subject-line strong { display: block; }

.module-line {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    margin: 8px 0;
}

.module-line label { margin: 0; min-width: 170px; }
.module-line select { width: auto; max-width: 180px; }

.wrap-wide { max-width: none; }
.class-grid { min-width: 980px; }
.class-grid input { max-width: none; width: 100%; padding: 6px 8px; }
.class-grid td { min-width: 120px; }
.class-grid .row-actions { min-width: 180px; white-space: nowrap; }
.class-grid .row-actions button { padding: 6px 8px; margin-right: 4px; }

textarea.syllabus {
    width: 100%;
    max-width: 720px;
    min-height: 150px;
}
.syllabus-date {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
}

.timetable-grid td { min-width: 108px; }
.paper + .paper { margin-top: 8px; }
.paper strong, .paper span { display: block; }
.slot-table input { max-width: 170px; }

.seating-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.seating-grid select { max-width: 150px; color: var(--ink); background: #fff; }
.seating-grid input[type="number"] { max-width: 90px; }
.seating-grid a { display: inline-block; margin-top: 4px; font-size: .9rem; }

.duty-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.duty-grid input[type="text"],
.duty-grid select {
    max-width: 200px;
    min-width: 150px;
    color: var(--ink);
    background: #fff;
}

@media (max-width: 700px) {
    textarea.syllabus { max-width: none; font-size: 1.05rem; }
}

.mark-status {
    background: #fdecec;
    border: 1px solid #f0c2c2;
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 8px;
    margin: 0 0 12px;
}

.component-tabs, .phone-only { display: none; }

.example-list { margin: 8px 0 0; padding-left: 1.2rem; }
.formula-add { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.formula-add h3 { font-size: 1rem; margin: 0 0 6px; }
.formula-edit { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 8px 0; }
.formula-edit label { display: flex; gap: 8px; align-items: center; flex: 1; }
.formula-edit input { flex: 1; min-width: 220px; max-width: none; font-family: Consolas, "Courier New", monospace; }
.col-tag { min-width: 3.4rem; text-align: center; }
.col-formula { display: block; font-weight: 400; color: var(--muted, #5c6b7a); font-size: 0.85rem; }
.mark-calculated { display: inline-block; min-width: 72px; text-align: center; font-weight: 700; padding: 8px 4px; }
.mark-entry { display: flex; gap: 4px; align-items: center; }
.mark-input {
    width: 72px;
    max-width: 72px;
    text-align: center;
    padding: 8px 4px;
}
.mark-input.is-error { border-color: var(--danger); background: #fff6f6; }
.mark-input.is-saved { border-color: var(--accent); }
.mark-input:disabled { background: #f3f6f8; color: var(--muted); }
.absent-btn {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 8px 10px;
}
tr.is-left { background: #fbfcfd; }
.mark-who { white-space: nowrap; }

@media (max-width: 700px) {
    .brand { width: 100%; }
    h1 { font-size: 1.35rem; }
    .component-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
    .phone-only { display: block; }
    .component-tabs .tab { background: #fff; color: var(--ink); border: 1px solid var(--line); }
    .component-tabs .tab.is-on { background: var(--navy); color: #fff; }
    .mark-grid thead { display: none; }
    .mark-grid table, .mark-grid tbody, .mark-grid tr, .mark-grid td { display: block; width: auto; }
    .mark-grid tr {
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 10px;
        margin-bottom: 10px;
        padding: 12px;
    }
    .mark-grid .mark-col { display: none; }
    .mark-grid .mark-col.is-active { display: block; }
    .mark-grid .desk-only { display: none !important; }
    .mark-who { white-space: normal; font-size: 1.05rem; margin-bottom: 8px; }
    .mark-entry { gap: 8px; }
    .mark-input {
        width: 100%;
        max-width: none;
        font-size: 1.35rem;
        padding: 14px;
        text-align: left;
    }
    .mark-calculated {
        display: block;
        font-size: 1.35rem;
        padding: 14px;
        text-align: left;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 8px;
    }
    .absent-btn { padding: 14px 16px; font-size: 1.05rem; }
    .formula-edit label { flex-wrap: wrap; width: 100%; }
    .formula-edit input { min-width: 0; width: 100%; font-size: 1.05rem; }

    .seating-scroll { overflow: visible; border: 0; }
    .seating-grid thead { display: none; }
    .seating-grid,
    .seating-grid tbody,
    .seating-grid tr,
    .seating-grid td { display: block; width: 100%; }
    .seating-grid tr {
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 12px;
    }
    .seating-grid td { border: 0; padding: 8px 0; }
    .seating-grid td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        margin-bottom: 4px;
    }
    .seating-grid select,
    .seating-grid input[type="number"] {
        width: 100%;
        max-width: none;
        min-height: 48px;
        font-size: 1.05rem;
    }
    .seating-grid td[data-label="Remove"] input[type="checkbox"] {
        width: 1.25rem;
        height: 1.25rem;
    }
    .seating-add .row-form { display: block; }
    .seating-add .row-form select,
    .seating-add .row-form input {
        display: block;
        width: 100%;
        max-width: none;
        min-height: 48px;
        margin-bottom: 8px;
    }

    .duty-scroll { overflow: visible; border: 0; }
    .duty-grid thead { display: none; }
    .duty-grid,
    .duty-grid tbody,
    .duty-grid tr,
    .duty-grid td { display: block; width: 100%; }
    .duty-grid tr {
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 12px;
    }
    .duty-grid td { border: 0; padding: 8px 0; }
    .duty-grid td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        margin-bottom: 4px;
    }
    .duty-grid input[type="text"],
    .duty-grid select {
        width: 100%;
        max-width: none;
        min-width: 0;
        min-height: 48px;
        font-size: 1.05rem;
    }
}
