:root {
    --blue: #5b8def;
    --pink: #f45b8d;
    --gradient: linear-gradient(90deg, var(--blue) 0%, var(--pink) 100%);
    --bg: #f4f6fb;
    --card-bg: #ffffff;
    --text-dark: #2c2c3a;
    --text-muted: #7a7a8c;
    --green: #22c55e;
    --red: #ef4444;
    --radius: 16px;
    --shadow: 0 4px 16px rgba(30, 30, 60, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text-dark);
    -webkit-tap-highlight-color: transparent;
}

.app-header {
    background: var(--gradient);
    padding: 18px 16px 0 16px;
    border-radius: 0 0 24px 24px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 50;
}

.app-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #fff;
    text-align: center;
    padding-bottom: 14px;
}

.app-title h1 {
    font-size: 1.15rem;
    margin: 0;
    font-weight: 700;
}

.app-logo { font-size: 1.4rem; }

.tab-nav {
    display: flex;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    padding: 4px;
    margin: 0 auto 0 auto;
    max-width: 640px;
    gap: 4px;
    overflow-x: auto;
}

.tab-nav .tab {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    border-radius: 999px;
    color: #fff;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.tab-nav .tab.active {
    background: #fff;
    color: var(--pink);
}

.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 14px 60px 14px;
}

.app-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 20px 0 30px 0;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 1.05rem;
    margin: 0 0 12px 0;
}

.card h3 {
    font-size: 0.95rem;
    margin: 0 0 8px 0;
    color: var(--text-dark);
}

.dashboard-title-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.dashboard-title-row img.logo,
.dashboard-title-row .logo-fallback {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue), var(--pink));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.dashboard-title-row .title-text h2 {
    margin: 0;
    color: var(--pink);
    font-size: 1.1rem;
}

