:root {
    --ink: #27324a;
    --muted: #718096;
    --paper: #f6f8fd;
    --surface: #fff;
    --line: #e5eaf3;
    --blue: #6879e8;
    --blue-dark: #5061cf;
    --green: #278460;
    --green-bg: #ddf5e9;
    --red: #c94d5c;
    --red-bg: #ffe5e8;
    --orange: #a96818;
    --orange-bg: #fff0d7;
    --gray-bg: #edf0f5;
    --shadow: 0 12px 34px rgb(63 76 117 / 8%);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: "Segoe UI", Arial, sans-serif; line-height: 1.5; }
body.modal-open { overflow: hidden; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

.page-shell { min-height: 100vh; display: flex; flex-direction: column; }
.site-header { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 11px; font-weight: 700; text-decoration: none; }
.brand-logo { width: 48px; height: 40px; object-fit: contain; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.content { width: min(1180px, calc(100% - 40px)); margin: 24px auto 60px; flex: 1; outline: none; }
.site-footer { padding: 24px; color: var(--muted); text-align: center; font-size: 13px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(34px, 5vw, 58px); line-height: 1.08; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: clamp(20px, 3vw, 28px); line-height: 1.2; }
.eyebrow, .section-kicker { margin-bottom: 9px; color: var(--blue); font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.section-kicker { color: var(--muted); }
.muted { color: var(--muted); }

.button { min-height: 44px; border: 1px solid transparent; border-radius: 14px; padding: 10px 17px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: inherit; background: transparent; cursor: pointer; font-weight: 600; text-decoration: none; transition: transform 150ms ease, background 150ms ease; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .role-tab:focus-visible, .help-close:focus-visible { outline: 3px solid rgb(80 97 207 / 25%); outline-offset: 2px; }
.button-primary { color: #fff; background: var(--blue); }
.button-primary:hover { background: var(--blue-dark); }
.button-secondary { border-color: var(--line); background: var(--surface); }
.button-quiet { min-height: 38px; padding: 7px 13px; border-color: var(--line); color: var(--muted); }
.button-wide { width: 100%; margin-top: 8px; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 600; }
input, select { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; color: var(--ink); background: #fff; }
select {
    padding-right: 42px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1.5 5 5 5-5' fill='none' stroke='%2327324a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 12px 8px;
}
.field + .field { margin-top: 16px; }
.form-error { min-height: 22px; color: var(--red); font-size: 13px; font-weight: 700; }
.form-panel form > .form-error:empty { display: none; }

.boot-loader { min-height: 55vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); font-weight: 600; }
.spinner { width: 36px; height: 36px; border: 3px solid #dfe3fb; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast-region { position: fixed; z-index: 120; top: 20px; right: 20px; width: min(390px, calc(100% - 40px)); display: grid; gap: 8px; }
.toast { border: 1px solid #a8d5ba; border-radius: 14px; padding: 13px 16px; color: var(--green); background: var(--green-bg); box-shadow: var(--shadow); font-weight: 700; }
.toast-error { border-color: #edb6b1; color: var(--red); background: var(--red-bg); }
.clipboard-fallback { position: fixed; top: -1000px; left: -1000px; width: 1px; height: 1px; }

.login-card, .narrow-card, .panel { border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.login-layout { min-height: 610px; display: grid; grid-template-columns: 1.15fr .85fr; align-items: center; gap: clamp(40px, 9vw, 120px); }
.login-intro { max-width: 650px; }
.login-intro > p:not(.eyebrow) { max-width: 590px; color: var(--muted); font-size: 18px; }
.group-note { max-width: 590px; margin-top: 24px; border: 1px solid #dfe4ff; border-radius: 18px; padding: 15px 17px; display: grid; gap: 4px; background: #f0f2ff; }
.group-note strong { font-size: 14px; }
.group-note span { color: var(--muted); font-size: 13px; }
.cutoff-note { max-width: 590px; margin-top: 24px; border-radius: 14px; padding: 13px 16px; color: #fff; background: var(--ink); font-size: 13px; font-weight: 600; }
.login-card { padding: 12px; }
.role-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; padding: 4px; border-radius: 16px; background: var(--gray-bg); }
.role-tab { border: 0; border-radius: 12px; padding: 11px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 600; }
.role-tab.is-active { color: var(--ink); background: #fff; box-shadow: 0 3px 12px rgb(23 35 59 / 8%); }
.role-panel { padding: 16px 18px; }
.role-panel .button-wide { margin-top: 24px; }
.narrow-card { width: min(520px, 100%); margin: 70px auto; padding: clamp(24px, 5vw, 44px); }
.narrow-card h1 { font-size: clamp(32px, 5vw, 46px); }
.stack-form { margin-top: 28px; }
.password-rules { margin: 13px 0 22px; padding-left: 20px; color: var(--muted); font-size: 13px; }
.error-card { text-align: center; }

.page-heading { margin: 34px 0 28px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.page-heading h1 { margin: 0; }
.parent-heading { align-items: flex-start; }
.parent-identity { position: relative; width: 100%; }
.parent-identity-row { display: flex; align-items: center; gap: 8px; }
.parent-heading h1 { min-width: 0; flex: 0 1 auto; font-size: clamp(15px, 4vw, 24px); white-space: nowrap; }
.birthday-value { margin: 7px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.birthday-editor { position: static; flex: 0 0 auto; }
.birthday-editor summary { min-height: 40px; padding: 7px 10px; list-style: none; font-size: 11px; white-space: nowrap; }
.birthday-editor summary::-webkit-details-marker { display: none; }
.birthday-form { position: absolute; z-index: 10; top: calc(100% + 8px); left: 0; width: min(430px, 100%); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; grid-template-columns: 90px minmax(160px, 1fr) auto; align-items: end; gap: 10px; background: var(--surface); box-shadow: 0 16px 36px rgb(39 50 74 / 16%); }
.birthday-form .field + .field { margin-top: 0; }
.birthday-form .button { min-height: 48px; }

.panel { margin-bottom: 22px; padding: clamp(18px, 3vw, 30px); }
.section-heading { margin-bottom: 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.attendance-meta { display: flex; align-items: center; gap: 8px; }
.timezone-badge, .readonly-badge, .row-counter, .current-week-badge { border-radius: 999px; padding: 8px 12px; color: var(--blue-dark); background: #e8ebff; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-legend { margin: -8px 0 16px; display: flex; flex-wrap: wrap; gap: 7px 13px; color: var(--muted); font-size: 10px; font-weight: 600; }
.legend-present, .status-present { color: var(--green); }
.legend-sick, .status-sick { color: var(--red); }
.legend-family, .status-family { color: var(--orange); }
.legend-missing, .status-missing { color: #98a2b3; }
.status-mark { display: inline-flex; justify-content: center; font-size: 15px; font-weight: 800; }
.status-pill { min-width: 62px; border-radius: 999px; padding: 5px 9px; display: inline-flex; justify-content: center; background: var(--orange-bg); font-size: 12px; font-weight: 800; }
.status-pill.status-sick { background: var(--red-bg); }

.parent-week-wrap { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; }
.parent-week-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
.parent-week-table th, .parent-week-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 10px 4px; text-align: center; }
.parent-week-table th:first-child { width: 23%; }
.parent-week-table thead th:nth-child(n + 2) { width: 11%; }
.parent-week-table thead th, .parent-week-table tbody th { color: var(--muted); background: #f8f9fc; font-size: 11px; font-weight: 600; }
.parent-week-table tbody td { font-size: 12px; }
.parent-week-table tr > *:last-child { border-right: 0; }
.parent-week-table tr:last-child > * { border-bottom: 0; }
.parent-week-table .is-weekend { background: #fffbf2; }

.attendance-rows { display: grid; gap: 10px; }
.attendance-row { display: grid; grid-template-columns: minmax(170px, .8fr) minmax(190px, 1fr) auto; align-items: end; gap: 12px; border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #fff; }
.attendance-row .field + .field { margin-top: 0; }
.attendance-row.is-weekend { border-color: #f0d59d; background: #fffbf2; }
.remove-row { min-height: 48px; border: 1px solid #f3bdc4; border-radius: 12px; padding: 8px 14px; color: var(--red); background: var(--red-bg); cursor: pointer; font-size: 13px; font-weight: 600; }
.weekend-warning { grid-column: 1 / -1; display: none; margin: 0; color: var(--orange); font-size: 12px; font-weight: 700; }
.attendance-row.is-weekend .weekend-warning { display: block; }
.form-actions { margin-top: 18px; display: flex; justify-content: space-between; gap: 12px; }
.vacation-hint { margin: -6px 0 18px; color: var(--muted); font-size: 13px; }
.vacation-grid { display: grid; grid-template-columns: .8fr 1fr 1fr; gap: 12px; }
.vacation-grid .field + .field { margin-top: 0; }
.vacation-grid + .button-wide { margin-top: 18px; }

.simple-table-wrap { overflow-x: auto; }
.simple-table { width: 100%; border-collapse: collapse; }
.simple-table th, .simple-table td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; }
.simple-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; }

.group-notification-card { border: 1px solid #f0d59d; border-radius: 18px; padding: 18px 20px; background: #fffbf2; }
.parent-notification { margin: -6px 0 22px; }
.group-notification-card .section-kicker { margin-bottom: 6px; color: var(--orange); }
.group-notification-message { margin-bottom: 7px; color: var(--ink); font-size: 17px; font-weight: 700; }
.group-notification-expiry { margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.notification-manager { display: grid; gap: 14px; }
.notification-manager > .section-heading { margin-bottom: 0; }
.notification-form { display: grid; }
.notification-form-grid { display: grid; grid-template-columns: minmax(260px, 1fr) 220px auto; align-items: end; gap: 12px; }
.notification-form-grid .field + .field { margin-top: 0; }
.notification-form-grid .button { min-height: 48px; }
.notification-counter { margin-top: 6px; justify-self: start; color: var(--muted); font-size: 11px; font-weight: 700; }
.active-notification { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 22px; }
.active-notification h3 { margin: 0 0 10px; font-size: 15px; }
.notification-delete { min-height: 38px; border: 1px solid #f3bdc4; padding: 7px 12px; color: var(--red); background: var(--red-bg); font-size: 12px; }
.active-notification .notification-delete { margin-top: 10px; }

.teacher-heading { align-items: flex-start; flex-direction: column; }
.week-navigation { width: 100%; display: grid; justify-items: start; gap: 9px; }
.week-period { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 700; }
.current-week-badge { padding: 2px 8px; color: var(--green); background: var(--green-bg); font-size: 10px; line-height: 16px; }
.week-buttons, .summary-actions, .title-group { display: flex; gap: 8px; }
.parent-week-controls { display: flex; align-items: center; gap: 10px; }
.parent-week-buttons .button { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.current-week-badge.is-placeholder { visibility: hidden; }
.title-group { align-items: center; }
.readonly-badge { color: #7a5a00; background: #fff0ad; }
.compact-title { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.compact-title span { border-radius: 999px; padding: 5px 10px; color: var(--blue-dark); background: #e8ebff; font-size: 12px; }
.copy-button { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.table-panel { padding-right: 0; }
.table-panel > .section-heading, .table-panel > .status-legend { margin-right: clamp(18px, 3vw, 30px); }
.matrix-wrap { overflow-x: auto; }
.attendance-matrix { width: 100%; min-width: 760px; table-layout: fixed; border-collapse: separate; border-spacing: 0; }
.attendance-matrix th, .attendance-matrix td { height: 54px; border-bottom: 1px solid var(--line); padding: 7px 2px; text-align: center; }
.attendance-matrix thead th { color: var(--muted); font-size: 11px; letter-spacing: .05em; }
.attendance-matrix thead span, .attendance-matrix thead small { display: block; }
.attendance-matrix thead small { margin-top: 3px; font-size: 11px; }
.attendance-matrix .name-column { position: sticky; left: 4%; z-index: 1; width: 19%; padding-left: 6px; color: var(--ink); background: var(--surface); text-align: left; }
.children-matrix thead th:nth-child(n + 3) { width: 11%; }
.attendance-matrix thead .name-column { z-index: 2; }
.attendance-matrix .row-number-column { position: sticky; left: 0; z-index: 2; width: 4%; color: var(--muted); background: var(--surface); font-size: 11px; }
.attendance-matrix .weekend-column { background: #fffbf2; }
.birthday-icon { margin-left: 4px; font-size: 15px; }
.summary-matrix .name-column { left: 0; width: 92px; }
.summary-matrix td { font-size: 18px; font-weight: 800; }
.empty-state { padding: 32px !important; color: var(--muted); text-align: center !important; }

.help-modal { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; }
.help-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgb(30 38 57 / 62%); backdrop-filter: blur(3px); cursor: default; }
.help-dialog { position: relative; width: min(620px, 100%); max-height: min(780px, calc(100vh - 40px)); overflow-y: auto; border: 1px solid var(--line); border-radius: 24px; padding: clamp(20px, 4vw, 32px); background: var(--surface); box-shadow: 0 24px 80px rgb(25 34 56 / 28%); outline: none; }
.help-heading { margin-bottom: 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.help-close { width: 40px; height: 40px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: var(--gray-bg); cursor: pointer; font-size: 25px; }
.help-section { border: 1px solid #dfe4ff; border-radius: 17px; padding: 17px 18px; background: #f7f8ff; }
.help-section + .help-section { margin-top: 12px; }
.help-section h3 { margin: 0 0 10px; }
.help-section ol { margin: 0; padding-left: 21px; }
.help-section li + li { margin-top: 7px; }
.help-section-teacher { border-color: #d8eee2; background: #f5fbf7; }
.help-note { margin: 13px 0 0; border-radius: 11px; padding: 10px 12px; color: #684c09; background: #fff0ad; font-size: 13px; font-weight: 600; }
.help-dialog > .button-wide { margin-top: 18px; }

@media (max-width: 820px) {
    .login-layout { min-height: auto; grid-template-columns: 1fr; gap: 34px; padding: 35px 0; }
    .login-intro { text-align: center; }
    .login-intro > p:not(.eyebrow), .group-note, .cutoff-note { margin-left: auto; margin-right: auto; }
    .group-note { text-align: left; }
}

@media (max-width: 560px) {
    body { padding-bottom: env(safe-area-inset-bottom); }
    .site-header, .content { width: min(100% - 24px, 1180px); }
    .site-header { padding: 14px 0; }
    .brand-logo { width: 42px; height: 34px; }
    .header-actions .button { min-height: 40px; padding: 7px 10px; font-size: 13px; }
    .content { margin-top: 8px; }
    h1 { font-size: clamp(31px, 10vw, 42px); }
    input, select { min-height: 52px; font-size: 16px; }
    .button { min-height: 48px; }
    .page-heading { margin-top: 18px; align-items: flex-start; flex-direction: column; }
    .panel { border-radius: 20px; }
    .parent-week-panel { padding-left: 12px; padding-right: 12px; }
    .parent-week-table th, .parent-week-table td { padding: 9px 2px; }
    .parent-week-table tbody th { font-size: 9px; }
    .birthday-form { grid-template-columns: 1fr 1fr; }
    .birthday-form .button { grid-column: 1 / -1; width: 100%; }
    .section-heading { align-items: flex-start; flex-wrap: wrap; gap: 12px; }
    .attendance-row { grid-template-columns: 1fr; }
    .attendance-row > * { grid-column: 1 / -1; }
    .form-actions { position: sticky; z-index: 4; bottom: 0; margin: 16px -18px -18px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); flex-direction: column-reverse; border-top: 1px solid var(--line); border-radius: 0 0 20px 20px; background: rgb(255 255 255 / 97%); box-shadow: 0 -12px 24px rgb(40 47 62 / 7%); }
    .form-actions .button { width: 100%; }
    .vacation-grid { grid-template-columns: 1fr; }
    .vacation-grid .field + .field { margin-top: 16px; }
    .week-buttons { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
    .parent-week-controls { width: 100%; align-items: stretch; flex-direction: column; }
    .parent-week-controls .current-week-badge { align-self: flex-start; }
    .table-panel { padding-left: 14px; }
    .summary-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
    .summary-actions .copy-button { min-width: 0; padding: 5px; font-size: 10px; }
    .attendance-matrix { min-width: 600px; }
    .attendance-matrix .name-column { font-size: 10px; }
    .attendance-matrix th, .attendance-matrix td { height: 48px; }
    .summary-matrix { min-width: 520px; }
    .summary-matrix .name-column { width: 64px; }
    .summary-matrix td { font-size: 14px; }
    .parent-notification { margin-top: 0; }
    .group-notification-card { padding: 15px 16px; }
    .group-notification-message { font-size: 15px; }
    .notification-form-grid { grid-template-columns: 1fr; }
    .notification-form-grid > * { grid-column: 1; }
    .notification-form-grid .field + .field { margin-top: 4px; }
    .notification-form-grid .button { width: 100%; }
    .help-modal { align-items: end; padding: 10px; }
    .help-dialog { max-height: calc(100vh - 20px); border-radius: 22px; }
    .toast-region { top: 12px; right: 12px; width: calc(100% - 24px); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
