:root {
  --ink: #172421;
  --muted: #677570;
  --forest: #153f3a;
  --forest-2: #205b53;
  --mint: #dcebe5;
  --cream: #f5f2e9;
  --paper: #fffefa;
  --line: #dce2dd;
  --amber: #d0913a;
  --amber-soft: #f8ead4;
  --red: #ad3f39;
  --shadow: 0 18px 55px rgba(28, 52, 47, .1);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--cream); }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% 4%, rgba(208, 145, 58, .11), transparent 24rem),
    var(--cream);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px 76px;
  position: relative;
  overflow: hidden;
}

.login-shell::before,
.login-shell::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(21, 63, 58, .11);
  border-radius: 50%;
  pointer-events: none;
}

.login-shell::before { width: 44vw; height: 44vw; left: -24vw; top: -12vw; }
.login-shell::after { width: 34vw; height: 34vw; right: -18vw; bottom: -18vw; }

.login-card {
  width: min(100%, 430px);
  padding: 42px;
  background: rgba(255, 254, 250, .94);
  border: 1px solid rgba(21, 63, 58, .13);
  border-radius: 28px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px 16px 16px 5px;
  display: grid;
  place-items: center;
  background: var(--forest);
  color: white;
  font: 700 27px Georgia, serif;
  box-shadow: 0 8px 20px rgba(21, 63, 58, .22);
  margin-bottom: 28px;
}

.brand-mark.small { width: 40px; height: 40px; font-size: 21px; border-radius: 12px 12px 12px 4px; margin: 0; }
.eyebrow { color: var(--forest-2); text-transform: uppercase; letter-spacing: .13em; font-size: .72rem; font-weight: 800; margin: 0 0 7px; }
h1, h2, p { margin-top: 0; }
h1 { font: 600 clamp(1.8rem, 3vw, 2.45rem)/1.1 Georgia, serif; letter-spacing: -.025em; margin-bottom: 12px; }
h2 { font: 600 1.35rem/1.2 Georgia, serif; letter-spacing: -.015em; margin-bottom: 8px; }
.login-intro, .page-heading p, .panel-heading p { color: var(--muted); }
.login-intro { margin-bottom: 28px; }
.login-footnote { position: absolute; bottom: 20px; color: var(--muted); font-size: .78rem; }

.stack { display: grid; gap: 17px; }
label { display: grid; gap: 7px; color: #3d4e49; font-size: .82rem; font-weight: 700; }

input, select, textarea {
  width: 100%;
  border: 1px solid #cad4ce;
  border-radius: 10px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(32, 91, 83, .12); }
.form-error { color: var(--red); min-height: 1.2em; margin: -5px 0 0; font-size: .82rem; font-weight: 650; }

.button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 15px;
  font-weight: 750;
  cursor: pointer;
  transition: transform .12s, background .12s, border-color .12s;
}

