/* Palette taken from TeamTor's own crew-signup page (brand red family + warm neutrals) — dark
   mode brightens the brand red a bit (#c8362f vs the reference's #8c1a1a) since the reference is
   a light-only design and the deep brick red reads too muddy as text/borders on a near-black
   background; light mode uses the reference's values as-is. */
:root {
  --bg: #1a1817;
  --bg-elevated: #221f1e;
  --bg-card: #2a2626;
  --bg-hover: #342f2f;
  --border: #3d3736;
  --text: #f2f0ed;
  --text-dim: #b8b2ab;
  --text-faint: #8a8480;
  --accent: #c8362f;
  --accent-soft: rgba(200, 54, 47, 0.18);
  --good: #3ec98c;
  --good-soft: rgba(62, 201, 140, 0.15);
  --warn: #e8b339;
  --warn-soft: rgba(232, 179, 57, 0.15);
  --bad: #ef5b6e;
  --bad-soft: rgba(239, 91, 110, 0.15);
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  --sidebar-w: 220px;
  --statsbar-w: 300px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f0ed;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #ece8e3;
    --border: #dedad4;
    --text: #1a1a1a;
    --text-dim: #666666;
    --text-faint: #8a857e;
    --accent: #8c1a1a;
    --accent-soft: rgba(140, 26, 26, 0.12);
    --good: #2d6a2f;
    --good-soft: #edf7ed;
    --bad: #8b2a1d;
    --bad-soft: #fdf0ed;
    --shadow: 0 8px 24px rgba(40, 30, 25, 0.08);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--statsbar-w);
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 24px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: block;
  object-fit: cover;
  flex-shrink: 0;
}

.brand-text {
  font-weight: 600;
  font-size: 15px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px;
  color: var(--text-faint);
  font-size: 12px;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.mode-toggle:hover {
  border-color: var(--accent);
}

.mode-toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.mode-toggle.live {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.mode-toggle.live .mode-toggle-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Main ---------- */
.main {
  padding: 24px 28px;
  overflow-y: auto;
  min-width: 0;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.view-header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
}

.view-header .sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.danger {
  color: var(--bad);
  border-color: var(--bad);
}

.btn.danger:hover {
  background: var(--bad-soft);
}

.btn.small {
  padding: 5px 10px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Cards / grids ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.tile .label {
  font-size: 11.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.tile .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 6px;
}

.tile .value.good {
  color: var(--good);
}
.tile .value.warn {
  color: var(--warn);
}
.tile .value.bad {
  color: var(--bad);
}

.tile .hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* ---------- Statsbar ---------- */
.statsbar {
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 20px 16px;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.statsbar h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.mini-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.mini-stat:last-child {
  border-bottom: none;
}

.mini-stat .n {
  font-weight: 700;
}

.violation-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow-y: auto;
}

.violation {
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bad-soft);
  color: var(--bad);
  line-height: 1.4;
}

.violation.warn-type {
  background: var(--warn-soft);
  color: var(--warn);
}

.violation-empty {
  font-size: 12.5px;
  color: var(--text-faint);
  padding: 10px 0;
}

/* ---------- Tables ---------- */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

table.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data-table tr:hover td {
  background: var(--bg-hover);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.field input {
  width: 100%;
}

.auth-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 4px;
}

.auth-status-email {
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea {
  width: 100%;
  resize: vertical;
}

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-hover);
  color: var(--text-dim);
}

.pill.good {
  background: var(--good-soft);
  color: var(--good);
}
.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.pill.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

/* ---------- Dienstplan grid ---------- */
.day-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.day-tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.day-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.dp-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.pool-panel {
  width: 230px;
  flex-shrink: 0;
  max-height: 70vh;
  overflow-y: auto;
}

/* Scrolls horizontally instead of squeezing the grid's columns to nothing — a fixed-width grid
   inside a shrinking flex child otherwise clips silently (no scrollbar, content just vanishes). */
.schedule-grid-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  border-radius: var(--radius-lg);
}

.schedule-grid {
  display: grid;
  min-width: 560px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
}

.schedule-grid .grid-row {
  display: grid;
  grid-template-columns: 130px repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}

@media (max-width: 860px) {
  .dp-layout {
    flex-direction: column;
  }
  .pool-panel {
    width: 100%;
    max-height: 180px;
  }
}

.schedule-grid .grid-row:last-child {
  border-bottom: none;
}

.schedule-grid .grid-head {
  font-weight: 700;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elevated);
}

.grid-cell {
  padding: 10px;
  border-left: 1px solid var(--border);
  min-height: 64px;
}

.grid-cell:first-child {
  border-left: none;
}

.post-label {
  padding: 12px 10px;
  font-weight: 600;
  font-size: 13px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
}

.slot-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 0.12s;
}

.slot-cell.drag-over {
  background: var(--accent-soft);
}

.slot-cell.inactive {
  background: repeating-linear-gradient(45deg, transparent, transparent 8px, var(--bg-hover) 8px, var(--bg-hover) 9px);
}

.slot-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.slot-count.ok {
  color: var(--good);
}
.slot-count.low {
  color: var(--bad);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: grab;
}

.chip .rm {
  color: var(--text-faint);
  cursor: pointer;
  font-weight: 700;
  margin-left: 4px;
}

.chip .rm:hover {
  color: var(--bad);
}

.chip .rm[data-substitute]:hover {
  color: var(--accent);
}

.chip.conflict {
  border-color: var(--bad);
}

.chip-badge {
  font-size: 11px;
  line-height: 1;
}

.chip-badge.conflict {
  filter: saturate(1.4);
}

.chip-badge.partner-ok {
  filter: saturate(1.2);
}

.chip-meal {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  margin-left: 2px;
}

.chip-meal.special {
  background: var(--good-soft);
  color: var(--good);
}

.add-btn {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-faint);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  align-self: flex-start;
}

.add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Popover / picker ---------- */
.picker {
  position: fixed;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 260px;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.picker input {
  margin: 8px;
}

.picker-list {
  overflow-y: auto;
  padding: 0 6px 6px;
}

.picker-item {
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}

.picker-item:hover {
  background: var(--bg-hover);
}

.picker-item .badge {
  color: var(--text-faint);
  font-size: 11px;
}

/* ---------- Toasts / modal ---------- */
.toast-host {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 500;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 320px;
}

.toast.error {
  border-color: var(--bad);
  color: var(--bad);
}
.toast.success {
  border-color: var(--good);
  color: var(--good);
}

.modal-host:empty {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 480px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal h3 {
  margin-top: 0;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  overflow: hidden;
  margin: 12px 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}

/* ---------- Settings ---------- */
.weight-row {
  display: grid;
  grid-template-columns: 200px 1fr 84px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.weight-row label {
  font-size: 13px;
  color: var(--text-dim);
}

input[type="range"] {
  width: 100%;
}

/* ---------- Misc ---------- */
.flex {
  display: flex;
  align-items: center;
  gap: 8px;
}

.grow {
  flex: 1;
}

.text-dim {
  color: var(--text-dim);
}

.text-faint {
  color: var(--text-faint);
}

.text-good {
  color: var(--good);
}

.text-bad {
  color: var(--bad);
}

.mt-16 {
  margin-top: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  margin: 20px 0 10px;
}

.suggestion-box {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 76px 1fr var(--statsbar-w);
  }
  .brand-text,
  .nav-item .label-text {
    display: none;
  }
  .nav-item {
    justify-content: center;
  }
}

@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
  }
  .statsbar,
  .sidebar {
    position: static;
    height: auto;
  }
}
