:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dbe1e8;
  --text: #1b2430;
  --text-muted: #64748b;
  --accent: #1e3a5f;
  --accent-2: #2563eb;
  --danger: #dc2626;
  --danger-bg: #fde8e8;
  --success: #16a34a;
  --warn: #d97706;
  --shadow: 0 4px 16px rgba(20, 30, 50, 0.10);
  --radius: 10px;
  --today-bg: #fff7e0;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1620;
  --surface: #182333;
  --surface-2: #1f2c3f;
  --border: #2c3b4f;
  --text: #e7edf5;
  --text-muted: #93a3b8;
  --accent: #6fa3d8;
  --accent-2: #4c8dee;
  --danger: #f87171;
  --danger-bg: #3a1f21;
  --success: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  --today-bg: #2a2412;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Varovalka: stran se nikoli ne sme dati vodoravno podrgniti/drseti kot
     celota (npr. če bi kak element pomotoma presegel širino zaslona) - vsak
     vodoravno drseč del (dnevi na mobilnem, tabela na namizju) ima svoj
     lasten "overflow-x: auto" znotraj sebe. */
  overflow-x: hidden;
}

body { min-height: 100vh; }

button { font-family: inherit; }

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-left h1 {
  font-size: 18px;
  margin: 0;
  color: var(--accent);
  white-space: nowrap;
}

.topbar-week {
  display: flex;
  align-items: center;
  gap: 4px;
}

.week-label {
  background: none;
  border: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  line-height: 1.2;
}
.week-label:hover { background: var(--surface-2); }
.week-label span:first-child { font-weight: 600; font-size: 14px; }
.week-range { font-size: 12px; color: var(--text-muted); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-icon { margin-right: 6px; }
.btn-primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); }
.btn-danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { filter: brightness(1.05); }

.conn-status {
  text-align: center;
  font-size: 13px;
  padding: 6px;
  background: var(--warn);
  color: #1b2430;
}

/* GRID */
main { padding: 14px; }
.grid-wrap { overflow-x: auto; }

.schedule-grid {
  display: grid;
  min-width: 900px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.grid-row {
  display: contents;
}

.grid-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px;
  min-height: 92px;
  background: var(--surface);
}

.grid-cell.head {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  padding: 10px 6px;
  min-height: unset;
  /* Opomba: ni "position: sticky" na navpični osi - .grid-wrap zaradi
     overflow-x:auto postane samostojen scroll-container tudi na Y osi
     (CSS spec), kar bi sticky top potisnilo navzdol in prekrivalo vrstice
     spodaj. Levi "sticky" (ime ekipe, kotna celica) ostaja - to je
     vodoravno drsenje znotraj iste vrstice in deluje pravilno. */
  z-index: 5;
}

.grid-cell.head.today { background: var(--today-bg); }

.grid-cell.team-name {
  /* Ozadje po ekipah nastavi JS (mehak pastelen odtenek barve ekipe -
     glej softColor() v app.js), zato je tu samo nevtralen privzeti izgled. */
  background: var(--surface-2);
  color: #1b2430;
  font-weight: 600;
  display: flex;
  align-items: center;
  min-height: unset;
  position: sticky;
  left: 0;
  z-index: 4;
}

.corner-cell {
  background: var(--surface-2);
  position: sticky;
  left: 0;
  z-index: 6;
  min-height: unset;
}

/* "Danes" na namizni tabeli označimo z rahlim obarvanim robom namesto s
   polnim ozadjem - polno ozadje bi se sicer spopadlo z novim, po ekipah
   obarvanim ozadjem vrstice. */
.grid-cell.day-cell.today { box-shadow: inset 0 0 0 2px var(--warn); }

