/* ========================================================================== 
   Ukeplan
   Struktur:
   1. Designvariabler og grunnstil
   2. Toppfelt og navigasjon
   3. Forklaring og ukeplan
   4. Kort, tilstander og fargetemaer
   5. Dialog
   6. Responsive regler
   ========================================================================== */

/* 1. Designvariabler og grunnstil
   -------------------------------------------------------------------------- */

:root {
  color: #24303a;
  background: #f7f4ee;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  --paper: #f7f4ee;
  --surface: #fffdf9;
  --surface-muted: #efede7;
  --ink: #24303a;
  --muted: #6d767d;
  --line: #d9d8d2;

  --primary: #315f73;
  --primary-soft: #dce9ec;
  --warning: #b98b20;
  --warning-soft: #fff1c9;
  --danger: #d97a64;
  --danger-soft: #f7ded7;
  --success-soft: #dfe9db;

  --radius-small: 10px;
  --radius-medium: 14px;
  --radius-large: 18px;
  --shadow-card: 0 18px 44px rgba(36, 48, 58, 0.1);

  /* Standardtema når dataene ikke har en egen farge ennå. */
  --theme-bg: #e8e8e2;
  --theme-border: #a7a79c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(49, 95, 115, 0.25);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
}

[hidden] {
  display: none !important;
}

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

/* 2. Toppfelt og navigasjon
   -------------------------------------------------------------------------- */

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

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  flex: 0 0 auto;
  border-radius: var(--radius-large);
  box-shadow: 0 10px 24px rgba(36, 48, 58, 0.14);
}

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

.subtitle,
.week-range {
  margin-bottom: 0;
  color: var(--muted);
}

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

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

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: #e6e5df;
}

.segment {
  padding: 9px 18px;
  border: 0;
  border-radius: 9px;
  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, 0.08);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

.field select,
.field input {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--ink);
}

.compact-field {
  min-width: 220px;
  margin-right: auto;
}

.week-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button,
.icon-button {
  min-height: 42px;
  border-radius: 11px;
  font-weight: 800;
}

.button {
  padding: 10px 15px;
  border: 0;
}

.icon-button {
  width: 42px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.8rem;
  line-height: 1;
}

.button-primary {
  background: var(--primary);
  color: #fff;
}

.button-secondary {
  background: var(--ink);
  color: #fff;
}

.button-quiet {
  background: #e8e6df;
  color: var(--ink);
}

/* 3. Forklaring og ukeplan
   -------------------------------------------------------------------------- */

