@font-face {
    font-family: "Kantumruy Pro";
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/kantumruy-pro-khmer-400-normal.woff2") format("woff2");
    unicode-range: U+1780-17FF, U+19E0-19FF, U+200C-200D, U+25CC;
}
@font-face {
    font-family: "Kantumruy Pro";
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/kantumruy-pro-khmer-600-normal.woff2") format("woff2");
    unicode-range: U+1780-17FF, U+19E0-19FF, U+200C-200D, U+25CC;
}
@font-face {
    font-family: "Kantumruy Pro";
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/kantumruy-pro-latin-400-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Kantumruy Pro";
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/kantumruy-pro-latin-600-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning-bg: #fef3c7;
    --warning-text: #92400e;
    --radius: 12px;
}

* { box-sizing: border-box; }
/* The hidden attribute always wins over display rules such as .btn or .voice-panel (JS toggles it). */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Kantumruy Pro", "Noto Sans Khmer", "Khmer OS", sans-serif;
    font-size: 17px;
    line-height: 1.7;
}

a { color: var(--primary); }

main {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

h1 { font-size: 1.4rem; margin: 8px 0 16px; }
h1.center { text-align: center; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }

/* Top bar and navigation */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 1.2rem; text-decoration: none; }
.topbar .brand img { display: block; border-radius: 9px; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.topbar form { margin: 0; }
.topbar { gap: 12px; }
.topbar .brand { flex: none; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45vw; font-size: .95rem; }
.who form { flex: none; }
.link-button {
    background: none; border: 0; padding: 4px 0; cursor: pointer;
    color: #fff; font: inherit; text-decoration: underline;
}

.tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.tabs a {
    flex: none;
    padding: 6px 14px;
    border-radius: 999px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.tabs a.active { background: var(--primary); color: #fff; }
.tab-icon { margin-right: 5px; }

.badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: .7rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    vertical-align: middle;
}

/* Cards and lists */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }

.info-list { margin: 0; }
.info-list div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}
.info-list div:last-child { border-bottom: 0; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.list-item {
    display: block;
    color: inherit;
    text-decoration: none;
}
.list-item .title { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: .92rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { text-align: center; }
.stat .number { font-size: 1.8rem; font-weight: 600; color: var(--primary); }
.stat .label { color: var(--muted); }

.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* Forms */
label { display: block; margin: 14px 0 4px; font-weight: 600; }
label:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: .9rem; font-weight: 400; }

input[type=text], input[type=tel], input[type=password], input[type=number], input[type=time], input[type=date], input[type=search], select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 76px; }
.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 10px;
    border: 0;
    background: none;
    color: var(--primary);
    font: inherit;
    font-size: .9rem;
    cursor: pointer;
}

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label {
    display: flex; align-items: center; gap: 6px; margin: 0;
    padding: 6px 12px; border: 1px solid #cbd5e1; border-radius: 999px;
    font-weight: 400;
}
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.btn {
    display: inline-block;
    padding: 10px 18px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn-block { display: block; width: 100%; margin-top: 20px; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-light { background: #e5e7eb; color: var(--text); }
.btn-light:hover { background: #d1d5db; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions form { margin: 0; }

/* Messages */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }

.status { display: inline-block; padding: 0 10px; border-radius: 999px; font-size: .85rem; }
.status-active { background: #dcfce7; color: #166534; }
.status-inactive { background: #e5e7eb; color: #4b5563; }
.status-pending { background: var(--warning-bg); color: var(--warning-text); }

.status-overdue { background: #fee2e2; color: #991b1b; }

/* Payments */
.reminder { font-size: 1.05rem; border-left: 5px solid #f59e0b; }
.month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.month-nav .btn { padding: 6px 16px; font-size: 1.2rem; }
.pay-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pay-row form { margin: 0; flex: none; }
.pay-row .btn { flex: none; padding: 8px 12px; }
.stat .number { overflow-wrap: anywhere; }

/* Discussion */
.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    vertical-align: middle;
}
.teacher-badge {
    display: inline-block;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: .8rem;
}
.thread.unread { border-left: 4px solid var(--danger); }
.private-note { color: #92400e; background: #fef3c7; border-radius: 8px; padding: 6px 10px; font-size: .92rem; margin: 0 0 10px; }
.move-form { padding-top: 12px; padding-bottom: 12px; }
.move-form .row { align-items: center; }
.move-form .btn { flex: none; }
.post-form select { margin-top: 0; }
.card > .list-item.thread { display: block; padding: 10px 0; border-bottom: 1px solid #e5e7eb; text-decoration: none; color: inherit; }
.card > .list-item.thread.unread { padding-left: 10px; }
.card > details { margin-top: 12px; }
.post-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }
.post-body.snippet { color: var(--text); }
.post-image { display: block; max-width: 100%; max-height: 480px; margin-top: 8px; border-radius: 8px; }
.reply.from-teacher { border-color: #93c5fd; background: #eff6ff; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: 0 !important; }
.delete-form { margin: 0; }
.link-danger { background: none; border: 0; padding: 0; color: var(--danger); font: inherit; font-size: .9rem; cursor: pointer; }

details.card > summary { list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details[open].card > summary { margin-bottom: 14px; }

textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font: inherit;
    resize: vertical;
}
.math-preview {
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.math-panel { margin-top: 10px; padding: 12px; border: 1px solid #93c5fd; border-radius: 10px; background: #eff6ff; }
math-field { display: block; width: 100%; padding: 8px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; font-size: 1.3rem; }
.image-previews { display: flex; flex-wrap: wrap; gap: 8px; }
.image-preview { display: block; max-width: 120px; max-height: 120px; margin-top: 10px; border-radius: 8px; }
.form-note { margin: 10px 0 0; }

/* Private conversations (សួរគ្រូ chat and homework): own messages on the right. */
.conversation { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 14px; background: #fff; border: 1px solid #e5e7eb; }
.bubble.mine { align-self: flex-end; background: #dbeafe; border-color: #bfdbfe; }
.bubble.theirs { align-self: flex-start; }
.bubble.theirs.from-teacher { background: #eff6ff; border-color: #93c5fd; }
.bubble-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .85rem; }
.bubble-meta .delete-form { margin-left: auto; }
.bubble .post-body { margin: 4px 0 0; }
.bubble .post-image { max-height: 320px; }
.unread-dot-row { display: flex; align-items: center; gap: 6px; }

/* Voice messages and read receipts */
.voice { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.voice-label { font-size: .9rem; color: var(--muted); }
.voice audio { height: 36px; max-width: 100%; flex: 1; min-width: 180px; }
.voice-panel { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding: 10px; border-radius: 10px; background: #fef2f2; }
.voice-panel audio { height: 36px; flex: 1; min-width: 180px; }
.voice-status { font-weight: 600; }
/* Not read yet is what needs attention: dark and bold. Read: light grey. */
.receipt { color: var(--text); font-weight: 700; font-size: .85rem; letter-spacing: -2px; }
.receipt.read { color: #9ca3af; font-weight: 400; }
.seen-line { text-align: right; color: var(--text); font-weight: 700; font-size: .85rem; margin: -6px 4px 12px; }
.seen-line.read { color: #9ca3af; font-weight: 400; }
.post-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.post-tools button[type=submit] { margin-left: auto; }
.file-button { margin: 0; font-weight: 600; }

/* Live notifications for the teacher (assets/js/notify.js) */
.toasts {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.toast {
    width: 100%;
    max-width: 480px;
    padding: 12px 16px;
    border-radius: 12px;
    background: #1f2937;
    color: #fff;
    text-decoration: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    pointer-events: auto;
    animation: toast-in .3s ease-out;
    transition: opacity .5s;
}
.toast.hide { opacity: 0; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }

/* Login / register pages */
.qr-box { text-align: center; margin-top: 16px; padding-top: 16px; border-top: 1px solid #e5e7eb; }
.qr { display: block; width: 170px; height: auto; margin: 0 auto; border-radius: 12px; }

.install-banner { display: flex; align-items: center; gap: 10px; background: #eff6ff; border: 1px solid #93c5fd; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.install-banner span { flex: 1; }
.install-banner .btn { flex: none; padding: 8px 14px; }
.install-close { flex: none; background: none; border: 0; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }

h3 { font-size: 1.05rem; margin: 18px 0 8px; color: var(--muted); }
.text-danger { color: var(--danger); }
.homework-row.todo { border-left: 4px solid #f59e0b; }
.homework-reminder { display: block; color: inherit; text-decoration: none; }
.meta.feedback { color: var(--primary); font-weight: 600; }
.link-like { color: var(--primary); }
.hw-student .list-item { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.student-nav { justify-content: space-between; }
/* សារសិស្ស inbox: one row per conversation, like a chat app. */
.inbox { background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); margin-bottom: 12px; }
.chat-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid #f1f5f9; color: inherit; text-decoration: none; }
.chat-row:last-child { border-bottom: 0; }
.chat-row.unread { background: #eff6ff; }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 1.15rem; color: #fff; background: hsl(var(--hue, 220), 55%, 52%); }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-group { font-weight: 400; font-size: .8rem; color: var(--muted); }
.chat-last { color: var(--muted); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row.unread .chat-last { color: var(--text); font-weight: 600; }
.chat-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: .8rem; color: var(--muted); }
.student-row { display: flex; align-items: center; gap: 10px; }
.student-row .list-item { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.message-button { flex: none; padding: 8px 12px; font-size: .92rem; white-space: nowrap; }
.search-form { display: flex; gap: 8px; margin-bottom: 10px; }
.search-form input { flex: 1; min-width: 0; }
.search-form .btn { flex: none; }
.filter-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.filter-tabs a { padding: 4px 12px; border-radius: 999px; background: #e5e7eb; color: var(--text); text-decoration: none; font-size: .92rem; }
.filter-tabs a.active { background: var(--primary); color: #fff; }
.filter-tabs .badge { font-size: .75rem; }
.hw-photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hw-photo { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hw-photo form { margin: 0; }
.hw-thumb { display: block; width: 88px; height: 88px; object-fit: cover; border-radius: 8px; border: 1px solid #e5e7eb; background: #f3f4f6; }
.hw-student { padding-top: 12px; padding-bottom: 12px; }
.hw-form { margin-top: 12px; }
.hw-form .file-button { text-align: center; }
.current-image { display: block; max-width: 160px; max-height: 160px; margin: 6px 0; border-radius: 8px; }
.group-kind-label { margin: 8px 0 4px; }
.kind-badge { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: .8rem; background: #e0e7ff; color: #3730a3; }
.kind-badge.school { background: #dcfce7; color: #166534; }
.approve-form { display: flex; gap: 8px; flex: 1; min-width: 0; }
.approve-form select { flex: 1; min-width: 0; margin: 0; }
.approve-form .btn { flex: none; }

.auth { max-width: 420px; margin: 24px auto; }
.auth .switch { text-align: center; margin-top: 16px; }