.day-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.add-assignment-btn {
  /* Vedno na (pastelnem) obarvanem ozadju vrstice/kartice, zato ima
     nevtralno temno sivo barvo ne glede na temo (namesto var(--text-muted),
     ki bi bila v temni temi presvetla in slabo vidna). */
  border: 1px dashed rgba(20, 25, 35, 0.25);
  background: rgba(255, 255, 255, 0.5);
  color: #4b5563;
  border-radius: 8px;
  padding: 4px;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
}
.add-assignment-btn:hover { background: rgba(255, 255, 255, 0.85); color: #1b2430; }

.assignment-chip {
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  color: #10141c;
  border-left: 4px solid transparent;
  background: var(--surface-2);
  line-height: 1.35;
}
.assignment-chip:hover { filter: brightness(0.97); }
:root[data-theme="dark"] .assignment-chip { color: #10141c; }
.assignment-chip .chip-project { font-weight: 700; display: block; }
.assignment-chip .chip-location { display: block; opacity: 0.85; }
.assignment-chip .chip-time { font-weight: 600; margin-right: 4px; }

.assignment-chip.status-koncano { opacity: 0.6; text-decoration: line-through; }
.assignment-chip.status-odpovedano { opacity: 0.55; text-decoration: line-through; }
.assignment-chip.status-v-teku { box-shadow: inset 0 0 0 2px rgba(37,99,235,0.35); }

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

.fab {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #fff;
  border: none;
  font-size: 26px;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 15;
}

/* MODALS */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-small { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.modal-footer .spacer { flex: 1; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}
.field input, .field select, .field textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.field-row { display: flex; gap: 10px; }

.teams-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.team-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.team-row input[type="text"] {
  flex: 1;
  border: 1px solid transparent;
  background: none;
  color: var(--text);
  font-size: 14px;
  padding: 4px;
  border-radius: 6px;
}
.team-row input[type="text"]:focus { border-color: var(--border); background: var(--surface-2); }

.team-add-row { display: flex; gap: 8px; align-items: center; }
.team-add-row input[type="text"] {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.team-add-row input[type="color"] {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 100;
  box-shadow: var(--shadow);
}

/* AUTH SCREEN */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-box {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-box h1 {
  margin: 0;
  font-size: 20px;
  color: var(--accent);
  text-align: center;
}
.auth-sub {
  margin: 0 0 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-submit { margin-top: 6px; }
.auth-link {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  text-align: center;
}
.auth-link:hover { text-decoration: underline; }
.auth-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}
.current-user {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* INSTALL BANNER (PWA "Dodaj na domači zaslon") */
.install-banner {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent);
  color: #fff;
  font-size: 13px;
}
.install-banner-icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
.install-banner-text { flex: 1; line-height: 1.35; }
.install-banner .btn-small { padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.install-banner .icon-btn { color: #fff; flex-shrink: 0; }
.install-banner .icon-btn:hover { background: rgba(255, 255, 255, 0.15); }

/* MOBILNI PRIKAZ: privzeto skrit, prikazan samo na ozkih zaslonih (glej
   media query spodaj), kjer nadomesti vodoravno drsečo tabelo z izbiro
   enega dneva + navpičnim seznamom kartic po ekipah - veliko bolj berljivo
   in dostopno na telefonu kot vodoravno drsenje. */
.mobile-day-view { display: none; }

.day-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  -webkit-overflow-scrolling: touch;
}
.day-pill {
  flex: 1 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
  cursor: pointer;
}
.day-pill-name { font-size: 12px; font-weight: 600; }
.day-pill-date { font-size: 11px; color: var(--text-muted); }
.day-pill.today { border-color: var(--warn); }
.day-pill.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
}
.day-pill.active .day-pill-name,
.day-pill.active .day-pill-date { color: #fff; }

.mobile-teams-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.team-card {
  /* Ozadje in levi obarvani rob nastavi JS (softColor() v app.js) - vsaka
     kartica je obarvana v mehkem, pastelnem odtenku barve svoje ekipe. */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.team-card:active { transform: scale(0.995); }
.team-card-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.team-card-name { font-weight: 700; font-size: 15px; color: #1b2430; }
.team-card-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.team-card-chips .assignment-chip { font-size: 13px; padding: 10px 12px; }
.team-card-empty {
  margin: 0 0 10px;
  color: #5b6472;
  font-size: 13px;
  font-style: italic;
}
.add-assignment-btn-block {
  margin-top: 10px;
  padding: 10px;
  font-size: 13px;
}

/* RESPONSIVE: pod 720px pokažemo mobilni prikaz (dan + kartice) namesto
   namizne tabele, ki bi zahtevala vodoravno drsenje. */
@media (max-width: 720px) {
  .topbar-left h1 { font-size: 15px; }
  main { padding: 12px; }
  .grid-wrap { display: none; }
  .mobile-day-view { display: block; }
  .fab { display: inline-flex; align-items: center; justify-content: center; }

  /* Zgornja vrstica je na ozkem zaslonu prezasedena - tiskanje s telefona je
     itak redko potrebno (ostane na voljo na računalniku), zato ga skrijemo.
     "Ekipe" pa naj ostane dosegljiv, le kot majhna ikona brez besedila (isto
     dela tudi plavajoči gumb "+" spodaj desno, a "Ekipe" naj bo dosegljiv
     tudi neposredno v vrstici). Preostanek naj se prelomi v drugo vrstico,
     če še vedno ne gre skupaj v eno - namesto da bi silil v širino in
     razpotegnil stran. */
  #btnPrint { display: none; }
  #btnManageTeams { padding: 6px 8px; }
  #btnManageTeams .btn-icon { margin-right: 0; font-size: 16px; }
  #btnManageTeams .btn-label { display: none; }
  .current-user { max-width: 90px; font-size: 11px; }
  .topbar {
    flex-wrap: wrap;
    row-gap: 4px;
    gap: 6px;
    padding: 8px 10px;
  }
  .topbar-right { gap: 2px; }
  .topbar-week { order: 3; width: 100%; justify-content: center; }
}

/* Se ozji zasloni (majhni telefoni) - dodatno skrcimo ime tedna in datume */
@media (max-width: 380px) {
  .week-range { display: none; }
  .current-user { max-width: 50px; }
}

/* PRINT */
@media print {
  .topbar, .fab, .conn-status, .toast, .auth-screen, .install-banner, .mobile-day-view { display: none !important; }
  .grid-wrap { display: block !important; }
  body { background: #fff; color: #000; }
  .schedule-grid { min-width: 0; box-shadow: none; }
  .grid-cell.head, .corner-cell, .grid-cell.team-name { position: static; background: #eee !important; }
  main { padding: 0; }
}
