:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8e9ed;
  --muted: #9aa0ad;
  --accent: #f5b13d;     /* country/amber */
  --accent-2: #e07a3c;
  --green: #4cc38a;
  --blue: #5b9bd5;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2230 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }

.brand {
  font-weight: 800;
  letter-spacing: .18em;
  color: var(--accent);
}
.brand.small { font-size: 13px; letter-spacing: .14em; }

/* Logo-bilde (erstatter tekst-logoen) */
.brand-logo { display: block; height: 72px; width: auto; margin: 0 auto 4px; }
.brand-logo.small { height: 30px; margin: 0; }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 40px 32px;
  text-align: center; box-shadow: var(--shadow);
}
.login-card h1 { margin: 6px 0 8px; font-size: 26px; }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 18px;
  background: #fff; color: #1f1f1f; text-decoration: none; font-weight: 600;
  padding: 12px 20px; border-radius: 10px; transition: transform .08s ease, box-shadow .2s;
}
.google-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,.3); }

/* ---------- Topbar ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(15,17,21,.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.divider { width: 1px; height: 18px; background: var(--line); }
.user { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user img { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); }

button, .ghost {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 8px 14px;
  text-decoration: none; transition: background .15s, border-color .15s;
}
button:hover, .ghost:hover { background: #262b36; border-color: #3a4150; }
.primary { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 700; }
.primary:hover { background: #ffc35a; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 22px 0; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 14px; color: var(--muted); font-weight: 600;
}
.tab:hover { background: transparent; color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.count {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  font-size: 12px; background: var(--panel-2); border-radius: 999px; color: var(--muted);
}

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; padding: 16px 22px; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar select, dialog input, dialog select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font: inherit;
}
.toolbar input[type="search"] { min-width: 260px; flex: 1; max-width: 420px; }
.spacer { flex: 1; }
.stat { color: var(--muted); font-size: 13px; }

main { padding: 6px 22px 60px; }

/* ---------- Cards (volunteers) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.card h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card .contact { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px 14px; }
.card .contact a { color: var(--blue); text-decoration: none; }
.pill {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.prefs { display: flex; flex-direction: column; gap: 5px; }
.pref-row { display: flex; align-items: center; gap: 8px; }
.pref-rank { width: 18px; text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 600;
  border: 1px solid transparent; display: inline-flex; align-items: center; gap: 5px;
}
.badge .prio {
  font-size: 10px; background: rgba(0,0,0,.25); border-radius: 999px; padding: 0 5px;
}
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 4px; }
.shifts-list { display: flex; flex-wrap: wrap; gap: 5px; }
.shift-chip { font-size: 11px; padding: 3px 8px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--line); }
.note { font-size: 13px; color: var(--text); background: var(--panel-2); border-radius: 9px; padding: 8px 10px; }
.note.dim { color: var(--muted); }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.card .actions { margin-top: auto; display: flex; gap: 8px; }
.assigned-line { font-size: 12px; color: var(--green); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- Schedule grid ---------- */
.sched-wrap {
  overflow: auto; max-height: calc(100vh - 210px);
  border: 1px solid var(--line); border-radius: var(--radius);
}
table.sched { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 720px; }
table.sched th, table.sched td {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  vertical-align: top; padding: 8px;
}
/* Header-rad følger med vertikalt */
table.sched thead th { background: var(--panel-2); position: sticky; top: 0; z-index: 3; font-size: 13px; }
/* Venstre kolonne (navn/vakt) følger med horisontalt */
table.sched th.shift-th { text-align: left; min-width: 200px; background: var(--panel); position: sticky; left: 0; z-index: 2; }
/* Hjørnecellen må ligge over begge */
table.sched thead th.shift-th { z-index: 4; }
table.sched td { min-width: 130px; background: var(--panel); }
.cell-people { display: flex; flex-direction: column; gap: 4px; }
.assignee {
  font-size: 12px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 3px 6px; display: flex; align-items: center; gap: 6px; justify-content: space-between;
}
.assignee .x { cursor: pointer; color: var(--muted); border: none; background: none; padding: 0 2px; }
.assignee .x:hover { color: var(--accent-2); }
.cell-add { font-size: 11px; color: var(--accent); cursor: pointer; margin-top: 4px; display: inline-block; }
.want-dot { color: var(--muted); font-size: 11px; }

