:root {
  --paper: #f7f4ee;
  --surface: #fffdf9;
  --ink: #24303a;
  --muted: #6d767d;
  --line: #d9d8d2;
  --blue: #315f73;
  --blue-soft: #dce9ec;
  --yellow: #f3d78d;
  --coral: #d97a64;
  --coral-soft: #f7ded7;
  --green-soft: #dfe9db;
  --shadow: 0 18px 44px rgba(36, 48, 58, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, select, input { font: inherit; }
button { cursor: pointer; }

.app-header,
main { width: min(1500px, calc(100% - 32px)); margin-inline: auto; }

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 34px 0 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(2rem, 4vw, 3.5rem); line-height: .95; letter-spacing: -.045em; }
h2 { margin-bottom: 0; }
.subtitle, .week-range { color: var(--muted); margin-bottom: 0; }

.toolbar,
.week-heading {
  display: flex;
  gap: 18px;
  align-items: end;
  justify-content: space-between;
}

.toolbar {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.62);
}

.segmented { display: inline-flex; padding: 4px; border-radius: 12px; background: #e6e5df; }
.segment { border: 0; border-radius: 9px; padding: 9px 18px; background: transparent; color: var(--muted); font-weight: 700; }
.segment.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 3px 10px rgba(0,0,0,.08); }

.field { display: grid; gap: 7px; color: var(--muted); font-size: .83rem; font-weight: 700; }
.field select, .field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: var(--ink);
  padding: 10px 11px;
  min-height: 42px;
}
.compact-field { min-width: 220px; margin-right: auto; }