.week-heading {
  padding: 28px 2px 15px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.lesson {
  background: var(--primary);
}

.legend-dot.changed {
  background: var(--warning);
}

.legend-dot.closed {
  background: var(--danger);
}

.legend-dot.event {
  background: #91aaa9;
}

.colour-legend {
  margin: 0 0 14px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 999px;
  background: var(--theme-bg, #e8e8e2);
}

.legend-chip i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--theme-border, #a7a79c);
}

.schedule-shell {
  overflow-x: auto;
  padding-bottom: 28px;
}

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

.schedule-cell {
  min-height: 112px;
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
}

.schedule-cell:nth-child(6n) {
  border-right: 0;
}

.schedule-cell.last-row {
  border-bottom: 0;
}

.corner-cell,
.day-header,
.time-cell {
  background: var(--surface-muted);
}

.corner-cell,
.time-cell {
  display: grid;
  align-content: center;
  text-align: center;
}

.week-number {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.week-label,
.day-name,
.period-number {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.week-label {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
}

.day-header {
  display: grid;
  align-content: center;
  min-height: 76px;
}

.day-header.is-today {
  background: #f3d78d;
}

.day-name {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.day-date {
  font-size: 1.15rem;
  font-weight: 900;
}

.period-number {
  font-size: 0.72rem;
}

.period-time {
  font-size: 0.87rem;
  font-weight: 900;
}

.empty-cell {
  display: grid;
  place-items: center;
  color: #b5b4af;
  font-size: 1.2rem;
}

.soft-empty {
  opacity: 0.35;
}

/* Kalenderdager og dagmarkører */

.day-header.has-day-marker {
  align-content: start;
  gap: 5px;
}

.day-marker {
  margin-top: 6px;
  padding: 7px 9px;
  border-left: 4px solid #9fb597;
  border-radius: var(--radius-small);
  background: rgba(223, 233, 219, 0.85);
  font-size: 0.72rem;
  line-height: 1.25;
}

.day-marker strong {
  display: block;
  color: var(--ink);
}

.day-marker span {
  color: var(--muted);
}

.day-marker.holiday {
  border-left-color: #d2a196;
  background: rgba(244, 232, 228, 0.8);
}

.day-marker.planning-day {
  border-left-color: #83aebe;
  background: rgba(227, 238, 242, 0.85);
}

.day-marker.school-start,
.day-marker.school-end {
  border-left-color: #d4a772;
  background: rgba(246, 234, 217, 0.9);
}

.day-marker.teacher-day {
  border-left-color: #b193bd;
  background: rgba(240, 230, 242, 0.88);
}

.schedule-cell.muted-day {
  background: rgba(246, 244, 238, 0.55);
}

.schedule-cell.muted-day.holiday {
  background: rgba(247, 222, 215, 0.18);
}

.schedule-cell.muted-day.planning-day {
  background: rgba(220, 233, 236, 0.24);
}

.schedule-cell.muted-day.school-start,
.schedule-cell.muted-day.school-end {
  background: rgba(246, 234, 217, 0.28);
}

/* 4. Kort, tilstander og fargetemaer
   -------------------------------------------------------------------------- */

.lesson-card,
.event-card {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px;
  border-left: 5px solid var(--theme-border, var(--primary));
  border-radius: var(--radius-small);
  background: var(--theme-bg, var(--primary-soft));
}

.lesson-card {
  height: 100%;
}

.lesson-subject {
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1.15;
}

.lesson-meta {
  color: #50606b;
  font-size: 0.75rem;
  line-height: 1.3;
}

.lesson-note {
  margin-top: 2px;
  color: #7a5147;
  font-size: 0.72rem;
  font-weight: 800;
}

.lesson-mobile-line {
  display: none;
}

/* Spesialkort */

.lesson-card.meeting-card {
  border-left-color: #8297a8;
  background: #e8eef2;
}

.lesson-card.free-card {
  border-left-color: #c4beb1;
  background: #f1eee8;
}

.event-card {
  margin-top: 6px;
  border-left-color: #91aaa9;
  background: #e8f0ef;
}

.event-card:first-child {
  margin-top: 0;
}

/* Tilstander ligger etter temaene og vinner derfor over vanlig kortfarge. */

.lesson-card.changed {
  border-left-color: var(--warning);
  background:
    linear-gradient(
      0deg,
      rgba(255, 241, 201, 0.58),
      rgba(255, 241, 201, 0.58)
    ),
    var(--theme-bg, var(--warning-soft));
}

.lesson-card.cancelled {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.lesson-card.closed-day {
  border-left-color: var(--danger);
  background: #f4e8e4;
}

/*
   Fargesystem

   Hver theme-klasse setter bare to variabler. De samme klassene fungerer derfor
   både på .lesson-card og .legend-chip, uten flere selector-lister.
*/

.theme-default {
  --theme-bg: #e8e8e2;
  --theme-border: #a7a79c;
}

/* Klasser */

.theme-class-1ima {
  --theme-bg: #edf5e6;
  --theme-border: #a8c593;
}

.theme-class-1imb {
  --theme-bg: #e4f2e8;
  --theme-border: #8fbea0;
}

.theme-class-1imc {
  --theme-bg: #eef4dc;
  --theme-border: #b2c681;
}

.theme-class-2mpa {
  --theme-bg: #f6e7d1;
  --theme-border: #c99558;
}

.theme-class-3mka {
  --theme-bg: #f4e0e5;
  --theme-border: #bd7f8d;
}

.theme-class-3mkb {
  --theme-bg: #f3dfd9;
  --theme-border: #c67f70;
}

/* Fag */

.theme-subject-programming {
  --theme-bg: #dceee7;
  --theme-border: #6f9e8d;
}

.theme-subject-story {
  --theme-bg: #dceceb;
  --theme-border: #719d9a;
}

.theme-subject-technology {
  --theme-bg: #dce9ee;
  --theme-border: #7197a5;
}

.theme-subject-vocational {
  --theme-bg: #cfe6dc;
  --theme-border: #4f8975;
}


.theme-subject-media-society-1 {
  --theme-bg: #f7ecd9;
  --theme-border: #c99d68;
}

.theme-subject-media-society-2 {
  --theme-bg: #f6e6d3;
  --theme-border: #c58e59;
}

.theme-subject-media-society,
.theme-subject-media-society-3 {
  --theme-bg: #f3deca;
  --theme-border: #b9794b;
}

.theme-subject-science {
  --theme-bg: #e3efdc;
  --theme-border: #7c9f69;
}

.theme-subject-mathematics {
  --theme-bg: #dce9f4;
  --theme-border: #6f95b5;
}

.theme-subject-english {
  --theme-bg: #f3e0e1;
  --theme-border: #b8797f;
}


.theme-subject-physical-education {
  --theme-bg: #eceae4;
  --theme-border: #a6a198;
}

.theme-subject-design {
  --theme-bg: #ebe4f1;
  --theme-border: #9d86ae;
}

.theme-subject-production {
  --theme-bg: #f1deda;
  --theme-border: #bd7f73;
}

/* Lærere */

.theme-teacher-ahe {
  --theme-bg: #dcefed;
  --theme-border: #6f9f9c;
}

.theme-teacher-kw {
  --theme-bg: #e0eaf4;
  --theme-border: #7899b5;
}

.theme-teacher-dkk {
  --theme-bg: #f8efcf;
  --theme-border: #bba552;
}

.theme-teacher-iad {
  --theme-bg: #e9e6f5;
  --theme-border: #9690bd;
}

.theme-teacher-eoo {
  --theme-bg: #f4e2e9;
  --theme-border: #bb849b;
}

.theme-teacher-cup {
  --theme-bg: #f6e2d8;
  --theme-border: #c88b70;
}

.theme-teacher-jes {
  --theme-bg: #e6efda;
  --theme-border: #89a368;
}

.theme-teacher-cab {
  --theme-bg: #f6e9d5;
  --theme-border: #c89b62;
}

.theme-teacher-mn {
  --theme-bg: #e3e9f7;
  --theme-border: #8595c0;
}

/* 5. Dialog
   -------------------------------------------------------------------------- */

#editDialog {
  width: min(720px, calc(100% - 24px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-large);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
}

#editDialog::backdrop {
  background: rgba(24, 31, 36, 0.52);
  backdrop-filter: blur(3px);
}

#editForm {
  padding: 24px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.dialog-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 2rem;
}

.dialog-intro {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.full-width {
  grid-column: 1 / -1;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.checkbox-row input {
  width: auto;
  min-height: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.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: 0.82rem;
}

.saved-changes-list {
  display: grid;
  gap: 8px;
}

.saved-change {
  display: flex;
  align-items: center;
  justify-content: space-between;
  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: 0.76rem;
}

.empty-saved-list {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

/* 6. Responsive regler
   -------------------------------------------------------------------------- */

/* Nettbrett og smale vinduer */
@media (max-width: 820px) {
  .app-header,
  .toolbar,
  .week-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .compact-field {
    min-width: 0;
    margin-right: 0;
  }

  .week-controls {
    justify-content: space-between;
  }

  .week-controls .button {
    flex: 1;
  }

  .legend {
    margin-top: 4px;
  }
}

/* Mobil */
@media (max-width: 720px) {
  :root {
    --shadow-card: 0 10px 28px rgba(36, 48, 58, 0.09);
  }

  body {
    background: #f8f5ef;
  }

  .app-header,
  main {
    width: min(1500px, calc(100% - 20px));
  }

  .app-header {
    gap: 14px;
    padding: 18px 0 14px;
  }

  .brand {
    align-items: flex-start;
    gap: 12px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-medium);
  }

  h1 {
    font-size: clamp(1.85rem, 9vw, 2.6rem);
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .toolbar {
    gap: 12px;
    padding: 12px;
    border-radius: 16px;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1;
    padding-inline: 10px;
  }

  .week-heading {
    gap: 10px;
    padding-top: 18px;
  }

  .legend {
    gap: 8px 12px;
    font-size: 0.74rem;
  }

  .colour-legend {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .legend-chip {
    white-space: nowrap;
  }

  .schedule-shell {
    margin-inline: -10px;
    padding-inline: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .schedule {
    grid-template-columns: 88px repeat(5, minmax(128px, 1fr));
    min-width: 760px;
    border-radius: var(--radius-medium);
  }

  .schedule-cell {
    min-height: 82px;
    padding: 7px;
  }

  .day-header {
    min-height: 68px;
  }

  .day-name {
    font-size: 0.68rem;
    letter-spacing: 0.06em;
  }

  .day-date {
    font-size: 0.94rem;
  }

  .time-cell {
    padding-inline: 4px;
  }

  .period-number {
    font-size: 0.66rem;
  }

  .period-time {
    font-size: 0.76rem;
  }

  .lesson-card,
  .event-card {
    min-height: 58px;
    gap: 4px;
    padding: 8px;
    border-left-width: 4px;
    border-radius: 9px;
  }

  .lesson-subject,
  .lesson-meta {
    display: none;
  }

  .lesson-mobile-line {
    display: block;
    font-size: 0.76rem;
    font-weight: 900;
    line-height: 1.24;
  }

  .lesson-note {
    font-size: 0.66rem;
    line-height: 1.2;
  }

  .event-card .lesson-subject,
  .meeting-card .lesson-subject,
  .free-card .lesson-subject,
  .cancelled .lesson-subject {
    display: block;
    font-size: 0.78rem;
  }

  .event-card .lesson-meta,
  .meeting-card .lesson-meta,
  .free-card .lesson-meta,
  .cancelled .lesson-meta {
    display: block;
    font-size: 0.68rem;
  }

  .day-marker {
    padding: 6px 7px;
    font-size: 0.66rem;
  }

  #editForm {
    padding: 18px;
  }

  .saved-change {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Små mobiler og dialog */
@media (max-width: 560px) {
  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .full-width {
    grid-column: auto;
  }
}

/* Liggende mobil */
@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: flex-end;
  }

  .compact-field {
    flex: 1 1 180px;
  }

  .week-heading {
    padding-top: 14px;
  }

  .schedule {
    grid-template-columns: 96px repeat(5, minmax(145px, 1fr));
    min-width: 900px;
  }

  .schedule-cell {
    min-height: 72px;
  }

  .lesson-card,
  .event-card {
    min-height: 50px;
    padding: 7px;
  }
}

/* Redusert bevegelse */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