/* ---------- Timeline view ---------- */
table.timeline th.name-th { width: 170px; min-width: 170px; max-width: 170px; }
table.timeline .tl-name { font-weight: 600; }
/* Frossen kolonne for antall bekreftede vakter */
table.timeline .tl-count {
  position: sticky; left: 170px; z-index: 2; background: var(--panel);
  width: 56px; min-width: 56px; max-width: 56px;
  text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
}
table.timeline thead th.tl-count { z-index: 4; background: var(--panel-2); font-weight: 600; }
table.timeline tfoot .tl-count { background: var(--panel-2); color: var(--text); }
table.timeline td.tl-count.zero { color: var(--muted); opacity: .4; font-weight: 400; }
table.timeline td.tl-cell { min-width: 104px; padding: 5px; }
table.timeline td.clickable { cursor: pointer; }
table.timeline td.tl-empty:hover { background: rgba(255,255,255,.03); }

/* Hver boks = ett team-ønske; stablet med førstevalg øverst, neste under */
.tl-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-size: 11px; font-weight: 600; border-radius: 6px; padding: 3px 7px; margin-bottom: 3px;
}
.tl-chip:last-child { margin-bottom: 0; }
.tl-chip.wish { cursor: pointer; opacity: .5; }
.tl-chip.wish:hover { opacity: 1; }
.tl-chip.set { font-weight: 700; opacity: 1; }
.tl-chip.neutral { border-left: 3px dashed var(--muted); color: var(--muted); }
.tl-chip .x { border: none; background: none; padding: 0; color: currentColor; opacity: .6; cursor: pointer; }
.tl-chip .x:hover { opacity: 1; }
.tl-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Oppsummeringsrader nederst i tidslinjen */
table.timeline tfoot td, table.timeline tfoot th {
  background: var(--panel-2); text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
}
table.timeline tfoot th.name-th { text-align: left; font-weight: 600; }
table.timeline tfoot .sum-total td, table.timeline tfoot .sum-total th {
  font-size: 15px; border-top: 2px solid var(--accent); color: var(--text); line-height: 1.15;
}
table.timeline tfoot .sum-total .sum-avail { font-size: 15px; font-weight: 800; }
table.timeline tfoot .sum-total .sum-need {
  display: block; font-size: 10px; font-weight: 600; color: var(--muted); opacity: .6; margin-top: 1px;
}
table.timeline tfoot td.zero { color: var(--muted); opacity: .45; font-weight: 400; }

/* Kapasitets-celler (satt / terskel + tilgjengelig) i team-radene */
table.timeline tfoot td.cap-td { cursor: pointer; padding: 4px 6px; line-height: 1.15; }
table.timeline tfoot td.cap-td:hover { outline: 1px solid var(--accent); outline-offset: -1px; }
.cap-line { font-size: 13px; font-weight: 700; }
.cap-set { color: var(--text); }
.cap-sep { color: var(--muted); margin: 0 1px; }
.cap-thr { color: var(--muted); }
.cap-avail { display: block; font-size: 10px; font-weight: 600; color: var(--muted); opacity: .5; margin-top: 1px; }
table.timeline tfoot td.cap-td.met { background: rgba(76,195,138,.22); }
table.timeline tfoot td.cap-td.met .cap-set { color: var(--green); }
table.timeline tfoot td.cap-td.met .cap-thr { color: var(--green); }
table.timeline tfoot td.cap-td.zero { opacity: .5; }
/* Ikke satt terskel: rød (må bestemmes) */
table.timeline tfoot td.cap-td.unset { background: rgba(224,90,90,.22); }
table.timeline tfoot td.cap-td.unset .cap-thr { color: #e87070; }
/* Under terskel (trengs flere): gul */
table.timeline tfoot td.cap-td.under { background: rgba(240,200,64,.20); }
table.timeline tfoot td.cap-td.under .cap-thr { color: #e8c14a; }
/* Ingen behov (terskel = 0): helt sort */
table.timeline tfoot td.cap-td.none-needed { background: #000; }
table.timeline tfoot td.cap-td.none-needed .cap-line { color: var(--muted); opacity: .45; }
table.timeline tfoot td.cap-td.none-needed .cap-avail { opacity: .3; }

/* ---------- Teams view ---------- */
.team-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.team-block h3 { margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.team-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.person-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; border-bottom: 1px solid var(--line); }
.person-row:last-child { border-bottom: none; }
@media (max-width: 640px) { .team-cols { grid-template-columns: 1fr; } }

.empty { color: var(--muted); padding: 40px; text-align: center; }

/* ---------- T-shirts view ---------- */
.tshirt-summary { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0 4px; }
.tshirt-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 20px; min-width: 96px; text-align: center;
}
.tshirt-card.dim { opacity: .6; }
.tshirt-size { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.tshirt-count { font-size: 28px; font-weight: 800; color: var(--accent); line-height: 1.2; }
table.list { border-collapse: collapse; width: 100%; max-width: 600px; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Allergens view ---------- */
.allergen-list { display: flex; flex-direction: column; gap: 10px; max-width: 680px; }
.allergen-item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 6px;
}
.allergen-head { display: flex; align-items: baseline; gap: 10px; }
.allergen-name { font-weight: 700; }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--radius); padding: 22px; width: min(420px, 92vw); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 4px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-top: 14px; }
dialog label select, dialog label input { width: 100%; margin-top: 5px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px;
  border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-size: 14px;
}

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  .topbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .topbar-left { gap: 8px; }
  .topbar-left strong, .topbar-left .divider { display: none; }
  .brand-logo.small { height: 24px; }
  .user span { display: none; }                  /* kun avatar */
  .topbar-right { gap: 6px; margin-left: auto; }
  button, .ghost { padding: 7px 11px; }

  .tabs {
    padding: 8px 10px 0; gap: 2px; flex-wrap: nowrap;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; white-space: nowrap; padding: 9px 11px; }

  .toolbar { padding: 12px; gap: 8px; }
  .toolbar input[type="search"] { min-width: 0; max-width: none; flex: 1 1 100%; order: -1; }
  .toolbar select { flex: 1 1 40%; }
  #copy-emails, #print { flex: 1 1 auto; }
  .spacer { display: none; }
  .stat { flex: 1 1 100%; }

  main { padding: 6px 12px 60px; }
  .grid { grid-template-columns: 1fr; }

  /* Tabeller: behold horisontal scroll, men smalere frosne kolonner */
  .sched-wrap { max-height: calc(100vh - 250px); }
  table.sched th.shift-th { min-width: 130px; }
  table.timeline th.name-th { width: 120px; min-width: 120px; max-width: 120px; }
  table.timeline .tl-count { left: 120px; width: 44px; min-width: 44px; max-width: 44px; }

  .team-cols { grid-template-columns: 1fr; }
  dialog { width: 94vw; }
}

