:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #dfe4ee;
  --text: #16233b;
  --text-muted: #5d6b85;
  --accent: #1a56db;
  --accent-soft: #e8effc;
  --accent-text: #1a56db;
  --success: #16794f;
  --error: #b42318;
  --shadow: 0 1px 2px rgb(22 35 59 / 0.05), 0 4px 16px rgb(22 35 59 / 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1420;
    --surface: #171f2f;
    --surface-2: #1e2839;
    --border: #2b374d;
    --text: #e7ecf5;
    --text-muted: #93a1ba;
    --accent: #3b74e8;
    --accent-soft: #1c2c4d;
    --accent-text: #8db0f5;
    --success: #4ade9a;
    --error: #f28b82;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.35);
  }
}

* { box-sizing: border-box; }

/* The display rules below (flex labels etc.) must never defeat the hidden attribute. */
[hidden] { display: none !important; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 980px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 6rem;
  line-height: 1.45;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-logo {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
}

.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }
.brand-sub { margin: 0; font-size: 0.8rem; color: var(--text-muted); }

nav { display: flex; gap: 0.4rem; background: var(--surface-2); padding: 0.25rem; border-radius: 10px; }

.tab {
  padding: 0.45rem 1rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Cards & fields ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-head-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.team-actions { display: flex; gap: 0.5rem; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem 1rem;
}

.span-2 { grid-column: span 2; }
@media (max-width: 560px) { .span-2 { grid-column: span 1; } }

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; font-weight: 550; color: var(--text-muted); }

input, select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); padding: 0; }

.check-row { flex-direction: row; align-items: center; gap: 0.5rem; align-self: end; padding-bottom: 0.4rem; font-weight: 550; }
.check-row em { font-style: normal; color: var(--text-muted); font-weight: 400; }

.field-hint { font-size: 0.75rem; font-weight: 400; color: var(--text-muted); }
.hint { font-size: 0.83rem; color: var(--text-muted); margin: 0 0 0.75rem; }

.subtle-details { margin-top: 0.9rem; }
.subtle-details summary { cursor: pointer; font-size: 0.83rem; color: var(--text-muted); margin-bottom: 0.6rem; }

.pill {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

/* ---------- Suckiness chips ---------- */

.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.9rem; }

.chip {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  background: var(--surface);
  font-size: 0.85rem;
  color: var(--text);
  user-select: none;
  transition: border-color 120ms, background 120ms;
}

.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip em { font-style: normal; font-weight: 700; opacity: 0.75; }

.slider-row { display: flex; align-items: center; gap: 0.75rem; }
.slider-row input[type="range"] { flex: 1; }
.slider-row output { font-weight: 700; min-width: 3.2rem; text-align: right; font-size: 0.95rem; color: var(--text); }

/* ---------- Team ---------- */

.quick-fill {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.quick-fill label { flex-direction: row; align-items: center; gap: 0.4rem; margin: 0; font-weight: 500; }
.quick-fill input { padding: 0.3rem 0.45rem; font-size: 0.85rem; }
.quick-fill input[type="number"] { width: 4.5rem; }
.quick-fill-label { font-weight: 650; color: var(--text-muted); }

.person-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.5rem;
  background: var(--surface);
  transition: border-color 120ms, background 120ms;
}

.person-card.is-involved { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 30%, var(--surface)); }

.person-head {
  display: grid;
  grid-template-columns: minmax(9rem, 1.4fr) minmax(7rem, 1fr) minmax(8rem, 1.2fr) minmax(8.5rem, auto) auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
}

.person-remove {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  opacity: 0.5;
}
.person-remove:hover { color: var(--error); background: var(--surface-2); opacity: 1; }

@media (max-width: 640px) {
  .person-head { grid-template-columns: 1fr 1fr; }
  .person-range { order: 3; }
}

.involve { flex-direction: row; align-items: center; gap: 0.55rem; margin: 0; }

.person-name {
  border: 1px solid transparent;
  background: transparent;
  font-weight: 650;
  font-size: 0.95rem;
  padding: 0.3rem 0.4rem;
  width: 100%;
}
.person-name:hover, .person-name:focus-visible { border-color: var(--border); background: var(--surface); }

