:root {
    --ink: #27324a;
    --muted: #718096;
    --paper: #f6f8fd;
    --surface: #ffffff;
    --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;
    --yellow: #ffd86b;
    --shadow: 0 12px 34px rgba(63, 76, 117, 0.08);
}

* { 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; }

.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-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 10px 10px 10px 3px;
    color: #fff;
    background: var(--blue);
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions form { margin: 0; }
.content { width: min(1180px, calc(100% - 40px)); margin: 24px auto 60px; flex: 1; }
.site-footer { padding: 24px; color: var(--muted); text-align: center; font-size: 13px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-family: inherit; font-size: clamp(34px, 5vw, 58px); font-weight: 700; line-height: 1.08; letter-spacing: -0.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: 0.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;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, .role-tab:focus-visible { outline: 3px solid rgba(49, 93, 168, 0.25); outline-offset: 2px; }
.button-primary { color: #fff; background: var(--blue); box-shadow: none; }
.button-primary:hover { background: var(--blue-dark); }
.button-secondary { border-color: var(--line); color: var(--ink); background: var(--surface); }
.button-quiet { min-height: 38px; padding: 7px 13px; color: var(--muted); background: transparent; border-color: var(--line); }
.button-wide { width: 100%; margin-top: 8px; }
.button:disabled { opacity: 0.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;
}

.messages { margin-bottom: 18px; display: grid; gap: 8px; }
.message { border: 1px solid var(--line); border-radius: 12px; padding: 13px 16px; font-weight: 700; background: var(--surface); }
.message-success { border-color: #a8d5ba; color: var(--green); background: var(--green-bg); }
.message-error { border-color: #edb6b1; color: var(--red); background: var(--red-bg); }

.help-modal { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; }
.help-modal[hidden] { display: none; }
.help-backdrop { position: absolute; inset: 0; background: rgba(30, 38, 57, 0.62); backdrop-filter: blur(3px); }
.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 rgba(25, 34, 56, 0.28); outline: none; }
.help-heading { margin-bottom: 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.help-heading .section-kicker { margin-bottom: 5px; }
.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; line-height: 1; }
.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; font-size: 17px; }
.help-section ol { margin: 0; padding-left: 21px; }
.help-section li { padding-left: 3px; }
.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; }

.login-layout { min-height: 610px; display: grid; grid-template-columns: 1.15fr 0.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; }
.group-note a { color: var(--blue-dark); font-weight: 700; text-underline-offset: 3px; }
.cutoff-note { max-width: 590px; margin-top: 24px; border-radius: 14px; padding: 13px 16px; color: #fff; background: var(--ink); }
.cutoff-note span { color: inherit; font-size: 13px; font-weight: 600; }
.login-card, .narrow-card, .panel {
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.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 rgba(23, 35, 59, 0.08); }
.role-panel { padding: 22px 18px 16px; }
.role-panel label:not(:first-of-type) { margin-top: 17px; }
.role-panel .button-wide { margin-top: 24px; }
.child-select { position: relative; }
.child-select-ui { display: none; }
.child-select.has-custom-select > select { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.child-select.has-custom-select .child-select-ui { display: block; }
.child-select-trigger { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 14px; padding: 10px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--ink); background: #fff; cursor: pointer; text-align: left; }
.select-chevron { width: 9px; height: 9px; margin-right: 5px; flex: 0 0 auto; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-2px) rotate(45deg); transition: transform 150ms ease; }
.child-select-trigger[aria-expanded="true"] .select-chevron { transform: translateY(3px) rotate(225deg); }
.child-select-menu { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; right: 0; max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 14px; padding: 6px; background: #fff; box-shadow: 0 14px 34px rgba(39, 50, 74, 0.14); }
.child-select-menu button { width: 100%; border: 0; border-radius: 9px; padding: 10px 12px; color: var(--ink); background: transparent; cursor: pointer; text-align: left; }
.child-select-menu button:hover, .child-select-menu button[aria-selected="true"] { color: var(--blue-dark); background: #eef0ff; }
.child-select.is-invalid .child-select-trigger { border-color: var(--red); box-shadow: 0 0 0 3px rgba(201, 77, 92, 0.12); }

.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; }
.stack-form label:not(:first-of-type) { margin-top: 16px; }
.password-rules { margin: 13px 0 22px; padding-left: 20px; color: var(--muted); font-size: 13px; }

.page-heading { margin: 34px 0 28px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.page-heading h1 { margin: 0; }
.timezone-badge, .readonly-badge, .row-counter { border-radius: 999px; padding: 8px 12px; color: var(--blue-dark); background: #e8ebff; font-size: 12px; font-weight: 800; white-space: nowrap; }
.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; }

.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: 70px; }
.parent-week-table thead th { color: var(--muted); background: #f8f9fc; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.parent-week-table tbody th { color: var(--muted); background: #f8f9fc; font-size: 11px; font-weight: 600; text-align: center; }
.parent-week-table tbody td { font-size: 12px; }
.date-full { display: inline-block; line-height: 1.15; }
.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; }
.parent-week-table .status { min-width: 0; max-width: 100%; padding: 4px 5px; font-size: 10px; }
.status { min-width: 62px; border-radius: 999px; padding: 5px 9px; display: inline-flex; justify-content: center; color: var(--ink); background: var(--gray-bg); font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-present { color: var(--green); background: var(--green-bg); }
.status-sick { color: var(--red); background: var(--red-bg); }
.status-family { color: var(--orange); background: var(--orange-bg); }
.status-missing { color: #77746f; background: var(--gray-bg); }
.status-symbol { min-width: 0; padding: 0; background: transparent; font-size: 15px; font-weight: 800; }
.status-missing { min-width: 0; padding: 0; color: #98a2b3; background: transparent; font-size: 11px; font-weight: 600; }
.status-legend { margin: -8px 0 16px; display: flex; flex-wrap: wrap; gap: 7px 13px; color: var(--muted); font-size: 10px; font-weight: 600; }
.status-legend span { white-space: nowrap; }
.legend-present { color: var(--green); }
.legend-sick { color: var(--red); }
.legend-family { color: var(--orange); }
.legend-missing { color: #98a2b3; }

.attendance-rows { display: grid; gap: 10px; }
.attendance-row { position: relative; display: grid; grid-template-columns: minmax(170px, 0.8fr) minmax(190px, 1fr); align-items: end; gap: 12px; border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #fff; }
.attendance-row.is-weekend { border-color: #f0d59d; background: #fffbf2; }
.remove-row { grid-column: 1 / -1; min-height: 40px; 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; }
.form-error { min-height: 22px; margin-top: 8px; color: var(--red); font-size: 13px; font-weight: 700; }
.vacation-hint { margin: -6px 0 18px; color: var(--muted); font-size: 13px; }
.vacation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.vacation-submit { margin-top: 18px; }

.simple-table-wrap { overflow-x: auto; }
.matrix-wrap { overflow-x: hidden; }
.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; }

.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; text-align: left; }
.current-week-badge { height: 32px; border-radius: 999px; padding: 0 9px; display: inline-flex; align-items: center; color: var(--green); background: var(--green-bg); font-size: 10px; font-weight: 700; }
.week-buttons { display: flex; gap: 8px; }
.table-panel { padding-right: 0; }
.table-panel .section-heading { padding-right: clamp(18px, 3vw, 30px); }
.compact-title { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.compact-title span { height: 32px; border-radius: 999px; padding: 0 10px; display: inline-flex; align-items: center; color: var(--blue-dark); background: #e8ebff; font-size: 12px; font-weight: 700; }
.readonly-badge { height: 32px; padding-top: 0; padding-bottom: 0; display: inline-flex; align-items: center; color: #7a5a00; background: #fff0ad; }
.title-group { display: flex; align-items: center; gap: 8px; }
.heading-actions { display: flex; align-items: center; gap: 8px; }
.copy-button { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.summary-actions { display: flex; gap: 8px; }
.attendance-matrix { width: 100%; min-width: 0; 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: 0.05em; }
.attendance-matrix thead th span, .attendance-matrix thead th small { display: block; }
.attendance-matrix thead th small { margin-top: 3px; font-size: 11px; font-weight: 600; }
.attendance-matrix .name-column { position: sticky; left: 0; z-index: 1; width: 210px; padding-left: 4px; color: var(--ink); background: var(--surface); text-align: left; }
.attendance-matrix thead .name-column { z-index: 2; }
.attendance-matrix .weekend-column { background: #fffbf2; }
.attendance-matrix tbody tr:last-child > * { border-bottom: 0; }
.children-matrix-wrap { overflow-x: hidden; }
.children-matrix { width: 100%; min-width: 0; table-layout: fixed; }
.children-matrix .name-column { width: 120px; white-space: nowrap; }
.children-matrix th, .children-matrix td { padding-left: 1px; padding-right: 1px; }
.attendance-matrix .status-missing { min-width: 0; padding: 0; color: #98a2b3; background: transparent; font-size: 11px; }
.summary-panel .matrix-wrap { overflow-x: hidden; }
.summary-matrix { min-width: 0; table-layout: fixed; }
.summary-matrix .name-column { width: 92px; max-width: 92px; }
.summary-matrix td { font-size: 18px; font-weight: 800; }
.empty-state { padding: 32px !important; color: var(--muted); text-align: center !important; }
.error-card { text-align: center; }
.error-card .button { margin-top: 16px; }

@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) { margin-left: auto; margin-right: auto; }
    .group-note { margin-left: auto; margin-right: auto; text-align: left; }
    .cutoff-note { justify-content: center; }
    .teacher-heading { align-items: flex-start; }
    .week-navigation { justify-content: start; }
}

@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; }
    .header-actions { gap: 5px; }
    .header-actions .button { min-height: 40px; padding: 7px 10px; font-size: 13px; }
    .help-modal { align-items: end; padding: 10px; }
    .help-dialog { max-height: calc(100vh - 20px); border-radius: 22px; }
    .help-section { padding: 15px; font-size: 14px; }
    .content { margin-top: 8px; }
    .brand-mark { width: 34px; height: 34px; }
    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; }
    .parent-week-panel { padding-left: 12px; padding-right: 12px; }
    .parent-week-table th, .parent-week-table td { padding: 9px 2px; }
    .parent-week-table th:first-child { width: 48px; }
    .parent-week-table tbody th { font-size: 9px; }
    .parent-week-table tbody td { font-size: 10px; }
    .parent-week-table .date-full { max-width: 36px; font-size: 9px; overflow-wrap: anywhere; }
    .parent-week-table .status { padding: 3px 2px; font-size: 9px; line-height: 1.15; white-space: normal; }
    .parent-week-table .status-symbol { padding: 0; background: transparent; font-size: 13px; }
    .parent-week-table .status-missing { padding: 0; background: transparent; font-size: 9px; }
    .attendance-row { grid-template-columns: 1fr; }
    .attendance-row > div { grid-column: 1 / -1; }
    .attendance-row .remove-row { position: static; width: 100%; min-height: 44px; }
    .vacation-grid { grid-template-columns: 1fr; }
    .form-actions {
        position: sticky;
        bottom: 0;
        z-index: 4;
        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: rgba(255, 255, 255, 0.97);
        box-shadow: 0 -12px 24px rgba(40, 47, 62, 0.07);
    }
    .form-actions .button { width: 100%; }
    .week-navigation { display: grid; grid-template-columns: 1fr; }
    .week-period { grid-row: 1; text-align: left; }
    .week-buttons { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
    .panel { border-radius: 20px; }
    .table-panel { padding-left: 14px; }
    .attendance-matrix { width: 100%; min-width: 0; }
    .attendance-matrix .name-column { width: 88px; max-width: 88px; padding-left: 2px; font-size: 10px; }
    .attendance-matrix th, .attendance-matrix td { height: 48px; padding: 5px 2px; }
    .attendance-matrix thead th { font-size: 9px; letter-spacing: 0; }
    .attendance-matrix thead th small { font-size: 8px; }
    .attendance-matrix .status { min-width: 0; max-width: 100%; padding: 4px 2px; font-size: 8px; line-height: 1.15; white-space: normal; }
    .children-matrix { width: 100%; min-width: 0; }
    .children-matrix .name-column { width: 76px; max-width: 76px; padding-left: 1px; font-size: 8px; white-space: nowrap; }
    .children-matrix th, .children-matrix td { padding-left: 1px; padding-right: 1px; }
    .table-panel .section-heading { flex-wrap: wrap; gap: 10px; }
    .compact-title { gap: 6px; font-size: 18px; }
    .compact-title span, .readonly-badge { height: 30px; padding: 0 8px; font-size: 10px; }
    .title-group { gap: 6px; }
    .summary-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
    .summary-actions .copy-button { min-width: 0; padding-left: 5px; padding-right: 5px; font-size: 10px; }
    .summary-matrix { width: 100%; min-width: 0; }
    .summary-matrix .name-column { width: 64px; max-width: 64px; padding-left: 2px; font-size: 9px; }
    .summary-matrix th, .summary-matrix td { height: 44px; padding: 5px 2px; font-size: 12px; }
    .summary-matrix thead th { font-size: 9px; letter-spacing: 0; }
    .summary-matrix thead th small { margin-left: auto; margin-right: auto; font-size: 8px; line-height: 1.1; }
    .summary-matrix .status { min-width: 0; max-width: 64px; padding: 4px 5px; font-size: 9px; }
    .attendance-matrix .status-symbol { padding: 0; background: transparent; font-size: 13px; }
    .attendance-matrix .status-missing { padding: 0; color: #98a2b3; background: transparent; font-size: 10px; }
}
