:root {
  --bg: #f5f7f9; --panel: #fff; --ink: #1c2530; --muted: #5f6b78; --line: #dfe4ea;
  --brand: #1f5f8b; --brand-ink: #fff; --brand-soft: #e6f0f7;
  --free: #1e7a46; --free-soft: #e3f4ea; --busy: #b3362c; --busy-soft: #fbe6e4;
  --mine: #7a4fb3; --mine-soft: #efe7fa; --part: #8a5a00; --part-soft: #fdeccb; --sel: #1f5f8b; --sel-soft: #cfe2f0;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; --font-head: var(--font);
  font-family: var(--font);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 24px 0 4px; font-family: var(--font-head); }
h2, .brand { font-family: var(--font-head); }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Header */
.top { background: var(--brand); color: var(--brand-ink); }
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand img { height: 30px; width: auto; display: block; }
.brand img + .brand-text { display: none; }
.brand .brand-sub { font-weight: 400; opacity: .85; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.4); }
.top-inner { display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
nav a { color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 8px; opacity: .85; }
nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
nav a.active { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.who { font-size: .85rem; opacity: .9; }
.badge { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 99px; background: #fff; color: var(--brand); font-weight: 700; margin-left: 6px; }

/* Paneler & formulär */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); padding: 8px 10px; border: 1px solid #c5cdd6; border-radius: 8px; background: #fff; min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; background: var(--brand); color: #fff; font-weight: 600; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary, .btn.secondary { background: #fff; color: var(--brand); border-color: #b7c7d6; }
button.danger { background: #fff; color: var(--busy); border-color: #e5b8b3; }
button.link { background: none; color: var(--brand); padding: 4px 6px; border: none; font-weight: 600; }
.seg { display: inline-flex; border: 1px solid #b7c7d6; border-radius: 8px; overflow: hidden; }
.seg button { border-radius: 0; background: #fff; color: var(--brand); border: none; border-right: 1px solid #b7c7d6; }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--brand); color: #fff; }

/* Resurskort */
.cat { margin: 18px 0 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card { text-align: left; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-weight: 400; }
.card:hover { border-color: var(--brand); filter: none; box-shadow: 0 2px 8px rgba(31,95,139,.12); }
.card.on { border: 2px solid var(--brand); background: var(--brand-soft); padding: 11px 13px; }
.card b { display: block; margin-bottom: 2px; }
.card .d { font-size: .82rem; color: var(--muted); white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Kalender */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.cal-head h3 { margin: 0; font-size: 1.05rem; }
h3.mon::first-letter { text-transform: uppercase; }
.cals { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.cal { width: 100%; border-collapse: separate; border-spacing: 3px; table-layout: fixed; }
.cal th { font-size: .75rem; color: var(--muted); font-weight: 600; padding: 2px; }
.cal th.wk, .cal td.wk { font-size: .7rem; color: var(--muted); width: 30px; text-align: center; cursor: pointer; }
.cal td.wk:hover { color: var(--brand); text-decoration: underline; }
.cal td.day { height: 38px; text-align: center; border-radius: 6px; cursor: pointer; background: var(--free-soft); color: var(--free); font-weight: 600; font-size: .9rem; user-select: none; position: relative; }
.cal td.day:hover { outline: 2px solid var(--free); }
.cal td.busy { background: var(--busy-soft); color: var(--busy); cursor: not-allowed; }
.cal td.busy:hover { outline: none; }
.cal td.mine { background: var(--mine-soft); color: var(--mine); }
.cal td.past { background: #eef0f2; color: #a9b1ba; cursor: default; }
.cal td.past:hover { outline: none; }
.cal td.sel { background: var(--sel); color: #fff; }
.cal td.today::after { content: ""; position: absolute; left: 30%; right: 30%; bottom: 4px; height: 2px; background: currentColor; border-radius: 2px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }

/* Listor */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 8px; flex-wrap: wrap; }
.pill { font-size: .75rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill.free { background: var(--free-soft); color: var(--free); }
.pill.busy { background: var(--busy-soft); color: var(--busy); }
.pill.cancelled { background: #eceff2; color: var(--muted); }
.pill.warn { background: #fff3d6; color: #8a5a00; }

/* Översiktsgrid */
.grid-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.grid { border-collapse: collapse; font-size: .78rem; min-width: 100%; }
.grid th, .grid td { border: 1px solid #edf0f3; padding: 0; height: 30px; min-width: 26px; text-align: center; }
.grid th.res { position: sticky; left: 0; background: #fff; text-align: left; padding: 0 10px; min-width: 150px; white-space: nowrap; z-index: 1; font-weight: 600; }
.grid thead th { background: #f7f9fb; color: var(--muted); font-weight: 600; }
.grid thead th.we { color: #b0b8c1; }
.grid thead th.today { background: var(--brand); color: #fff; }
.grid td.f { cursor: pointer; }
.grid td.f:hover { background: var(--free-soft); }
.grid td.b { background: var(--busy-soft); }
.grid td.b.m { background: var(--mine-soft); }
.grid td.b span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .7rem; color: var(--busy); padding: 0 3px; text-align: left; }
.grid td.b.m span { color: var(--mine); }
.grid td.we { background-color: #fafbfc; }

/* Tabell (admin) */
table.t { width: 100%; border-collapse: collapse; background: #fff; font-size: .88rem; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.t-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

.error { background: var(--busy-soft); color: var(--busy); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.ok { background: var(--free-soft); color: var(--free); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.summary { background: var(--brand-soft); border-radius: 8px; padding: 10px 12px; font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1c2530; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); z-index: 10; }
#toast.show { opacity: 1; }

dialog { border: none; border-radius: var(--radius); padding: 20px; max-width: 520px; width: calc(100% - 32px); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,30,40,.4); }
dialog form { display: grid; gap: 12px; }

@media (max-width: 640px) {
  .top-inner { gap: 6px; padding: 8px 16px; }
  .brand { width: 100%; }
  .card .d { -webkit-line-clamp: 1; }
  nav a { padding: 6px 8px; font-size: .9rem; }
  .who { width: 100%; }
  .row > label { flex: 1 1 100%; }
}

/* ---- Multival ---- */
.picked { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; min-height: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-soft); color: var(--ink); border-radius: 99px; padding: 3px 4px 3px 11px; font-size: .85rem; }
.picked > .chip:not(:has(button)) { padding-right: 11px; }
.chip-x { background: none; color: var(--muted); border: none; padding: 0 6px; font-size: 1.05rem; line-height: 1; }
.chip-x:hover { color: var(--busy); filter: none; }
.card { position: relative; padding-right: 40px; }
.card .check { position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; border: 2px solid #b7c7d6; border-radius: 5px; background: #fff; }
.card.on .check { background: var(--brand); border-color: var(--brand); }
.card.on .check::after { content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.card.on { padding-right: 39px; }
.cal td.part { background: var(--part-soft); color: var(--part); }
.cal td.day small { position: absolute; right: 3px; bottom: 1px; font-size: .6rem; font-weight: 700; opacity: .85; }
.cal td.sel small { color: #fff; }
.legend i.lg { border: 1px solid transparent; }
.lg.free { background: var(--free-soft); border-color: var(--free) !important; }
.lg.part { background: var(--part-soft); border-color: var(--part) !important; }
.lg.busy { background: var(--busy-soft); border-color: var(--busy) !important; }
.lg.mine { background: var(--mine-soft); border-color: var(--mine) !important; }
.lg.sel { background: var(--sel); }
ul.items { list-style: none; padding: 0; margin: 8px 0; }
ul.items li { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; margin: 0; background: none; justify-content: flex-start; }
ul.items li:first-child { border-top: 0; }
ul.items li.it-no > span:first-child, ul.items li.it-no b { opacity: .75; }
ul.items li button { margin-left: auto; }
.list li.group { align-items: flex-start; }
.pickrow { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-weight: 400; cursor: pointer; font-size: 1rem; flex: 1; }
.pickrow input { width: 20px; height: 20px; accent-color: var(--brand); }
.list li.selectable.on { border-color: var(--brand); background: var(--brand-soft); }
.sticky-bar { position: sticky; bottom: 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.25); margin-top: 12px; }
.sticky-bar span { flex: 1 1 200px; font-size: .9rem; }
.sticky-bar .link { color: #fff; }

.cal td.day.past, .cal td.day.past.part, .cal td.day.past.busy { background: #eef0f2; color: #a9b1ba; cursor: default; }
.cal td.day.past small { display: none; }
.cal td.day.past:hover { outline: none; }

/* ---- Bilder ---- */
.card { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.card.on { padding: 0; }
.card-body { display: block; padding: 12px 40px 12px 14px; position: relative; }
.card.on .card-body { padding: 11px 39px 11px 13px; }
.card .check { top: 12px; right: 12px; }
.card-img { position: relative; display: block; aspect-ratio: 4 / 3; background: #eef1f4; }
.card-img img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; }
.card-img.noimg { display: none; }
.card .zoom { position: absolute; right: 8px; bottom: 8px; width: 32px; height: 32px; border-radius: 99px; background: rgba(28,37,48,.7); cursor: zoom-in; }
.card .zoom::before { content: ""; position: absolute; left: 8px; top: 8px; width: 11px; height: 11px; border: 2px solid #fff; border-radius: 50%; }
.card .zoom::after { content: ""; position: absolute; left: 20px; top: 20px; width: 7px; height: 2px; background: #fff; transform: rotate(45deg); transform-origin: left center; }
.card .zoom:hover, .card .zoom:focus-visible { background: var(--brand); outline: none; }
img.mini, .mini.noimg { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: #eef1f4; flex: none; display: inline-block; vertical-align: middle; }
img.mini { cursor: zoom-in; border: 1px solid var(--line); }
.busyrow { display: flex; gap: 10px; align-items: flex-start; }
dialog.lightbox { max-width: min(900px, calc(100% - 32px)); padding: 12px; text-align: center; }
dialog.lightbox img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto 8px; border-radius: 6px; }
dialog.lightbox .cap { font-weight: 600; margin-bottom: 8px; }
.imgedit { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.imgprev { width: 120px; height: 90px; border: 1px dashed #c5cdd6; border-radius: 8px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #fafbfc; }
.imgprev img { max-width: 100%; max-height: 100%; }
@media (max-width: 640px) { .card-img { aspect-ratio: 16 / 9; } }

/* ---- Inloggning (pilot) ---- */
body.logged-out #nav, body.logged-out #who { visibility: hidden; }
.login { max-width: 420px; margin: 48px auto; }
.link-inv { background: none; border: none; color: inherit; padding: 0; font: inherit; font-size: inherit; text-decoration: underline; opacity: .9; cursor: pointer; }
.link-inv:hover { opacity: 1; filter: none; }