.person-range { font-size: 0.9rem; font-weight: 650; color: var(--accent-text); white-space: nowrap; text-align: right; }

/* Uninvolved rows collapse to a compact checkbox + name + role line — no dead
   space reserved for the range/bonus columns until someone is checked. */
.person-card:not(.is-involved) .person-head {
  grid-template-columns: minmax(9rem, 1fr) minmax(9rem, 14rem) auto;
}
.person-card:not(.is-involved) .person-range,
.person-card:not(.is-involved) .bonus-wrap { display: none; }

.bonus-wrap { display: flex; align-items: center; gap: 0.3rem; justify-self: end; }
.bonus-prefix { color: var(--text-muted); font-weight: 600; }
.bonus-wrap input { width: 6rem; font-weight: 650; text-align: right; }

.bonus-auto {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
}
.bonus-auto:hover { color: var(--accent-text); border-color: var(--accent); }

.person-body { padding: 0.25rem 0.75rem 0.75rem; border-top: 1px dashed var(--border); margin-top: 0.1rem; padding-top: 0.75rem; }

.person-days input { max-width: 7rem; }

.extra-days { margin-top: 0.75rem; }
.extra-days-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.4rem; }
.extra-days-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.extra-day {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.25rem 0.35rem 0.25rem 0.6rem;
}
.extra-day label { flex-direction: row; align-items: center; gap: 0.4rem; margin: 0; font-size: 0.8rem; }
.extra-day input { width: 4.5rem; padding: 0.3rem 0.4rem; font-size: 0.85rem; }
.extra-day button {
  border: none; background: none; color: var(--text-muted);
  font-size: 1rem; cursor: pointer; padding: 0 0.3rem; border-radius: 4px;
}
.extra-day button:hover { color: var(--error); }

.person-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

.link-btn { border: none; background: none; color: var(--accent-text); font-size: 0.83rem; font-weight: 600; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

.hours-breakdown { font-size: 0.8rem; color: var(--text-muted); }

/* ---------- Helpdesk (collapsible card) ---------- */

.collapsible-card > summary { cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.collapsible-card > summary::-webkit-details-marker { display: none; }
.collapsible-card > summary h2 { margin: 0; }
.collapsible-card > summary .hint { margin: 0; }
.collapsible-card > summary::before { content: '▸'; color: var(--text-muted); font-size: 0.8rem; }
.collapsible-card[open] > summary::before { content: '▾'; }
.collapsible-card[open] > summary { margin-bottom: 0.75rem; }

/* ---------- Edit banner ---------- */

.edit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}

/* ---------- Save bar ---------- */

.save-bar {
  position: sticky;
  bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgb(22 35 59 / 0.18);
  padding: 0.75rem 1.1rem;
  z-index: 10;
}

.save-bar-stats { display: flex; gap: 2rem; }

.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 700; }
.stat strong { font-size: 1.15rem; letter-spacing: -0.01em; }
.stat-detail { font-size: 0.72rem; color: var(--text-muted); }

.save-bar-actions { display: flex; align-items: center; gap: 0.9rem; }

.btn-primary {
  padding: 0.65rem 1.4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  padding: 0.35rem 0.9rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.83rem;
  font-weight: 650;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-text); }

.btn-danger:hover { border-color: var(--error); color: var(--error); }
.row-actions { white-space: nowrap; }
.row-actions button + button { margin-left: 0.35rem; }

#form-message { margin: 0; font-size: 0.85rem; font-weight: 600; }
#form-message.success { color: var(--success); }
#form-message.error { color: var(--error); }

/* ---------- History ---------- */

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
th.num, td.num { text-align: right; }
td.num { font-weight: 650; }
tbody tr:hover { background: var(--surface-2); }

.row-sub { display: block; font-size: 0.75rem; color: var(--text-muted); }

.expander {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}
.expander:hover { color: var(--accent-text); background: var(--surface-2); }

.detail-row > td { background: var(--surface-2); padding: 0.75rem 1rem; }
.history-detail .detail-line { margin: 0 0 0.6rem; font-size: 0.85rem; }
.detail-factors { display: block; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }
.detail-table { width: 100%; }
.detail-table th, .detail-table td { font-size: 0.82rem; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); }
.detail-table tbody tr:last-child td { border-bottom: none; }