.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.primary { background: var(--forest); color: white; }
.button.primary:hover { background: #0f342f; }
.button.secondary { background: var(--amber-soft); color: #734a13; border-color: #eccd9f; }
.button.ghost { background: transparent; border-color: var(--line); }
.button.ghost:hover { background: rgba(21, 63, 58, .06); border-color: #becbc4; }
.button.danger { color: var(--red); background: #fff5f3; border-color: #efd0cc; }
.button.compact { padding: 7px 11px; font-size: .78rem; }
.button.wide { width: 100%; padding: 12px; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 68px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 0 clamp(18px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand, .user-menu { display: flex; align-items: center; gap: 12px; }
.brand > span:last-child, .user-menu > span { display: grid; }
.brand small, .user-menu small { color: var(--muted); font-size: .72rem; }
.user-menu { text-align: right; font-size: .85rem; }

.main-nav {
  padding: 0 clamp(18px, 4vw, 52px);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
}

.nav-button {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  padding: 13px 2px 11px;
  color: var(--muted);
  cursor: pointer;
  font-size: .84rem;
  font-weight: 720;
}
.nav-button span { margin-right: 4px; }
.nav-button.active { color: var(--forest); border-bottom-color: var(--forest); }

.content { max-width: 1440px; margin: 0 auto; padding: 34px clamp(18px, 4vw, 52px) 70px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 24px; }
.page-heading h1 { margin-bottom: 5px; }
.page-heading p { margin-bottom: 0; }
.class-picker { width: min(100%, 280px); }

.viewer-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  margin-bottom: 14px;
}

.viewer-control-block {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 254, 250, .82);
}

.viewer-control-block.compact-block { min-width: 280px; }
.control-heading, .viewer-summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.control-label { display: block; margin-bottom: 9px; color: var(--muted); font-size: .69rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.control-heading .control-label { margin-bottom: 0; }
.section-selection-actions { display: flex; gap: 10px; }
.text-button { border: 0; padding: 2px; background: transparent; color: var(--forest-2); font-size: .72rem; font-weight: 800; cursor: pointer; }
.text-button:hover { text-decoration: underline; }

.section-checks { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; max-height: 112px; overflow-y: auto; }
.section-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border: 1px solid #ccd7d1;
  border-radius: 999px;
  background: white;
  color: #455650;
  font-size: .73rem;
  font-weight: 750;
  cursor: pointer;
}
.section-check:has(input:checked) { border-color: var(--forest); background: var(--mint); color: var(--forest); }
.section-check input { width: 13px; height: 13px; padding: 0; accent-color: var(--forest); }
.section-check.depth-1 { border-style: dashed; }
.section-check.depth-2 { box-shadow: inset 3px 0 #a3bfb7; }

.view-switch { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; border-radius: 10px; background: #e9ebe7; }
.view-button { border: 0; padding: 7px 10px; border-radius: 7px; background: transparent; color: var(--muted); font-size: .73rem; font-weight: 800; cursor: pointer; white-space: nowrap; }
.view-button.active { background: white; color: var(--forest); box-shadow: 0 2px 8px rgba(0,0,0,.07); }
.viewer-summary { margin: 0 2px 12px; min-height: 34px; color: var(--muted); font-size: .78rem; }

.calendar-card, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 36px rgba(31, 53, 48, .055);
}

.calendar-toolbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.calendar-toolbar h2 { margin: 0 auto 0 4px; min-width: 175px; }
.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover { background: #f0f4f1; }

.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-weekdays { background: #f4f6f3; border-bottom: 1px solid var(--line); }
.calendar-weekdays span { padding: 9px 10px; color: var(--muted); font-size: .69rem; font-weight: 800; text-align: center; text-transform: uppercase; letter-spacing: .08em; }
.calendar-day {
  min-height: 112px;
  padding: 8px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: white;
  text-align: left;
  overflow: hidden;
  position: relative;
}
.calendar-day:nth-child(7n) { border-right: 0; }
.calendar-day.outside { background: #fafaf7; color: #a5aea9; }
.calendar-day.weekend { background: #f6f6f2; cursor: default; }
.calendar-day.school-out { background: repeating-linear-gradient(-45deg, #faf9f5, #faf9f5 5px, #f5f3ed 5px, #f5f3ed 10px); }
.calendar-day.allowed { cursor: pointer; }
.calendar-day.allowed:hover { box-shadow: inset 0 0 0 2px var(--forest-2); z-index: 1; }
.calendar-day.today .day-number { background: var(--forest); color: white; }
.calendar-day.locked-week::after { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--amber); }
.day-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: .78rem; font-weight: 750; margin-bottom: 5px; }
.day-events { display: grid; gap: 3px; }
.day-event {
  display: block;
  border-radius: 5px;
  padding: 3px 5px;
  background: var(--forest);
  color: white;
  font-size: .67rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-event.related { background: #dbe8e3; color: #25473f; border-left: 3px solid #6f978d; }
.day-event.color-0 { background: #205b53; }
.day-event.color-1 { background: #7b536b; }
.day-event.color-2 { background: #806022; }
.day-event.color-3 { background: #355d83; }
.day-event.color-4 { background: #7e4e3b; }
.day-event.color-5 { background: #4f648e; }
.day-event.related.color-0,
.day-event.related.color-1,
.day-event.related.color-2,
.day-event.related.color-3,
.day-event.related.color-4,
.day-event.related.color-5 { background: #e5ece8; color: #294b43; }
.more-events { color: var(--muted); font-size: .65rem; padding-left: 4px; }
.calendar-legend { display: flex; flex-wrap: wrap; gap: 16px; padding: 13px 18px; color: var(--muted); font-size: .7rem; }
.legend-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }
.legend-dot.exact { background: var(--forest); }
.legend-dot.related { background: #9bb9b1; }
.legend-dot.locked { background: var(--amber); }

.empty-state { text-align: center; padding: 70px 20px; border: 1px dashed #bdcbc4; border-radius: var(--radius); background: rgba(255,255,255,.45); }
.empty-state > span { font-size: 2rem; color: var(--forest-2); }
.empty-state h2 { margin: 12px 0 6px; }
.empty-state p { color: var(--muted); }

.exam-list { display: grid; gap: 10px; }
.exam-row {
  display: grid;
  grid-template-columns: 88px minmax(140px, 1.2fr) minmax(110px, .7fr) minmax(180px, 1.5fr) auto;
  align-items: center;
  gap: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 14px 16px;
}
.exam-date { display: grid; line-height: 1.2; }
.exam-date strong { font: 600 1.05rem Georgia, serif; }
.exam-date small, .exam-meta, .exam-note { color: var(--muted); font-size: .76rem; }
.exam-subject strong { display: block; }
.class-chip { display: inline-flex; width: fit-content; padding: 4px 8px; border-radius: 999px; background: var(--mint); color: var(--forest); font-size: .7rem; font-weight: 800; }
.exam-actions { display: flex; gap: 7px; justify-content: end; }
.empty-list { padding: 34px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 13px; }

.agenda-view { padding: 16px; display: grid; gap: 12px; }
.agenda-day { display: grid; grid-template-columns: 126px minmax(0, 1fr); gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.agenda-date { border-right: 1px solid var(--line); padding-right: 14px; }
.agenda-date strong, .agenda-date small { display: block; }
.agenda-date strong { font: 600 1rem Georgia, serif; }
.agenda-date small { margin-top: 4px; color: var(--muted); font-size: .7rem; }
.agenda-exams { display: grid; gap: 7px; }
.agenda-exam { display: grid; grid-template-columns: minmax(100px, .65fr) minmax(130px, 1fr) auto; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 9px; background: #f5f7f4; }
.agenda-exam strong { font-size: .8rem; }
.agenda-exam span { color: var(--muted); font-size: .74rem; }

.sections-view { padding: 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; align-items: start; }
.section-column { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: white; }
.section-column-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; background: #f0f4f1; border-bottom: 1px solid var(--line); }
.section-column-heading h3 { margin: 0; font: 600 1rem Georgia, serif; }
.section-column-heading span { color: var(--muted); font-size: .68rem; }
.section-column-list { display: grid; }
.section-exam { padding: 11px 14px; border-bottom: 1px solid #edf0ed; }
.section-exam:last-child { border-bottom: 0; }
.section-exam strong, .section-exam small { display: block; }
.section-exam strong { margin-top: 3px; font-size: .8rem; }
.section-exam small { color: var(--muted); font-size: .68rem; }
.section-empty { padding: 22px 14px; color: var(--muted); font-size: .75rem; text-align: center; }

.admin-nav { display: flex; overflow-x: auto; gap: 6px; padding: 5px; background: #e8e7df; border-radius: 12px; margin-bottom: 20px; width: fit-content; max-width: 100%; }
.admin-nav-button { border: 0; border-radius: 8px; background: transparent; padding: 8px 14px; color: var(--muted); font-size: .78rem; font-weight: 750; white-space: nowrap; cursor: pointer; }
.admin-nav-button.active { background: var(--paper); color: var(--forest); box-shadow: 0 2px 8px rgba(0,0,0,.07); }
.admin-grid { display: grid; grid-template-columns: minmax(280px, .75fr) minmax(350px, 1.25fr); gap: 20px; align-items: start; }
.panel { padding: 22px; }
.panel-heading { padding-bottom: 17px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel-heading h2 { margin: 0; }
.panel-heading p { font-size: .78rem; margin: 8px 0 0 40px; }
.step { color: var(--amber); font-size: .68rem; font-weight: 900; letter-spacing: .08em; }
.narrow-panel { max-width: 670px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: end; gap: 8px; }
.rule-summary { padding: 13px; border-radius: 10px; background: var(--mint); color: var(--forest); display: grid; font-size: .78rem; }

.management-list { display: grid; gap: 8px; max-height: 590px; overflow-y: auto; }
.management-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; }
.management-item.subclass { margin-left: 22px; border-left: 3px solid #a7c4bc; }
.management-main { min-width: 0; }
.management-main strong, .management-main small { display: block; overflow: hidden; text-overflow: ellipsis; }
.management-main small { color: var(--muted); font-size: .7rem; }
.management-actions { display: flex; flex-wrap: wrap; gap: 5px; flex-shrink: 0; justify-content: end; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #4d9a70; margin-right: 5px; }
.status-dot.inactive { background: #aaa; }

dialog { width: min(92vw, 520px); max-height: 90vh; border: 0; padding: 0; border-radius: 20px; box-shadow: 0 24px 90px rgba(14, 38, 33, .28); }
dialog::backdrop { background: rgba(18, 37, 33, .55); backdrop-filter: blur(3px); }
.dialog-card { padding: 26px; display: grid; gap: 16px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; }
.dialog-heading h2 { margin: 0; font-size: 1.55rem; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 5px; }

.toast-region { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { width: min(360px, calc(100vw - 40px)); padding: 12px 15px; border-radius: 11px; background: var(--forest); color: white; box-shadow: var(--shadow); font-size: .82rem; animation: toast-in .2s ease-out; }
.toast.error { background: #8e342f; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 850px) {
  .viewer-controls { grid-template-columns: 1fr; }
  .viewer-control-block.compact-block { min-width: 0; }
  .admin-grid { grid-template-columns: 1fr; }
  .exam-row { grid-template-columns: 75px 1fr auto; gap: 10px; }
  .exam-row .exam-meta, .exam-row .exam-note { grid-column: 2 / -1; }
}

@media (max-width: 640px) {
  .topbar { height: auto; min-height: 64px; padding-top: 8px; padding-bottom: 8px; }
  .brand small, .user-menu > span { display: none; }
  .main-nav { gap: 16px; overflow-x: auto; }
  .content { padding-top: 24px; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 14px; }
  .class-picker { width: 100%; }
  .calendar-card { margin-left: -12px; margin-right: -12px; border-radius: 12px; }
  .calendar-day { min-height: 82px; padding: 4px; }
  .calendar-toolbar { padding: 10px; }
  .calendar-toolbar h2 { font-size: 1.05rem; min-width: 0; }
  .calendar-toolbar #today-button { display: none; }
  .day-event { font-size: .58rem; padding: 2px 3px; }
  .calendar-legend { gap: 8px; padding: 10px; }
  .agenda-day { grid-template-columns: 1fr; gap: 9px; }
  .agenda-date { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 8px; }
  .agenda-exam { grid-template-columns: 1fr auto; }
  .agenda-exam span:nth-child(2) { grid-column: 1 / -1; }
  .exam-row { grid-template-columns: 68px 1fr; }
  .exam-actions { grid-column: 1 / -1; justify-content: stretch; }
  .exam-actions .button { flex: 1; }
  .field-row { grid-template-columns: 1fr; }
  .login-card { padding: 28px; }
}

@media print {
  body { background: white; }
  .topbar, .main-nav, .no-print, #tab-calendar, #tab-admin, .toast-region { display: none !important; }
  .content { max-width: none; padding: 0; }
  #tab-mine { display: block !important; }
  .exam-row { box-shadow: none; break-inside: avoid; }
  .exam-actions { display: none; }
}
