:root {
  color-scheme: light;
  --green-950: #123b31;
  --green-800: #1e5c4a;
  --green-700: #28705c;
  --green-100: #dff0e9;
  --green-50: #f2f8f5;
  --ink: #1d2724;
  --muted: #68736f;
  --line: #dfe5e2;
  --line-dark: #cdd5d1;
  --surface: #ffffff;
  --canvas: #f4f6f5;
  --red: #c64343;
  --red-bg: #fdeaea;
  --amber: #a86608;
  --amber-bg: #fff1d6;
  --blue: #346ca0;
  --blue-bg: #e8f1fb;
  --shadow: 0 16px 38px rgba(23, 55, 45, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font-size: 16px;
}

[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 18%, rgba(92, 162, 132, .18), transparent 34%),
    linear-gradient(145deg, #0f332a, #17493b 58%, #0d2d25);
}

.login-card {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 28px 70px rgba(0, 18, 12, .28);
}
.login-brand { display: flex; align-items: center; gap: 12px; color: var(--green-950); }
.login-brand .brand-mark { color: #fff; background: var(--green-950); }
.brand-mark.large { width: 50px; height: 50px; }
.login-brand strong, .login-brand span { display: block; }
.login-brand strong { font-size: 17px; }
.login-brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.login-copy { margin: 32px 0 23px; }
.login-copy h1 { font-size: 29px; }
.login-copy p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.form-field { display: grid; gap: 7px; margin-bottom: 15px; color: #4d5a55; font-size: 13px; font-weight: 700; }
.form-field input, .inline-form input, .editable-row input {
  width: 100%;
  min-width: 0;
  height: 43px;
  padding: 0 12px;
  border: 1px solid var(--line-dark);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
.form-field input:focus, .inline-form input:focus, .editable-row input:focus { border-color: var(--green-700); box-shadow: 0 0 0 3px rgba(40,112,92,.13); }
.form-error { min-height: 20px; margin: -2px 0 8px; color: var(--red); font-size: 13px; }
.login-button { width: 100%; min-height: 46px; }

button, select, textarea { font: inherit; }
button { color: inherit; }
button, select { min-height: 42px; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 72px;
  padding: 0 clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: var(--green-950);
}

.topbar-actions { display: flex; align-items: center; gap: 9px; min-width: 0; }
.header-button {
  min-height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid rgba(255,255,255,.17);
  border-radius: 9px;
  color: rgba(255,255,255,.88);
  background: rgba(255,255,255,.07);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.header-button:hover { background: rgba(255,255,255,.13); }
.header-button:disabled { opacity: .45; cursor: not-allowed; }
.header-button svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.header-button.compact { width: 38px; padding: 0; }
.user-name { max-width: 110px; overflow: hidden; color: rgba(255,255,255,.64); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 11px;
  background: rgba(255,255,255,.09);
}
.brand-mark svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; letter-spacing: .01em; }
.brand span { margin-top: 2px; color: rgba(255,255,255,.66); font-size: 12px; }

.save-state { display: flex; align-items: center; gap: 8px; color: rgba(255,255,255,.76); font-size: 13px; }
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: #6fd4a8; box-shadow: 0 0 0 4px rgba(111,212,168,.12); }
.save-state.saving .save-dot { background: #f0c66b; }
.save-state.error .save-dot { background: #f06b6b; }

main { padding: 26px clamp(18px, 4vw, 56px) 40px; }

.control-panel {
  max-width: 1600px;
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: minmax(140px, .75fr) minmax(210px, 1.4fr) minmax(240px, auto);
  align-items: end;
  gap: 14px;
}
.select-group, .month-picker { min-width: 0; }

.select-group label, .control-label {
  display: block;
  margin: 0 0 7px 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

select {
  min-width: 0;
  width: 100%;
  padding: 0 38px 0 13px;
  color: var(--ink);
  border: 1px solid var(--line-dark);
  border-radius: 9px;
  background: var(--surface);
  outline: none;
}
select:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid rgba(40,112,92,.24); outline-offset: 2px; }

.month-controls { display: grid; grid-template-columns: 42px minmax(150px, 1fr) 42px; gap: 6px; }
.icon-button, .month-title, .close-button {
  border: 1px solid var(--line-dark);
  background: var(--surface);
  cursor: pointer;
}
.icon-button { display: grid; place-items: center; border-radius: 9px; }
.icon-button:hover, .month-title:hover { border-color: #aebbb5; background: #f9fbfa; }
.icon-button svg, .close-button svg, .hint svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.month-title { min-width: 0; padding: 0 14px; overflow: hidden; border-radius: 9px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

.journal-card {
  max-width: 1600px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(29, 39, 36, .04);
}

.journal-header {
  min-height: 100px;
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.eyebrow { margin: 0 0 6px; color: var(--green-700); font-size: 13px; font-weight: 750; letter-spacing: .025em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(22px, 2.2vw, 30px); line-height: 1.18; letter-spacing: -.025em; }
.summary { display: flex; align-items: center; gap: 25px; }
.summary span { display: grid; gap: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.summary-value { font-size: 20px; line-height: 1; }
.summary-present { color: var(--green-700); }
.summary-absent { color: var(--red); }
.summary-late { color: var(--amber); }

.journal-toolbar {
  min-height: 52px;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; color: #53605b; font-size: 12px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-mark, .status-symbol {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 5px;
  font-style: normal;
  font-weight: 800;
}
.legend-mark { width: 23px; height: 23px; font-size: 11px; }
.present { color: var(--green-800); background: var(--green-100); }
.absent { color: var(--red); background: var(--red-bg); }
.late { color: var(--amber); background: var(--amber-bg); }
.excused { color: var(--blue); background: var(--blue-bg); }
.hint { margin: 0; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }

.table-wrap { overflow: auto; max-height: calc(100vh - 330px); min-height: 330px; overscroll-behavior: contain; }
.empty-state { min-height: 330px; padding: 50px 20px; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; }
.empty-state strong { font-size: 18px; }
.empty-state span { margin: 7px 0 18px; color: var(--muted); font-size: 14px; }
.journal-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.journal-table th, .journal-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.journal-table tr:last-child td { border-bottom: 0; }
.journal-table th:last-child, .journal-table td:last-child { border-right: 0; }
.journal-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 58px;
  padding: 0;
  color: #50605a;
  background: #f7f9f8;
  font-size: 12px;
  font-weight: 700;
  box-shadow: inset 0 -1px 0 var(--line-dark);
}
.journal-table .student-heading {
  left: 0;
  z-index: 6;
  width: 250px;
  min-width: 250px;
  padding: 0 16px;
  text-align: left;
  color: #36423e;
  background: #f2f5f3;
}
.day-heading { width: 44px; min-width: 44px; text-align: center; }
.day-heading span { display: block; }
.day-heading .weekday { margin-top: 3px; color: #8a9591; font-size: 10px; font-weight: 650; text-transform: uppercase; }
.day-heading.weekend { background: #f1f3f2; color: #89928f; }
.day-heading.today { color: #fff; background: var(--green-800); box-shadow: none; }
.day-heading.today .weekday { color: rgba(255,255,255,.7); }

.row-number { display: inline-grid; place-items: center; width: 25px; height: 25px; margin-right: 9px; border-radius: 7px; color: #7b8682; background: #e7ece9; font-size: 11px; font-weight: 700; }
.student-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 250px;
  min-width: 250px;
  height: 46px;
  padding: 0 12px;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--line-dark);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}
.journal-table tbody tr:hover .student-cell { background: #f8faf9; }

.attendance-cell { width: 44px; min-width: 44px; height: 46px; padding: 0; background: #fff; }
.attendance-cell.weekend { background: #fafbfa; }
.cell-button {
  position: relative;
  width: 100%;
  height: 45px;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.cell-button:hover { background: var(--green-50); box-shadow: inset 0 0 0 2px rgba(40,112,92,.25); }
.cell-button.active { background: var(--green-50); box-shadow: inset 0 0 0 2px var(--green-700); }
.cell-value { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 6px; font-size: 12px; font-weight: 850; }
.comment-indicator { position: absolute; right: 3px; bottom: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--green-700); box-shadow: 0 0 0 2px #fff; }

.cell-editor {
  position: fixed;
  z-index: 30;
  width: min(390px, calc(100vw - 24px));
  padding: 19px;
  border: 1px solid var(--line-dark);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.editor-handle { display: none; }
.editor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.editor-heading p { margin: 0 0 4px; color: var(--green-700); font-size: 13px; font-weight: 700; }
.editor-heading h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.close-button { width: 34px; height: 34px; min-height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 8px; color: #64706c; }
.close-button:hover { background: #f2f5f3; }
.status-fieldset { margin: 18px 0; padding: 0; border: 0; }
.status-fieldset legend, .comment-field label { margin-bottom: 8px; color: #59645f; font-size: 12px; font-weight: 750; }
.status-options { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.status-options button {
  min-height: 45px;
  padding: 6px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: #46514d;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.status-options button:hover { border-color: #aab7b1; background: #fafcfb; }
.status-options button.selected { border-color: var(--green-700); box-shadow: 0 0 0 2px rgba(40,112,92,.13); }
.status-symbol { width: 28px; height: 28px; font-size: 11px; }
.comment-field label { display: block; }
.comment-field textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid var(--line-dark);
  border-radius: 9px;
  color: var(--ink);
  line-height: 1.45;
  outline: none;
}
.comment-field textarea::placeholder { color: #9aa39f; }
.comment-meta { margin-top: 5px; display: flex; justify-content: space-between; color: #919a96; font-size: 11px; }
.guest-mode .status-options button { cursor: default; }
.guest-mode .comment-field textarea { color: #4d5a55; background: #f5f7f6; cursor: default; }
.editor-actions { margin-top: 17px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.text-button { min-height: 40px; padding: 0 4px; border: 0; background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; }
.text-button.danger { color: var(--red); }
.primary-button { min-height: 40px; padding: 0 20px; border: 0; border-radius: 9px; color: #fff; background: var(--green-800); font-size: 13px; font-weight: 750; cursor: pointer; }
.primary-button:hover { background: var(--green-700); }
.primary-button:disabled, .secondary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--green-700);
  border-radius: 9px;
  color: var(--green-800);
  background: #fff;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}
.secondary-button:hover { background: var(--green-50); }
.editor-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(14, 30, 25, .32); }

.modal-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(10, 27, 21, .48); backdrop-filter: blur(2px); }
.settings-modal {
  position: fixed;
  z-index: 40;
  inset: 5vh 50% auto auto;
  transform: translateX(50%);
  width: min(920px, calc(100vw - 28px));
  height: min(780px, 90vh);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr;
  border: 1px solid var(--line-dark);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(14, 36, 29, .25);
}
.settings-header { padding: 18px 20px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.settings-header p { margin: 0 0 4px; color: var(--green-700); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.settings-header h2 { margin: 0; font-size: 23px; }
.settings-tabs { padding: 0 20px; display: flex; gap: 22px; border-bottom: 1px solid var(--line); background: #fbfcfb; }
.settings-tabs button { min-height: 49px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-size: 13px; font-weight: 750; cursor: pointer; }
.settings-tabs button.active { color: var(--green-800); border-bottom-color: var(--green-700); }
.settings-content { overflow: auto; padding: 22px; }
.settings-pane { display: none; }
.settings-pane.active { display: block; }
.settings-grid { display: grid; grid-template-columns: minmax(250px, .72fr) minmax(340px, 1.28fr); gap: 20px; }
.settings-section { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfb; }
.settings-section.narrow { max-width: 560px; }
.section-heading { margin-bottom: 14px; }
.section-heading h3 { margin: 0; font-size: 17px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-bottom: 12px; }
.editable-list { display: grid; gap: 7px; max-height: 490px; overflow-y: auto; }
.editable-row { min-width: 0; min-height: 45px; padding: 5px 6px 5px 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.editable-row.active { border-color: var(--green-700); box-shadow: inset 3px 0 var(--green-700); }
.editable-row input { height: 34px; padding: 0 7px; border-color: transparent; background: transparent; font-size: 13px; font-weight: 650; }
.editable-row input:focus { background: #fff; }
.row-action { width: 32px; height: 32px; min-height: 32px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 7px; color: #7a8581; background: transparent; cursor: pointer; }
.row-action:hover { color: var(--green-800); background: var(--green-50); }
.row-action.danger:hover { color: var(--red); background: var(--red-bg); }
.row-action svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.list-empty { padding: 18px 10px; color: var(--muted); font-size: 13px; text-align: center; }
.password-form { max-width: 420px; }
.password-form .primary-button { margin-top: 4px; }

.toast-region { position: fixed; z-index: 60; right: 18px; bottom: 18px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 250px; max-width: min(380px, calc(100vw - 28px)); padding: 12px 14px; border: 1px solid #c9e1d7; border-radius: 10px; color: var(--green-950); background: #f3fbf7; box-shadow: 0 10px 30px rgba(23,55,45,.13); font-size: 13px; font-weight: 650; animation: toast-in .18s ease-out; }
.toast.error { color: #7f2424; border-color: #efcaca; background: #fff4f4; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .control-panel { grid-template-columns: 1fr 1.4fr; }
  .month-picker { grid-column: 1 / -1; }
  .month-controls { grid-template-columns: 42px 1fr 42px; }
  .journal-header { align-items: flex-start; }
  .summary { gap: 15px; }
  .journal-toolbar { align-items: flex-start; flex-direction: column; }
  .hint { white-space: normal; }
  .table-wrap { max-height: calc(100vh - 410px); }
  .save-state { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { height: 62px; padding: 0 14px; }
  .brand-mark { width: 37px; height: 37px; }
  .brand span { display: none; }
  .topbar-actions { gap: 6px; }
  .header-button { width: 37px; padding: 0; }
  .header-button span, .user-name { display: none; }
  main { padding: 14px 10px 20px; }
  .control-panel { grid-template-columns: 1fr 1fr; gap: 10px 8px; margin-bottom: 12px; }
  .select-group label, .control-label { font-size: 12px; }
  select { padding-left: 10px; font-size: 14px; }
  .month-title { font-size: 14px; }
  .journal-card { border-radius: 11px; }
  .journal-header { min-height: 0; padding: 16px; display: block; }
  .eyebrow { font-size: 11px; }
  h1 { font-size: 22px; }
  .summary { margin-top: 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .summary span { min-width: 0; font-size: 11px; white-space: normal; }
  .summary-value { font-size: 18px; }
  .journal-toolbar { padding: 11px 14px; gap: 10px; }
  .legend { display: grid; width: 100%; grid-template-columns: 1fr 1fr; gap: 7px 12px; }
  .hint { width: 100%; min-width: 0; align-items: flex-start; line-height: 1.4; }
  .table-wrap { max-height: calc(100vh - 390px); min-height: 310px; }
  .journal-table .student-heading, .student-cell { width: 188px; min-width: 188px; }
  .journal-table .student-heading { padding: 0 10px; }
  .student-cell { padding: 0 8px; max-width: 188px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
  .row-number { width: 23px; height: 23px; margin-right: 6px; }
  .day-heading, .attendance-cell { width: 46px; min-width: 46px; }
  .cell-editor { inset: auto 0 0 !important; width: 100%; max-height: calc(100vh - 24px); overflow-y: auto; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; }
  .editor-handle { display: block; width: 42px; height: 4px; margin: -4px auto 13px; border-radius: 999px; background: #d4dbd7; }
  .editor-backdrop:not([hidden]) { display: block; }
  .settings-modal { inset: 0; transform: none; width: 100%; height: 100%; border: 0; border-radius: 0; }
  .settings-header { padding: 15px 14px; }
  .settings-tabs { padding: 0 14px; gap: 16px; overflow-x: auto; }
  .settings-tabs button { white-space: nowrap; }
  .settings-content { padding: 14px; }
  .settings-section { padding: 14px; }
  .inline-form { grid-template-columns: 1fr; }
  .inline-form .secondary-button { width: 100%; }
  .editable-list { max-height: 330px; }
  .login-screen { padding: 14px; }
  .login-card { padding: 25px 21px; border-radius: 14px; }
  .login-copy { margin: 26px 0 20px; }
  .login-copy h1 { font-size: 25px; }
  .toast-region { right: 10px; bottom: 10px; }
}

@media (prefers-reduced-motion: no-preference) {
  .cell-editor { animation: editor-in .14s ease-out; }
  @keyframes editor-in { from { opacity: 0; transform: translateY(5px) scale(.985); } to { opacity: 1; transform: none; } }
}