.week-controls { display: flex; align-items: center; gap: 8px; }
.button, .icon-button {
  border: 0;
  border-radius: 11px;
  min-height: 42px;
  padding: 10px 15px;
  font-weight: 800;
}
.button-primary { background: var(--blue); color: white; }
.button-secondary { color: white; background: var(--ink); }
.button-quiet { color: var(--ink); background: #e8e6df; }
.icon-button { width: 42px; padding: 0; background: var(--surface); border: 1px solid var(--line); font-size: 1.8rem; line-height: 1; }

.week-heading { padding: 28px 2px 15px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-dot.lesson { background: var(--blue); }
.legend-dot.changed { background: var(--yellow); }
.legend-dot.closed { background: var(--coral); }

.schedule-shell { overflow-x: auto; padding-bottom: 28px; }
.schedule {
  min-width: 1060px;
  display: grid;
  grid-template-columns: 128px repeat(5, minmax(175px, 1fr));
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.schedule-cell {
  min-height: 112px;
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.7);
}
.schedule-cell:nth-child(6n) { border-right: 0; }
.schedule-cell.last-row { border-bottom: 0; }

.corner-cell,
.day-header,
.time-cell { background: #efede7; }
.corner-cell { display: grid; align-content: center; text-align: center; }
.week-number { font-size: 2rem; font-weight: 900; line-height: 1; }
.week-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 800; }
.day-header { min-height: 76px; display: grid; align-content: center; }
.day-name { font-size: .78rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.day-date { font-size: 1.15rem; font-weight: 900; }
.day-header.is-today { background: var(--yellow); }
.time-cell { display: grid; align-content: center; text-align: center; }
.period-number { font-size: .72rem; color: var(--muted); font-weight: 800; text-transform: uppercase; }
.period-time { font-size: .87rem; font-weight: 900; }

.lesson-card {
  height: 100%;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px;
  border-left: 5px solid var(--blue);
  border-radius: 10px;
  background: var(--blue-soft);
}
.lesson-card.changed { border-color: #b98b20; background: #fff1c9; }
.lesson-card.cancelled { border-color: var(--coral); background: var(--coral-soft); }
.lesson-card.closed-day { border-color: var(--coral); background: #f4e8e4; }
.lesson-subject { font-size: .9rem; font-weight: 900; line-height: 1.15; }
.lesson-meta { color: #50606b; font-size: .75rem; line-height: 1.3; }
.lesson-note { margin-top: 2px; color: #7a5147; font-size: .72rem; font-weight: 800; }
.empty-cell { color: #b5b4af; display: grid; place-items: center; font-size: 1.2rem; }

#editDialog {
  width: min(720px, calc(100% - 24px));
  border: 0;
  border-radius: 18px;
  padding: 0;
  box-shadow: 0 28px 70px rgba(0,0,0,.28);
}
#editDialog::backdrop { background: rgba(24,31,36,.52); backdrop-filter: blur(3px); }
#editForm { padding: 24px; }
.dialog-header { display: flex; justify-content: space-between; gap: 24px; }
.dialog-close { border: 0; background: transparent; font-size: 2rem; color: var(--muted); }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
.full-width { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

@media (max-width: 820px) {
  .app-header, .toolbar, .week-heading { align-items: stretch; flex-direction: column; }
  .compact-field { min-width: 0; margin-right: 0; }
  .week-controls { justify-content: space-between; }
  .week-controls .button { flex: 1; }
  .legend { margin-top: 4px; }
}

@media (max-width: 560px) {
  .app-header, main { width: min(100% - 20px, 1500px); }
  .dialog-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
}

[hidden] { display: none !important; }

.legend-dot.event { background: #9fb7b6; }
.colour-legend { margin: 0 0 14px; }
.legend-chip {
  --theme-bg: #e8eee8;
  --theme-border: #9fb7a4;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--theme-bg);
  border: 1px solid rgba(0,0,0,.06);
}
.legend-chip i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--theme-border);
}

.theme-class-1ima, .theme-subject-programming { --theme-bg: #e8f0dc; --theme-border: #9ab079; }
.theme-class-1imb, .theme-subject-story { --theme-bg: #e3eef2; --theme-border: #83aebe; }
.theme-class-1imc, .theme-subject-media-society { --theme-bg: #f0e6f2; --theme-border: #b193bd; }
.theme-class-2mpa, .theme-subject-design { --theme-bg: #f6ead9; --theme-border: #d4a772; }
.theme-class-3mkb, .theme-subject-production { --theme-bg: #f3e1dc; --theme-border: #cf9284; }
.theme-default { --theme-bg: #e8e8e2; --theme-border: #a7a79c; }
.lesson-card.theme-class-1ima,
.lesson-card.theme-class-1imb,
.lesson-card.theme-class-1imc,
.lesson-card.theme-class-2mpa,
.lesson-card.theme-class-3mkb,
.lesson-card.theme-subject-programming,
.lesson-card.theme-subject-story,
.lesson-card.theme-subject-media-society,
.lesson-card.theme-subject-design,
.lesson-card.theme-subject-production,
.lesson-card.theme-default {
  background: var(--theme-bg);
  border-left-color: var(--theme-border);
}
.lesson-card.changed {
  background: linear-gradient(0deg, rgba(255, 241, 201, .58), rgba(255, 241, 201, .58)), var(--theme-bg, #fff1c9);
  border-left-color: #b98b20;
}

.day-header.has-day-marker { align-content: start; gap: 5px; }
.day-marker {
  margin-top: 6px;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(223, 233, 219, .85);
  border-left: 4px solid #9fb597;
  font-size: .72rem;
  line-height: 1.25;
}
.day-marker strong { display: block; color: var(--ink); }
.day-marker span { color: var(--muted); }
.day-marker.holiday { background: rgba(244, 232, 228, .8); border-left-color: #d2a196; }
.day-marker.planning-day { background: rgba(227, 238, 242, .85); border-left-color: #83aebe; }
.day-marker.school-start, .day-marker.school-end { background: rgba(246, 234, 217, .9); border-left-color: #d4a772; }
.day-marker.teacher-day { background: rgba(240, 230, 242, .88); border-left-color: #b193bd; }

.schedule-cell.muted-day { background: rgba(246, 244, 238, .55); }
.schedule-cell.muted-day.holiday { background: rgba(247, 222, 215, .18); }
.schedule-cell.muted-day.planning-day { background: rgba(220, 233, 236, .24); }
.schedule-cell.muted-day.school-start,
.schedule-cell.muted-day.school-end { background: rgba(246, 234, 217, .28); }
.soft-empty { opacity: .35; }

.meeting-card { background: #e8eef2; border-left-color: #8297a8; }
.free-card { background: #f1eee8; border-left-color: #c4beb1; }
.event-card {
  margin-top: 6px;
  padding: 10px;
  border-left: 5px solid #91aaa9;
  border-radius: 10px;
  background: #e8f0ef;
}
.event-card:first-child { margin-top: 0; }

.dialog-intro { color: var(--muted); font-size: .86rem; margin: 8px 0 0; }
.saved-changes-panel {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.saved-changes-header h3 { margin: 0 0 4px; font-size: 1rem; }
.saved-changes-header p { margin: 0 0 12px; color: var(--muted); font-size: .82rem; }
.saved-changes-list { display: grid; gap: 8px; }
.saved-change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffaf2;
}
.saved-change span { display: block; margin-top: 2px; color: var(--muted); font-size: .76rem; }
.empty-saved-list { color: var(--muted); font-size: .86rem; margin: 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.checkbox-row input { width: auto; min-height: auto; }

/* Identitet / app-følelse */
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand-mark {
  flex: 0 0 auto;
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(36, 48, 58, .14);
}
.lesson-mobile-line { display: none; }

/* Mobiltilpasning: behold ukeplanen, men gjør den lettere å lese på liten skjerm. */
@media (max-width: 720px) {
  :root { --shadow: 0 10px 28px rgba(36, 48, 58, .09); }
  body { background: #f8f5ef; }
  .app-header {
    padding: 18px 0 14px;
    gap: 14px;
  }
  .brand { align-items: flex-start; gap: 12px; }
  .brand-mark { width: 46px; height: 46px; border-radius: 14px; }
  h1 { font-size: clamp(1.85rem, 9vw, 2.6rem); }
  .subtitle { font-size: .9rem; }
  .toolbar { padding: 12px; border-radius: 16px; gap: 12px; }
  .segmented { width: 100%; }
  .segment { flex: 1; padding-inline: 10px; }
  .week-heading { padding-top: 18px; gap: 10px; }
  .legend { gap: 8px 12px; font-size: .74rem; }
  .colour-legend { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .legend-chip { white-space: nowrap; }
  .schedule-shell {
    margin-inline: -10px;
    padding-inline: 10px;
    -webkit-overflow-scrolling: touch;
  }
  .schedule {
    min-width: 760px;
    grid-template-columns: 88px repeat(5, minmax(128px, 1fr));
    border-radius: 14px;
  }
  .schedule-cell {
    min-height: 82px;
    padding: 7px;
  }
  .day-header { min-height: 68px; }
  .day-name { font-size: .68rem; letter-spacing: .06em; }
  .day-date { font-size: .94rem; }
  .time-cell { padding-inline: 4px; }
  .period-number { font-size: .66rem; }
  .period-time { font-size: .76rem; }
  .lesson-card,
  .event-card {
    min-height: 58px;
    padding: 8px;
    border-left-width: 4px;
    border-radius: 9px;
    gap: 4px;
  }
  .lesson-subject { display: none; }
  .lesson-mobile-line {
    display: block;
    font-size: .76rem;
    line-height: 1.24;
    font-weight: 900;
  }
  .lesson-meta { display: none; }
  .lesson-note { font-size: .66rem; line-height: 1.2; }
  .event-card .lesson-subject { display: block; font-size: .78rem; }
  .event-card .lesson-meta { display: block; font-size: .68rem; }
  .meeting-card .lesson-subject,
  .free-card .lesson-subject,
  .cancelled .lesson-subject { display: block; font-size: .78rem; }
  .meeting-card .lesson-meta,
  .free-card .lesson-meta,
  .cancelled .lesson-meta { display: block; font-size: .68rem; }
  .day-marker { padding: 6px 7px; font-size: .66rem; }
  #editForm { padding: 18px; }
  .saved-change { align-items: stretch; flex-direction: column; }
}

/* Liggende mobil: bruk litt mer av bredden og komprimer høyden. */
@media (max-width: 940px) and (orientation: landscape) {
  .app-header { padding-top: 14px; padding-bottom: 10px; }
  .subtitle { display: none; }
  .toolbar { flex-direction: row; flex-wrap: wrap; align-items: end; }
  .compact-field { flex: 1 1 180px; }
  .week-heading { padding-top: 14px; }
  .schedule { min-width: 900px; grid-template-columns: 96px repeat(5, minmax(145px, 1fr)); }
  .schedule-cell { min-height: 72px; }
  .lesson-card, .event-card { min-height: 50px; padding: 7px; }
}

/* Arbeidstid ligger under kortene og fanger aldri trykk. */
.schedule-cell { position: relative; min-width: 0; }
.worktime-background { position: absolute; left: 0; right: 0; background: #e5eae7; border-left: 3px solid #94a69b; pointer-events: none; z-index: 0; }
.schedule-cell > :not(.worktime-background) { position: relative; z-index: 1; }
.worktime-hint { display: flex; align-items: center; gap: 8px; color: #56675e; font-size: .82rem; }
.worktime-swatch { display: inline-block; flex: 0 0 auto; width: 12px; height: 12px; background: #e5eae7; border-left: 3px solid #94a69b; }
.worktime-label { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-size: .72rem; color: #46594e; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
#worktimeDialog { width: min(580px, calc(100% - 24px)); max-height: 90dvh; overflow-y: auto; border: 0; border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
#worktimeDialog::backdrop { background: rgba(24,31,36,.52); }
#worktimeTeacher { margin: 18px 0 8px; font-weight: 800; }
.worktime-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.worktime-row legend { font-weight: 700; font-size: .85rem; }
#worktimeError { color: #a22e24; }

/* Alle fem dager får plass i liggende visning, uten vannrett rulling. */
@media (orientation: landscape) {
  .schedule { min-width: 0; width: 100%; grid-template-columns: 64px repeat(5, minmax(0, 1fr)); }
  .schedule-shell { margin-inline: 0; padding-inline: 0; }
  .lesson-card, .event-card, .day-marker { min-width: 0; overflow-wrap: anywhere; }
}
@media (orientation: landscape) and (max-width: 1100px) {
  .app-header, main { width: calc(100% - 20px); }
  .app-header { flex-direction: row; align-items: center; padding: 10px 0; }
  .brand-mark { width: 40px; height: 40px; }
  h1 { font-size: 1.8rem; }
  .subtitle, .eyebrow { display: none; }
  .toolbar { flex-direction: row; flex-wrap: wrap; gap: 10px; padding: 10px; align-items: end; }
  .segmented { width: auto; }
  .compact-field { min-width: 100px; flex: 1; }
  .week-heading { gap: 10px; padding-top: 14px; }
  .schedule-cell { padding: 5px; min-height: 78px; }
  .day-header { min-height: 65px; }
  .day-name { font-size: .65rem; letter-spacing: 0; }
  .day-date { font-size: .9rem; }
  .period-number { font-size: .6rem; }
  .period-time { font-size: .72rem; }
  .lesson-card, .event-card { padding: 6px; border-left-width: 3px; }
  .lesson-subject { display: block; font-size: .72rem; }
  .lesson-meta { display: block; font-size: .65rem; }
  .lesson-mobile-line { display: none; }
  .worktime-label { font-size: .65rem; flex-wrap: wrap; }
  .colour-legend { flex-wrap: wrap; }
}

.theme-class-3mka { --theme-bg: #f6edcf; --theme-border: #bda454; }
.theme-subject-technology { --theme-bg: #deede8; --theme-border: #76a495; }
.lesson-card.theme-class-3mka, .lesson-card.theme-subject-technology {
  background: var(--theme-bg);
  border-left-color: var(--theme-border);
}
