:root {
    --bg: #f4f8fb;
    --surface: #ffffff;
    --border: #e3eaf1;
    --text: #2b323a;
    --muted: #757e89;
    --accent: #0277bd;
    --accent-hover: #01579b;
    --accent-soft: #e1f5fe;
    --heading: #34485b;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.landing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 24px;
}

.landing h1 {
    margin: 0 0 8px;
    font-size: 32px;
    letter-spacing: -0.02em;
    color: var(--heading);
}

.landing p {
    margin: 0 0 24px;
    color: var(--muted);
    max-width: 420px;
}

.button {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(43, 50, 58, 0.18);
}

.button:hover {
    background: var(--accent-hover);
    text-decoration: none;
}

.button.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.button.secondary:hover {
    background: var(--bg);
}

.landing .actions {
    display: flex;
    gap: 10px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(43, 50, 58, 0.08);
    position: sticky;
    top: 0;
    z-index: 1;
}

.topbar .left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar .brand {
    font-weight: 600;
    color: var(--accent);
}

.nav-toggle {
    display: none;
}

.hamburger {
    display: none;
    -webkit-tap-highlight-color: transparent;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 30px;
    height: 30px;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
}

.hamburger:hover {
    background: var(--accent-soft);
}

.hamburger span {
    display: block;
    height: 2px;
    border-radius: 1px;
    background: var(--accent);
}

.scrim {
    display: none;
    cursor: pointer;
}

.topbar .user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar .user .name {
    color: var(--muted);
    max-width: 40vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar .user .logout {
    padding: 6px 14px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(43, 50, 58, 0.18);
}

.topbar .user .logout:hover {
    background: var(--accent-hover);
    text-decoration: none;
}

.layout {
    display: flex;
    align-items: stretch;
    min-height: calc(100vh - 48px);
}

.sidebar {
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar nav a {
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--text);
}

.sidebar nav a:hover {
    background: var(--bg);
    text-decoration: none;
}

.sidebar nav a.active {
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-weight: 500;
}

.build-info {
    margin-top: auto;
    padding: 7px 10px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}

.content {
    flex: 1;
    /* Flex items won't shrink below their content by default; without
       this a wide table widens the page instead of scrolling itself. */
    min-width: 0;
    padding: 24px;
}

.content h1 {
    margin: 0 0 16px;
    font-size: 20px;
    color: var(--heading);
}

.banner {
    margin: 0 0 16px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    max-width: 640px;
}

.banner[hidden] {
    display: none;
}

.banner-error {
    background: #fdecea;
    border: 1px solid #f5c6c0;
    color: #a12b1f;
}

.banner-warn {
    background: #fff3e0;
    border: 1px solid #ffcc80;
    color: #bf4300;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    vertical-align: middle;
}

.status-online {
    background: #2e7d32;
}

.status-offline {
    background: #c62828;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    max-width: 640px;
    box-shadow: 0 1px 3px rgba(43, 50, 58, 0.08);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--accent-soft);
    color: #556370;
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

tbody tr:last-child td {
    border-bottom: none;
}

td.toggle {
    width: 70px;
    text-align: center;
}

td.toggle input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    width: 36px;
    height: 20px;
    margin: 0;
    border: none;
    border-radius: 999px;
    background: #e2e5ec;
    cursor: pointer;
    vertical-align: middle;
    transition: background 0.18s ease;
}

td.toggle input[type="checkbox"]::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(43, 50, 58, 0.3);
    transition: transform 0.18s ease;
}

td.toggle input[type="checkbox"]:checked {
    background: var(--accent);
}

td.toggle input[type="checkbox"]:checked::after {
    transform: translateX(16px);
}

td.toggle input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .hamburger {
        display: flex;
    }

    .topbar {
        padding: 0 12px;
    }

    .sidebar {
        position: fixed;
        top: 48px;
        left: 0;
        bottom: 0;
        width: 210px;
        flex: none;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 1px 6px rgba(43, 50, 58, 0.2);
        z-index: 3;
    }

    .nav-toggle:checked~.layout .sidebar {
        transform: translateX(0);
    }

    .nav-toggle:checked~.layout .scrim {
        display: block;
        position: fixed;
        top: 48px;
        right: 0;
        bottom: 0;
        left: 0;
        background: rgba(43, 50, 58, 0.35);
        z-index: 2;
    }

    .content {
        padding: 16px;
    }

    th,
    td {
        padding: 9px 12px;
    }

    td.toggle {
        width: 58px;
    }
}