.dashboard-title-row .title-text p {
    margin: 2px 0 0 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.controls-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.date-picker {
    flex: 1;
    min-width: 150px;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid #e5e5f0;
    background: #fdeef2;
    color: var(--pink);
    font-weight: 600;
    font-size: 0.9rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 999px;
    border: none;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    text-decoration: none;
    justify-content: center;
}

.btn-primary { background: var(--blue); color: #fff; }
.btn-pink { background: var(--pink); color: #fff; }
.btn-outline { background: #fff; border: 1px solid #ddd; color: var(--text-dark); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.menu-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 640px) {
    .menu-grid { grid-template-columns: repeat(3, 1fr); }
}

.menu-card {
    background: linear-gradient(160deg, #eef4ff, #fdeef4);
    border-radius: 14px;
    padding: 14px;
}

.menu-card h4 {
    margin: 0 0 8px 0;
    font-size: 0.88rem;
    color: var(--text-dark);
}

.menu-card p {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.empty-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* ครูรายงาน: เลือกห้อง */
.room-select-btn {
    width: 100%;
    padding: 16px;
    border-radius: 14px;
    border: 2px dashed var(--blue);
    background: #f2f7ff;
    color: var(--blue);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: center;
}

.room-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 30, 0.55);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
}
.room-modal-backdrop.open { display: flex; }

.room-modal {
    background: #24242e;
    color: #fff;
    width: 100%;
    max-width: 480px;
    max-height: 78vh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    padding: 16px 0 24px 0;
}

.room-modal .modal-header {
    padding: 6px 20px 14px 20px;
    font-weight: 700;
    border-bottom: 1px solid #3a3a46;
}

.room-modal .level-label {
    padding: 12px 20px 6px 20px;
    color: #9c9cae;
    font-size: 0.8rem;
    font-weight: 700;
}

.room-modal .room-item {
    padding: 14px 20px;
    border-bottom: 1px solid #33333e;
    cursor: pointer;
    font-size: 0.95rem;
}
.room-modal .room-item:active { background: #33333e; }

/* ฟอร์มครูรายงาน */
.selected-room-banner {
    background: #eaf6ec;
    color: #1f8b3b;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.selected-room-banner button {
    background: none;
    border: none;
    color: #1f8b3b;
    text-decoration: underline;
    font-size: 0.8rem;
    cursor: pointer;
}

.checklist-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f5;
    gap: 10px;
}
.checklist-item:last-child { border-bottom: none; }

.checklist-item .item-label {
    font-size: 0.88rem;
    flex: 1;
}

.toggle-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.toggle-btn {
    padding: 8px 14px;
    border-radius: 999px;
    border: 2px solid transparent;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    background: #f1f1f5;
    color: #999;
}

.toggle-btn.pass.selected { background: var(--green); color: #fff; }
.toggle-btn.fail.selected { background: var(--red); color: #fff; }

.star-rating {
    display: flex;
    gap: 6px;
    font-size: 1.6rem;
    justify-content: flex-start;
    margin-top: 4px;
}
.star-rating .star {
    cursor: pointer;
    color: #ddd;
}
.star-rating .star.filled { color: #f5b301; }

.radio-choice-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
@media (min-width: 560px) {
    .radio-choice-grid { grid-template-columns: 1fr 1fr; }
}

.radio-choice {
    border: 2px solid #e8e8f0;
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.radio-choice input { accent-color: var(--pink); }
.radio-choice.selected-good { border-color: var(--green); background: #f0fbf2; }
.radio-choice.selected-bad { border-color: var(--red); background: #fef1f1; }

.note-field {
    margin-top: 8px;
    display: none;
}
.note-field.visible { display: block; }

textarea, input[type=text], input[type=date] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #e2e2ea;
    font-family: inherit;
    font-size: 0.88rem;
}

.photo-upload-box {
    border: 2px dashed #c9d6f5;
    border-radius: 14px;
    padding: 24px 14px;
    text-align: center;
    color: var(--blue);
    cursor: pointer;
    background: #f7faff;
    position: relative;
}
.photo-upload-box .icon { font-size: 1.8rem; display: block; margin-bottom: 6px; }
.photo-upload-box .hint { font-size: 0.75rem; color: var(--text-muted); }
.photo-upload-box input[type=file] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

.photo-preview-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.photo-preview-row img {
    width: 72px; height: 72px; object-fit: cover; border-radius: 10px;
}

.step-progress {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}
.step-progress .dot {
    flex: 1;
    height: 6px;
    border-radius: 4px;
    background: #e6e6ee;
}
.step-progress .dot.done { background: var(--gradient); }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
table.data-table th, table.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    text-align: left;
}
table.data-table th { color: var(--text-muted); font-weight: 700; }

.status-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}
.status-pill.ok { background: #eafaf0; color: #1f8b3b; }
.status-pill.bad { background: #fdeeee; color: #d33; }

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    margin-bottom: 14px;
}
.alert-error { background: #fdeeee; color: #b02a2a; }
.alert-success { background: #eafaf0; color: #1f8b3b; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }

.admin-menu-list a {
    display: block;
    padding: 14px 16px;
    border-radius: 12px;
    background: #f7f8fc;
    margin-bottom: 10px;
    text-decoration: none;
    color: var(--text-dark);
    font-weight: 600;
    font-size: 0.9rem;
}

@media print {
    .app-header, .app-footer, .no-print { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ---------- แดชบอร์ด: สรุปสถิติ ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 4px;
}
@media (min-width: 560px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
}

.stat-card {
    border-radius: 14px;
    padding: 16px;
    background: #f7f8fc;
}
.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}
.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-dark);
}
.stat-card .stat-value small {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}
.stat-card.stat-issue.has-issue {
    background: #fdeeee;
}
.stat-card.stat-issue.has-issue .stat-value { color: #c62828; }
.stat-card.stat-issue:not(.has-issue) {
    background: #eafaf0;
}
.stat-card.stat-issue:not(.has-issue) .stat-value { color: #1f8b3b; }

.progress-track {
    height: 8px;
    background: #e6e6ee;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}
.progress-fill {
    height: 100%;
    background: var(--gradient);
    border-radius: 999px;
}

/* ---------- แดชบอร์ด: การ์ดรายงานรายห้อง ---------- */
.report-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 700px) {
    .report-list { grid-template-columns: 1fr 1fr; }
}

.report-card {
    border: 1px solid #eef0f7;
    border-radius: 14px;
    padding: 14px;
    background: #fbfbfe;
}
.report-card.has-issue {
    border-color: #f6c9c9;
    background: #fff8f8;
}

.report-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.report-card-head .room-name {
    font-weight: 700;
    font-size: 0.95rem;
}

.check-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.check-chip {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 999px;
    background: #eafaf0;
    color: #1f8b3b;
    white-space: nowrap;
}
.check-chip.fail {
    background: #fdeeee;
    color: #c62828;
}

.report-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    align-items: center;
}
.report-card-meta strong { color: var(--text-dark); }

.report-alert-note {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #fff3cd;
    color: #7a5c00;
    font-size: 0.78rem;
}