/* Kun synlig ved utskrift */
.print-only { display: none; }

/* ---------- Utskrift ---------- */
@media print {
  @page { size: landscape; margin: 8mm; }

  /* Tving frem bakgrunnsfarger (fargekoding) */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  body { background: #fff !important; color: #000 !important; }

  /* Skjul all UI-krom */
  .topbar, .tabs, .toolbar, #login, #assign-dialog, #toast { display: none !important; }
  .tl-chip .x, .assignee .x, .cell-add, .tl-add, .actions { display: none !important; }

  main { padding: 0 !important; }

  /* Utskrifts-tittel */
  .print-only { display: block; }
  #print-title { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
  #print-title img { height: 34px; }
  #print-title-text { font-size: 16px; font-weight: 700; color: #000; }

  /* Lås opp scroll/sticky så hele tabellen kommer med */
  .sched-wrap { overflow: visible !important; max-height: none !important; border: none !important; }
  table.sched thead th, table.sched th.shift-th,
  table.timeline .tl-count, table.timeline th.name-th { position: static !important; }

  /* Lys tabell på papir, behold statusfarger via mer spesifikke regler */
  table.sched { font-size: 8.5px; min-width: 0 !important; width: 100% !important; }
  table.sched th, table.sched td {
    background: #fff !important; color: #000 !important;
    border: 1px solid #bbb !important; padding: 3px 4px !important; min-width: 0 !important;
  }
  table.sched thead th { background: #eee !important; }
  thead { display: table-header-group; }   /* gjenta header per side */
  tr, .tl-chip, .card, .team-block, .allergen-item { break-inside: avoid; }

  /* Behold fargekoding på kapasitets-cellene */
  table.timeline tfoot td.cap-td.met { background: #d6f3e3 !important; }
  table.timeline tfoot td.cap-td.under { background: #fbf0c8 !important; }
  table.timeline tfoot td.cap-td.unset { background: #f7d6d6 !important; }
  table.timeline tfoot td.cap-td.none-needed { background: #000 !important; }
  .tl-chip.wish { display: none !important; }  /* skjul ønsker – kun oppsatt på papir */

  /* Kort-visningene flyter pent på papir */
  .grid { display: block !important; }
  .card { break-inside: avoid; border: 1px solid #bbb !important; margin-bottom: 8px; }
}
