:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2530;
  --muted: #6b7686;
  --line: #dde2e9;
  --accent: #1f5fa8;
  --accent-ink: #ffffff;
  --ok: #2e7d32;
  --warn: #b26a00;
  --bad: #c62828;
  --okbg: #e6f4e6;
  --warnbg: #fff3df;
  --badbg: #fdeaea;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}
header {
  display: flex; align-items: center; gap: 16px;
  background: var(--accent); color: var(--accent-ink); padding: 8px 20px;
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 17px; margin: 0 12px 0 0; font-weight: 600; }
nav button {
  background: transparent; border: none; color: #cfe0f3; font: inherit;
  padding: 6px 10px; cursor: pointer; border-radius: 6px;
}
nav button.active, nav button:hover { background: rgba(255,255,255,.16); color: #fff; }
header .spacer { flex: 1; }
header select { border: none; border-radius: 6px; padding: 4px 6px; font: inherit; }
header .who { font-size: 12.5px; opacity: .9; }
header .linkbtn {
  background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff;
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font: inherit;
}
main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 16px;
}
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar label { color: var(--muted); font-size: 12.5px; }
input, select, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=date], select {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: #fff;
}
button.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 6px 14px; cursor: pointer;
}
button.primary:hover { filter: brightness(1.1); }
button.ghost {
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; color: var(--ink);
}
button.danger { color: var(--bad); }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid th, table.grid td {
  border: 1px solid var(--line); padding: 4px 7px; text-align: right; white-space: nowrap;
}
table.grid th { background: #eef1f5; font-weight: 600; position: sticky; top: 46px; }
table.grid td.name, table.grid th.name { text-align: left; max-width: 330px;
  overflow: hidden; text-overflow: ellipsis; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: #f0f5fb; }
table.grid td.ok { background: var(--okbg); color: var(--ok); }
table.grid td.warn { background: var(--warnbg); color: var(--warn); }
table.grid td.bad { background: var(--badbg); color: var(--bad); }
table.grid tfoot td { font-weight: 600; background: #eef1f5; }
table.grid input.hrs {
  width: 52px; text-align: right; border: 1px solid transparent; background: transparent;
  border-radius: 4px; padding: 2px 4px;
}
table.grid input.hrs:hover { border-color: var(--line); background: #fff; }
table.grid input.hrs:focus { border-color: var(--accent); background: #fff; outline: none; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; }
.badge.kurs { background: #e3edf8; color: #1f5fa8; }
.badge.projekt { background: #efe6f7; color: #6a3a9e; }
.badge.lopande { background: #e6f1e6; color: #2e7d32; }
.badge.requested { background: var(--warnbg); color: var(--warn); }
.badge.rejected { background: var(--badbg); color: var(--bad); }
.muted { color: var(--muted); }
.meta-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 4px 18px; font-size: 13px; }
.meta-list div b { color: var(--muted); font-weight: 500; margin-right: 6px; }
#login-view { max-width: 360px; margin: 80px auto; }
#login-view input { width: 100%; margin-bottom: 10px; }
#login-view button { width: 100%; }
.error { color: var(--bad); font-size: 13px; margin: 6px 0; }
.formrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.crumb { background: none; border: none; color: var(--accent); cursor: pointer;
  padding: 0; font: inherit; }
.crumb:hover { text-decoration: underline; }
#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #2b3442; color: #fff; padding: 8px 18px; border-radius: 8px;
  opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50;
  max-width: min(640px, calc(100vw - 32px)); text-align: center;
}
#toast.show { opacity: 1; }

/* roller */
table.grid tr.self td { background: #f2f7ec; }
.badge.self { background: #dcebd0; color: #2e5e1e; margin-left: 6px; }
.badge.role-admin { background: #fdeaea; color: #8e1f1f; }
.badge.role-studierektor { background: #e3edf8; color: #1f5fa8; }
.badge.role-larare { background: #e6f1e6; color: #2e7d32; }
.notice { border-left: 4px solid var(--warn); background: var(--warnbg); }
.help { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.help b { color: var(--ink); font-weight: 600; }
td.warn-cell { color: var(--warn); }

/* historik */
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.hist-entry { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }
.hist-entry.src-import { border-left-color: #6a3a9e; }
.hist-entry.src-system { border-left-color: var(--muted); }
.hist-entry.src-okänd { border-left-color: var(--bad); }
.hist-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; font-size: 12.5px; margin-bottom: 2px; }
.hist-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-who { font-weight: 600; }
.badge.src { background: #eef1f5; color: var(--muted); }
.hist-item { font-size: 13px; padding: 1px 0; }
.hist-what { color: var(--muted); }
.hist-item.insert .hist-what { color: var(--ok); }
.hist-item.delete .hist-what { color: var(--bad); }
.hist-fields { display: flex; flex-wrap: wrap; gap: 4px 14px; padding-left: 12px; font-size: 12.5px; }
.hist-field .old { color: var(--muted); text-decoration: line-through; }
.hist-more { font-size: 12.5px; padding-left: 12px; }
.hist-footer { margin-top: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12.5px; }
table.grid tr.inactive td { color: var(--muted); background: #fafbfc; }

/* osparade ändringar */
table.grid td.dirty { background: #fff4c2; }
table.grid td.dirty input.hrs, table.grid td.dirty select { background: #fff4c2; font-weight: 600; }
table.grid td.invalid { background: var(--badbg); }
table.grid td.invalid input.hrs { border-color: var(--bad); color: var(--bad); }
table.grid td.conflict { outline: 2px solid var(--bad); outline-offset: -2px; }
.savebar {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
  margin-top: 10px; padding: 10px 14px; background: #fff8dc; border: 1px solid #e8d48a;
  border-radius: 8px; box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}
.savebar[hidden] { display: none; }
.savebar-text { flex: 1; font-weight: 600; color: #6b5300; }
button.primary:disabled { opacity: .5; cursor: default; filter: none; }
.conflict-notice {
  border-left: 4px solid var(--bad); background: var(--badbg); padding: 8px 12px;
  margin-bottom: 10px; border-radius: 4px; font-size: 13px;
}
.hover-hint { font-size: 12px; margin: 6px 0 0; }

/* kurstillfällen */
.badge.inst { background: #fff1d6; color: #8a5a00; font-variant-numeric: tabular-nums;
  white-space: nowrap; margin-left: 6px; }
td .badge.inst:first-child { margin-left: 0; }
.edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px 16px; margin: 10px 0; }
.edit-row { display: flex; flex-direction: column; gap: 3px; }
.edit-row > span { color: var(--muted); font-size: 12.5px; }
.edit-row small { font-size: 11.5px; }
.siblings { margin: 10px 0 0; }
.name-cell { display: flex; align-items: center; gap: 6px; max-width: 316px; }
.name-cell .lbl { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; text-align: left; }
.name-cell .badge { flex: 0 0 auto; margin-left: 0; }
.edit-row input, .edit-row select { width: 100%; box-sizing: border-box; }
table.grid th.left { text-align: left; }

/* samläsning */
.badge.coread { background: #dff1ee; color: #1d6b5f; white-space: nowrap; }
.warn-note { background: var(--warnbg); color: var(--warn); padding: 6px 10px;
  border-radius: 6px; margin: 8px 0; }
input.stud { width: 64px; text-align: right; }
table.coread-table { width: auto; min-width: 60%; }
h3 { font-size: 15px; margin: 18px 0 4px; }
table.grid tr.subrow td { color: var(--muted); font-size: 12px; background: #fafbfc;
  padding-top: 2px; padding-bottom: 2px; }
table.grid tr.subrow td.name { padding-left: 14px; }
table.grid tr.subrow .crumb { font-size: 12px; }
.sub-arrow { color: var(--muted); flex: 0 0 auto; }

/* fördela tid */
td.row-actions { white-space: nowrap; }
td.row-actions .ghost + .ghost { margin-left: 4px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 28, 40, .35);
  display: flex; align-items: flex-start; justify-content: center; z-index: 40;
  padding: 6vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; padding: 18px 22px; width: 100%;
  max-width: 620px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.modal h2 { margin: 0 0 2px; }
.spread-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; }
.spread-row label { display: flex; flex-direction: column; gap: 3px; }
.spread-row label span { color: var(--muted); font-size: 12.5px; }
.spread-modes { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.spread-modes label.radio { display: flex; align-items: center; gap: 6px; }
input.num { width: 80px; text-align: right; }
input.num.inactive { background: #f3f4f6; color: var(--muted); }
.spread-preview table { margin-top: 6px; }
.spread-preview tr.other-year td { background: #f7f9fc; }

/* tidslinje */
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden; margin: 0 0 10px; }
.view-toggle .seg { border: none; background: #fff; padding: 4px 14px; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--muted); }
.view-toggle .seg + .seg { border-left: 1px solid var(--line); }
.view-toggle .seg.on { background: var(--accent); color: var(--accent-ink); }
.tl-scroll { overflow-x: auto; }
.tl { min-width: 980px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.tl-row { display: grid; grid-template-columns: minmax(220px, 320px) 112px 1fr 70px 78px;
  align-items: center; border-bottom: 1px solid var(--line); min-height: 34px; }
.tl-row:last-child { border-bottom: none; }
.tl-row.self { background: #f2f7ec; }
.tl-head, .tl-foot { background: #eef1f5; font-weight: 600; }
.tl-name { padding: 3px 8px; min-width: 0; }
.tl-name .name-cell { max-width: none; }
.tl-status { padding: 0 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.tl-total { text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.tl-actions { padding: 0 6px; text-align: right; }
.tl-empty { grid-column: 1 / -1; padding: 8px; }
.tl-months { display: grid; grid-template-columns: repeat(var(--n, 12), 1fr); align-self: stretch;
  align-items: center; }
.tl-months span { text-align: center; border-left: 1px solid var(--line); padding: 6px 0;
  font-variant-numeric: tabular-nums; }
.tl-foot .tl-months span { font-size: 12px; }
.tl-foot .tl-months span.over { color: var(--bad); }
.tl-track { position: relative; align-self: stretch; min-height: 32px;
  background-image: linear-gradient(to right, var(--line) 1px, transparent 1px);
  background-size: calc(100% / var(--n, 12)) 100%; }
.tl-bar { position: absolute; top: 4px; bottom: 4px; display: flex; overflow: hidden;
  border: 1px solid #93ad5f; border-radius: 3px; background: #fff; }
.tl-cell { flex: 1; background: #c9dc9f; }
.tl-label { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 6px;
  font-size: 12px; color: #2c3a12; white-space: nowrap; overflow: hidden; }
.tl-bar.requested { border-color: #d9a441; }
.tl-bar.requested .tl-cell { background: #ffdf9e; }
.tl-bar.rejected { border-color: #c7cbd2; opacity: .55; }
.tl-bar.rejected .tl-cell { background: #e5e7eb; }
.tl-bar.sub { border-style: dashed; top: 7px; bottom: 7px; }
.tl-bar.sub .tl-cell { background: #e4edd0; }
.tl-sub { background: #fafbfc; min-height: 28px; }
.tl-sub .tl-track { min-height: 26px; }
.tl-bar.outside { border-color: #d98a2b; z-index: 1; }
.tl-bar.outside .tl-cell { background: #ffd8a8; }

/* Ingående grupper från Kursredan */
table.groups-table tr.group-head td { background: #f7f9fb; }
table.groups-table tr.subrow td.name { padding-left: 24px; font-weight: 400; }
table.groups-table tr.struck td { color: var(--muted); text-decoration: line-through; }
.edit-grid input:disabled, .edit-grid select:disabled { background: #f3f5f8; color: var(--muted); }

/* periodväljare och perioder över årsskiften */
.period-picker { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.period-picker > label { color: var(--muted); font-size: 12.5px; }
.period-picker .muted { font-size: 12px; }
.period-custom { display: inline-flex; gap: 6px; align-items: center; }
.wide-scroll { overflow-x: auto; }
.wide-scroll table.grid th { position: static; }
.other-h { font-size: 12px; }
#year-label[hidden] { display: none; }
.export-bar { margin: 10px 0 0; }
.export-bar > label { color: var(--muted); font-size: 12.5px; }

/* Årsmål och oplanerad tid i personvyn */
.sum-line { margin: 10px 0 4px; }
.bad-text { color: var(--bad); }
.target-src { font-size: 12px; }
button.link { background: none; border: none; padding: 0; font: inherit; font-size: 12px;
  color: var(--accent); cursor: pointer; }
button.link:hover { text-decoration: underline; }

/* ny person / ändra uppgifter */
.person-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 12px 0; }
.person-form label { display: flex; flex-direction: column; gap: 3px; }
.person-form label span { color: var(--muted); font-size: 12.5px; }
.person-form .wide { grid-column: 1 / -1; }
.person-form input[type=text], .person-form select { font: inherit; padding: 5px 7px; }
.toolbar .push-right, .export-bar .push-right { margin-left: auto; }

/* omfattning och ledighet */
table.periods { margin: 6px 0 10px; }
table.months-avail { margin: 4px 0 12px; }
table.months-avail tr.muted td { color: var(--muted); font-style: italic; }
.period-form .toolbar { flex-wrap: wrap; gap: 6px; }
.period-form input[type=date] { font: inherit; padding: 3px 5px; }
table.periods th, table.periods td { text-align: left; }
.card h3 { font-size: 14px; margin: 16px 0 6px; }
.pct-hint { display: block; font-size: 12.5px; margin: 2px 0 0; min-height: 1em; }

/* budget och obemannat */
table.months-avail tr.nn-row td { background: #fff4d6; font-weight: 600; }