td .desc {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 480px) {
    .col-ip {
        display: none;
    }
}
/* ---------- Ventilation dashboard ---------- */

.content h2 {
    margin: 0 0 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--heading);
}

.section {
    max-width: 960px;
    margin: 0 0 28px;
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.section-head a {
    font-size: 13px;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border);
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 14px 16px;
    background: var(--surface);
}

.metric-label {
    color: var(--muted);
    font-size: 12px;
}

.metric-value {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--heading);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.metric-value .unit {
    margin-left: 3px;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
}

.metric-sub {
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.metric-sub .na {
    color: #a7afb8;
}

/* Ventilation level meter */
.level {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 31px;
    padding: 4px 0 1px;
}

.level span {
    flex: 0 0 7px;
    border-radius: 2px;
    background: #e2e5ec;
}

.level span.on {
    background: var(--accent);
}

.level span:nth-child(1)  { height: 20%; }
.level span:nth-child(2)  { height: 28%; }
.level span:nth-child(3)  { height: 36%; }
.level span:nth-child(4)  { height: 44%; }
.level span:nth-child(5)  { height: 52%; }
.level span:nth-child(6)  { height: 60%; }
.level span:nth-child(7)  { height: 68%; }
.level span:nth-child(8)  { height: 76%; }
.level span:nth-child(9)  { height: 88%; }
.level span:nth-child(10) { height: 100%; }

/* Filter clogging bar */
.meter {
    height: 6px;
    margin: 4px 0 2px;
    border-radius: 999px;
    background: #e2e5ec;
    overflow: hidden;
}

.meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.metric.is-warn .meter span {
    background: #e65100;
}

.metric.is-warn .metric-value {
    color: #bf4300;
}

/* Day / Month / Total breakdown */
.breakdown {
    display: grid;
    grid-template-columns: auto 1fr;
    margin: 4px 0 0;
    font-variant-numeric: tabular-nums;
}

.breakdown dt,
.breakdown dd {
    margin: 0;
    padding: 4px 0;
    border-top: 1px solid var(--border);
}

.breakdown dt:first-of-type,
.breakdown dt:first-of-type + dd {
    border-top: none;
}

.breakdown dt {
    color: var(--muted);
    font-size: 12px;
    line-height: 22px;
}

.breakdown dd {
    text-align: right;
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
    color: var(--heading);
    white-space: nowrap;
}

.breakdown dd .unit {
    margin-left: 3px;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

@media (max-width: 900px) {
    .metrics {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .metric {
        padding: 12px;
    }

    .metric-value {
        font-size: 21px;
    }
}

/* ---------- Cameras ---------- */

.cameras {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    max-width: 1400px;
}

.card.camera {
    max-width: none;
}

.camera-head {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--accent-soft);
    color: #556370;
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.camera-feed {
    aspect-ratio: 16 / 9;
    background: #000;
}

.camera-feed video-stream {
    display: block;
    width: 100%;
    height: 100%;
}

.camera-feed video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

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

/* ---------- Messages (TAMO, ELIIS) ---------- */

.card.messages-card {
    max-width: 960px;
}

.messages-list td {
    vertical-align: top;
}

/* The subject link stretches over its row, so the whole row opens the message. */
.messages-list tbody tr {
    position: relative;
    cursor: pointer;
}

.messages-list tbody tr:hover {
    background: var(--bg);
}

.messages-list a.row-link::after {
    content: "";
    position: absolute;
    inset: 0;
}

.messages-list a.row-link:focus-visible {
    outline: none;
}

.messages-list tbody tr:has(a.row-link:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.messages-list .sender {
    display: block;
}

.messages-list tr.unread .sender,
.messages-list tr.unread a {
    font-weight: 600;
}

.messages-list .col-date {
    width: 140px;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.messages-list .date-inline {
    display: none;
}

.tag {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    border-radius: 4px;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-size: 11px;
    font-weight: 500;
    line-height: 18px;
    vertical-align: 1px;
}

.tag-warn {
    background: #fff3e0;
    color: #bf4300;
}

.pager {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 960px;
    margin-top: 16px;
}

.pager-page {
    color: var(--muted);
}

.content .empty {
    color: var(--muted);
}

.message-nav {
    margin: 0 0 12px;
}

.message-head {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.message-head h1 {
    margin: 0 0 10px;
    font-size: 18px;
}

.message-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 16px;
    margin: 0;
}

.message-meta dt {
    color: var(--muted);
}

.message-meta dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.attachment {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.attachment::before {
    content: "";
    flex: none;
    width: 12px;
    height: 12px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.4 11.1l-9.2 9.2a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.4 11.1l-9.2 9.2a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5'/%3E%3C/svg%3E") center / contain no-repeat;
}

a.attachment:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    text-decoration: none;
}

span.attachment {
    color: var(--muted);
}

.message-body {
    padding: 16px;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

@media (max-width: 600px) {
    .messages-list .col-date {
        display: none;
    }

    .messages-list .date-inline {
        display: block;
    }
}

/* ---------- Sidebar unread badge ---------- */

.sidebar nav a:has(.nav-badge) {
    display: flex;
    align-items: center;
    gap: 8px;
    container-type: inline-size;
}

.sidebar nav .nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-badge {
    flex: none;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: #d32f2f;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Too narrow for the number: fall back to a plain dot. */
@container (max-width: 150px) {
    .nav-badge {
        min-width: 8px;
        height: 8px;
        padding: 0;
    }

    .nav-badge-count {
        display: none;
    }
}

/* ---------- TAMO grades ---------- */

.h1-sub {
    margin-left: 8px;
    font-weight: 400;
    color: var(--muted);
}

/* The card hugs the table, so wide screens don't stretch the cells. */
.card.grades-card {
    width: fit-content;
    max-width: 100%;
}

/* The day columns scroll sideways; the subject column stays put. */
.grades-scroll {
    overflow-x: auto;
}

table.grades {
    width: auto;
    font-variant-numeric: tabular-nums;
}

table.grades th,
table.grades td {
    padding: 6px 4px;
    text-align: center;
    white-space: nowrap;
}

table.grades .subject {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 160px;
    max-width: 220px;
    padding: 6px 12px;
    text-align: left;
    /* One line per subject, so rows keep their height; long names are cut
       with an ellipsis, the full name is in the title. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
}

table.grades thead .subject {
    background: var(--accent-soft);
}

table.grades tbody th.subject {
    font-weight: 500;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
}

/* Day columns are as wide as a row is tall, so cells come out square. */
table.grades th.day,
table.grades td {
    width: 38px;
    min-width: 38px;
    max-width: 38px;
}

table.grades th.day {
    padding: 6px 2px;
    line-height: 1.2;
}

table.grades tbody td {
    height: 38px;
    padding: 4px 2px;
}

table.grades .day-num {
    display: block;
    font-size: 13px;
    color: var(--heading);
}

table.grades .day-name {
    display: block;
    font-size: 10px;
    font-weight: 400;
    text-transform: none;
}

table.grades th.day.weekend {
    color: #a7afb8;
}

table.grades .today {
    background: #fff8e1;
}

table.grades thead th.day.today {
    background: #ffecb3;
}

table.grades tbody tr:hover td,
table.grades tbody tr:hover th.subject {
    background: var(--bg);
}

.grade-cell {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
}

.mark {
    display: inline-block;
    min-width: 26px;
    padding: 1px 5px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
}

.mark-high { background: #e8f5e9; color: #2e7d32; }
.mark-mid { background: #eef2f6; color: #34485b; }
.mark-low { background: #fff3e0; color: #bf6d00; }
.mark-poor { background: #fdecea; color: #c62828; }
.mark-passed { background: #e0f2f1; color: #00796b; }
.mark-attendance { background: #f3e5f5; color: #7b1fa2; font-weight: 500; }

.grade-cell:focus-visible .mark {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.grade-details {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    white-space: pre-line;
    font-size: 13px;
}

.grade-details[hidden] {
    display: none;
}

.grades-hint {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.grades-hint .mark {
    min-width: 0;
    font-size: 11px;
    line-height: 16px;
}

@media (max-width: 768px) {
    table.grades .subject {
        min-width: 110px;
        max-width: 140px;
        padding: 6px 8px;
    }
}

/* Social activity hours: a summary above the grades table. */
.card.social-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 420px;
    margin: 0 0 16px;
    padding: 14px 16px;
}

.social-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.social-card .metric-value {
    font-size: 20px;
}
