:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e3e6ea;
  --line2: #eef0f3;
  --accent: #1d4ed8;
  --err: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --name-w: 150px;
  --row-h: 22px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 24px 0 8px; }
h3 { margin: 0 0 12px; }
button, .filebtn {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
button.ghost { background: #fff; color: var(--accent); }
button.danger { background: #fff; color: var(--err); border-color: var(--err); }
button.small { padding: 2px 8px; font-size: 12px; }
.filebtn { display: inline-block; background: #fff; color: var(--accent); }
.filebtn input { display: none; }
input, select, textarea { font: inherit; padding: 4px 6px; border: 1px solid #cbd2d9; border-radius: 5px; background: #fff; }
.muted { color: var(--muted); }

.top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 24px;
  background: #fff; border-bottom: 1px solid var(--line); padding: 10px 16px; flex-wrap: wrap;
}
.brand .sub { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--ink); border: 0; border-radius: 6px; padding: 6px 12px; }
.tabs button.active { background: #e8eefc; color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--err); color: #fff; font-size: 11px; }
.badge:empty { display: none; }
.saved { margin-left: auto; color: var(--muted); font-size: 12px; }

main { padding: 12px 16px 40px; }
.view { display: none; }
.view.active { display: block; }
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar label { display: inline-flex; align-items: center; gap: 6px; }
.hint { color: var(--muted); font-size: 12px; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 8px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 12px; border-radius: 3px; display: inline-block; background: var(--c); }
.legend i.st-preliminar { background: color-mix(in srgb, var(--c) 35%, white); border: 1px dashed var(--c); }
.legend i.st-onskad { background: #fff; border: 1px dotted var(--c); }
.legend i.st-gjord { opacity: .45; }

/* Timeline */
.timeline {
  position: relative; overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; max-height: calc(100vh - 190px); user-select: none;
}
.tl-inner { position: relative; }
.tl-head { position: sticky; top: 0; z-index: 10; background: #fff; display: flex; border-bottom: 1px solid var(--line); }
.tl-corner { position: sticky; left: 0; z-index: 11; width: var(--name-w); min-width: var(--name-w); background: #fff; border-right: 1px solid var(--line); font-size: 11px; color: var(--muted); padding: 4px 8px; }
.tl-cols { position: relative; height: 38px; }
.tl-year { position: absolute; top: 0; height: 18px; font-size: 12px; font-weight: 600; border-left: 1px solid #c9ced6; padding-left: 4px; white-space: nowrap; }
.tl-month { position: absolute; top: 18px; height: 20px; font-size: 10px; color: var(--muted); text-align: center; border-left: 1px solid var(--line2); overflow: hidden; }
.tl-row { display: flex; border-bottom: 1px solid var(--line2); }
.tl-row.ext .tl-name { color: var(--muted); font-style: italic; }
.tl-row.sep { border-top: 2px solid var(--line); }
.tl-row.hl { background: #fff8db; }
.tl-name {
  position: sticky; left: 0; z-index: 5; width: var(--name-w); min-width: var(--name-w); background: #fff;
  border-right: 1px solid var(--line); padding: 3px 8px; font-size: 13px; display: flex; flex-direction: column; justify-content: center; cursor: pointer;
}
.tl-name small { color: var(--muted); font-size: 10px; }
.tl-row.hl .tl-name { background: #fff8db; }
.tl-track { position: relative; }
.tl-grid { position: absolute; inset: 0; pointer-events: none; }
.tl-out { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 4px, #fafafa 4px, #fafafa 8px); }
.tl-now { position: absolute; top: 0; bottom: 0; width: 2px; background: #ef4444; z-index: 4; pointer-events: none; }
.tl-end { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px solid #111827; z-index: 3; pointer-events: none; }
.tl-end::after { content: "ST-slut"; position: absolute; left: 3px; top: 0; font-size: 9px; color: #111827; white-space: nowrap; }
.tl-wish { position: absolute; height: 4px; bottom: 1px; background: #f59e0b; border-radius: 2px; z-index: 2; pointer-events: none; opacity: .8; }

.blk {
  position: absolute; height: calc(var(--row-h) - 4px); border-radius: 4px; font-size: 11px; line-height: calc(var(--row-h) - 6px);
  padding: 0 4px; overflow: hidden; white-space: nowrap; cursor: grab; z-index: 3;
  background: var(--c); color: #fff; border: 1px solid color-mix(in srgb, var(--c) 70%, black);
}
.blk.st-gjord { opacity: .5; }
.blk.st-preliminar { background: color-mix(in srgb, var(--c) 30%, white); color: color-mix(in srgb, var(--c) 75%, black); border: 1px dashed var(--c); }
.blk.st-onskad { background: #fff; color: var(--c); border: 1px dotted var(--c); }
.blk.st-bekraftad::before { content: "✓ "; }
.blk.absence { background: repeating-linear-gradient(135deg, #9ca3af, #9ca3af 4px, #d1d5db 4px, #d1d5db 8px); color: #111827; border-color: #6b7280; }
.blk.absence.st-preliminar { background: repeating-linear-gradient(135deg, #e5e7eb, #e5e7eb 4px, #f9fafb 4px, #f9fafb 8px); border-style: dashed; }
.blk.bad { outline: 2px solid var(--err); outline-offset: 0; }
.blk.dragging { opacity: .8; cursor: grabbing; z-index: 8; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.blk .rz { position: absolute; top: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.blk .rz.l { left: 0; } .blk .rz.r { right: 0; }

/* Occupancy */
.occ-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; max-height: calc(100vh - 170px); }
table.occ { border-collapse: separate; border-spacing: 0; font-size: 12px; }
table.occ th, table.occ td { border-bottom: 1px solid var(--line2); border-right: 1px solid var(--line2); padding: 2px 4px; text-align: center; white-space: nowrap; }
table.occ thead th { position: sticky; top: 0; background: #fff; z-index: 2; font-weight: 500; color: var(--muted); }
table.occ thead tr:first-child th { font-weight: 700; color: var(--ink); }
table.occ thead tr:nth-child(2) th { top: 22px; }
table.occ th.u { position: sticky; left: 0; background: #fff; text-align: left; z-index: 1; min-width: 190px; }
table.occ thead th.u { z-index: 3; }
table.occ tr.grp th { background: #f3f4f6; text-align: left; position: sticky; left: 0; }
table.occ td.c0 { color: #c0c4ca; }
table.occ td.cfree { background: #eef6ff; }
table.occ td.cfull { background: #dcfce7; color: #14532d; }
table.occ td.cover { background: #fee2e2; color: var(--err); font-weight: 700; }
table.occ td.cnone { background: #fafafa; color: #d1d5db; }
table.occ td.names { text-align: left; font-size: 11px; line-height: 1.25; vertical-align: top; min-width: 70px; }
table.occ td.past { opacity: .55; }
table.occ tr.tot td.low { background: #fee2e2; color: var(--err); font-weight: 700; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.card.inactive { opacity: .6; }
.card h3 { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.card h3 input.name { font-size: 16px; font-weight: 600; border-color: transparent; padding: 1px 4px; width: 12em; }
.card h3 input.name:hover, .card h3 input.name:focus { border-color: #cbd2d9; }
.card .meta { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; margin-bottom: 8px; align-items: center; }
.card .meta span:nth-child(odd) { color: var(--muted); }
.req { display: grid; grid-template-columns: 150px 1fr 74px; gap: 6px; align-items: center; font-size: 12px; margin: 2px 0; }
.bar { position: relative; height: 10px; background: #eef0f3; border-radius: 5px; overflow: hidden; }
.bar .d { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ok); }
.bar .p { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(135deg, #86efac, #86efac 3px, #dcfce7 3px, #dcfce7 6px); }
.req.miss .lbl { color: var(--err); font-weight: 600; }
.req .num { text-align: right; color: var(--muted); }
.card ul.w { margin: 6px 0 0; padding-left: 18px; font-size: 12px; }
.card ul.w li.error { color: var(--err); }
.card ul.w li.warn { color: var(--warn); }
.card .wishes { margin-top: 10px; border-top: 1px solid var(--line2); padding-top: 8px; font-size: 12px; }
.card .wishes .wrow { display: flex; gap: 4px; align-items: center; margin: 3px 0; flex-wrap: wrap; }
.card .wishes select, .card .wishes input { font-size: 12px; padding: 2px 4px; }
.card .acts { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* Warnings */
.wgroup { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; }
.wgroup h3 { font-size: 14px; margin-bottom: 6px; }
.witem { padding: 3px 0; border-bottom: 1px solid var(--line2); cursor: pointer; font-size: 13px; }
.witem:last-child { border-bottom: 0; }
.witem:hover { background: #f8fafc; }
.witem .lv { display: inline-block; width: 70px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.witem.error .lv { color: var(--err); } .witem.warn .lv { color: var(--warn); } .witem.info .lv { color: var(--muted); }

/* Units table */
table.edit { border-collapse: collapse; background: #fff; font-size: 12px; }
table.edit th, table.edit td { border: 1px solid var(--line); padding: 3px 5px; }
table.edit th { background: #f3f4f6; font-weight: 600; position: sticky; top: 52px; }
table.edit input[type=text] { width: 100%; min-width: 60px; padding: 2px 4px; font-size: 12px; }
table.edit input[type=number] { width: 4.5em; padding: 2px 4px; font-size: 12px; }
table.edit td.cb { text-align: center; }
table.edit tr.off { color: var(--muted); background: #fafafa; }
#units { overflow-x: auto; margin-bottom: 8px; }

/* Dialog */
dialog { border: 0; border-radius: 10px; padding: 18px 20px; width: min(620px, 95vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .35); }
dialog label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
dialog label input, dialog label select, dialog label textarea { color: var(--ink); font-size: 14px; }
.checks { display: flex; gap: 6px 18px; flex-wrap: wrap; margin-bottom: 10px; }
dialog label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 10px; }
.dlg-btns { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.spacer { flex: 1; }
.suggest { margin-top: 10px; font-size: 12px; }
.suggest button { margin: 2px 4px 2px 0; }
.fwarn { margin-top: 8px; font-size: 12px; color: var(--err); }

.tip { position: fixed; z-index: 100; pointer-events: none; background: #111827; color: #fff; font-size: 12px; padding: 6px 8px; border-radius: 6px; max-width: 340px; display: none; white-space: pre-line; }

@media print {
  .top, .toolbar, .hint { display: none !important; }
  .timeline, .occ-wrap { max-height: none; overflow: visible; border: 0; }
}
.card details.credit { font-size: 12px; }
.card details.credit summary { cursor: pointer; color: var(--muted); }
.creditgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 3px 10px; margin-top: 4px; }
.creditgrid label { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.creditgrid input { width: 4.5em; }
.card .rates { display: flex; flex-wrap: wrap; gap: 3px 10px; font-size: 12px; }
.card .rates .rate.past { color: var(--muted); }
.card .rateform input[type=month] { width: 9em; }
/* Placeringar under 100 % */
table.plist { border-collapse: collapse; width: 100%; font-size: 13px; }
table.plist th, table.plist td { border-bottom: 1px solid var(--line, #e5e7eb); padding: 6px 8px; text-align: left; vertical-align: top; }
table.plist th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.plist tr.done { opacity: .7; }
table.plist td.low { color: #b45309; font-weight: 600; }
table.plist td.note { max-width: 260px; font-size: 12px; color: var(--muted); }
table.plist .pbtns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 9px; background: #e5e7eb; color: #374151; }
.tag.new { background: #fef3c7; color: #92400e; }
.tag.ok { background: #dcfce7; color: #166534; }
.blk.partial { outline: 2px dashed #d97706; outline-offset: -2px; }
/* Kommentarer på varningar */
.witem .wline { display: flex; align-items: center; gap: 4px; }
.witem .wtext { flex: 1; }
.witem .wbtn { border: 0; background: none; cursor: pointer; opacity: .35; font-size: 13px; padding: 0 4px; }
.witem:hover .wbtn, .witem .wbtn.has { opacity: 1; }
.witem.accepted .wtext { text-decoration: line-through; color: var(--muted); }
.wnote { margin: 3px 0 4px 74px; font-size: 12px; cursor: default; }
.wnote.edit textarea { width: 100%; font: inherit; }
.wnote-row { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.tag.st-open { background: #e0f2fe; color: #075985; }
.tag.st-atgard { background: #fee2e2; color: #991b1b; }
.tag.st-planerad { background: #fef3c7; color: #92400e; }
.tag.st-godtagen, .tag.st-atgardad { background: #dcfce7; color: #166534; }
.wgroup.orphan { border-style: dashed; }
/* Underlag för schemaläggning */
.subtabs { display: flex; gap: 2px; }
.subtabs button { background: #fff; color: var(--text, #111); border: 1px solid var(--line); border-radius: 0; padding: 5px 12px; }
.subtabs button:first-child { border-radius: 6px 0 0 6px; } .subtabs button:last-child { border-radius: 0 6px 6px 0; }
.subtabs button.active { background: #1e293b; color: #fff; border-color: #1e293b; }
.ul-summary { font-size: 13px; color: var(--muted); }
.ul-summary .ok { color: #166534; font-weight: 600; }
.toolbar .spacer { flex: 1; }
.ul-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.ul-card.done { border-color: #86efac; }
.ul-card > summary { padding: 9px 14px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.ul-card .ul-prog { margin-left: auto; font-size: 12px; color: var(--muted); }
.ul-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 8px 18px; padding: 6px 14px 14px; }
.ul-grid.single { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.ul-f { display: grid; grid-template-columns: 170px 1fr; gap: 8px; align-items: start; font-size: 13px; padding: 4px 0 4px 8px; border-left: 3px solid #fde68a; }
.ul-f.filled { border-left-color: #86efac; }
.ul-f.wide { grid-column: 1 / -1; grid-template-columns: 170px 1fr; }
.ul-l { color: #334155; font-weight: 500; }
.ul-h { color: var(--muted); font-weight: 400; font-size: 11px; margin-top: 2px; }
.ul-i input:not([type=checkbox]):not([type=number]):not([type=month]), .ul-i textarea, .ul-i select { width: 100%; max-width: 520px; font: inherit; }
.ul-checks { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.ul-period { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.ul-rank { margin: 0; padding-left: 20px; } .ul-rank li { margin: 1px 0; }
.ul-rules td { padding: 2px 10px 2px 0; font-size: 13px; }
.ul-rules select { width: auto !important; }
@media (max-width: 600px) { .ul-f, .ul-f.wide { grid-template-columns: 1fr; } .ul-grid { grid-template-columns: 1fr; } }
