/* CrewBoard - Weekend Crew Scheduler (demo)
   Palette: ink slate + deep teal accent + amber signal. Ops-tool aesthetic. */

:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --ink: #1c2a2e;
  --ink-soft: #5b6b6f;
  --line: #d8dcd4;
  --line-strong: #b9c0b6;
  --accent: #0e6f5c;
  --accent-soft: #e0efe9;
  --accent-ink: #0a5646;
  --warn: #a8650a;
  --warn-soft: #fbf0da;
  --warn-line: #e3b563;
  --empty-ink: #8a978f;
  --shadow: 0 10px 30px rgba(28, 42, 46, 0.14);
  --radius: 10px;
  --font-ui: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191b;
    --surface: #1d2427;
    --surface-2: #242d30;
    --ink: #e4e9e6;
    --ink-soft: #93a2a0;
    --line: #2e393c;
    --line-strong: #43514f;
    --accent: #3dbf9d;
    --accent-soft: #17352e;
    --accent-ink: #7fdcc3;
    --warn: #e0a94f;
    --warn-soft: #33280f;
    --warn-line: #8a6c25;
    --empty-ink: #64756f;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  border-radius: 9px;
  letter-spacing: 0.5px;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12.5px;
  color: var(--ink-soft);
}

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

/* ---------- buttons ---------- */

.btn {
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); }

.btn-solid {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-solid:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

/* ---------- stat bar ---------- */

.statbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 40px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.stat { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }

.stat-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
}

.stat-value {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-range .stat-value { font-size: 15px; font-family: var(--font-mono); font-weight: 500; padding-top: 4px; }

#stat-conflict-wrap.has-conflicts .stat-value { color: var(--warn); }

.meter {
  width: 120px; height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  padding: 20px 24px 40px;
  max-width: 1240px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .roster-panel { order: -1; }

  /* position: sticky on <td>/<th> is unreliable in mobile Safari -- it can
     desync row heights between the "stuck" column/header and the rest of
     the table, producing a visually jumbled grid. Disable stickiness below
     tablet width and fall back to a plain 2-direction scroll instead. */
  .sched thead th,
  .sched .datecol,
  .sched thead .datecol {
    position: static;
  }
}

/* ---------- schedule grid ---------- */

.grid-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ---------- view tabs ---------- */

.view-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: color 0.12s, background 0.12s;
}
.tab-btn:hover { color: var(--ink); background: var(--surface); }
.tab-btn.active { color: var(--accent-ink); border-bottom-color: var(--accent); background: var(--surface); }

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

.sched {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 760px;
}

.sched th, .sched td {
  border-bottom: 1px solid var(--line);
  padding: 0;
}

.sched thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  text-align: left;
  padding: 10px 12px;
  white-space: nowrap;
}

.sched thead th .role-hint {
  display: block;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--empty-ink);
  margin-top: 1px;
}

.sched .datecol {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 10px 14px;
  white-space: nowrap;
  vertical-align: top;
  min-width: 168px;
}

.sched thead .datecol { z-index: 3; background: var(--surface-2); }

tr.weekend-start .datecol,
tr.weekend-start td { border-top: 2px solid var(--line-strong); }

.date-main {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 600;
}
.date-main .dow { color: var(--accent); margin-right: 6px; }

.date-event {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: normal;
  max-width: 170px;
}

/* slots */

.slot { padding: 6px 8px; vertical-align: middle; min-width: 118px; }

.slot-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background 0.12s, opacity 0.15s;
}
.slot-btn:hover { border-color: var(--accent); }

.slot-btn.empty {
  background: transparent;
  border: 1px dashed var(--line-strong);
  color: var(--empty-ink);
  font-weight: 400;
}
.slot-btn.empty:hover { border-color: var(--accent); color: var(--accent); border-style: solid; }

.slot-btn.conflict {
  background: var(--warn-soft);
  border: 1px solid var(--warn-line);
}
.slot-btn.conflict::after {
  content: attr(data-conf);
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--warn);
}

.slot-btn.dimmed { opacity: 0.28; }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex: none;
}

.grid-hint {
  margin: 0;
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* ---------- availability grid ---------- */

.avail-table { min-width: 640px; }

.avail-table .datecol {
  min-width: 130px;
}

.avail-person {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.avail-cell { text-align: center; vertical-align: middle; padding: 8px; }

.avail-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}

.avail-mark.yes {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.avail-mark.no {
  background: var(--surface-2);
  color: var(--empty-ink);
}

/* ---------- roster ---------- */

.roster-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 16px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-note { font-size: 12px; color: var(--ink-soft); }

.roster { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.roster-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13.5px;
  background: transparent;
  width: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.roster-item:hover { background: var(--surface-2); }
.roster-item.active { background: var(--accent-soft); border-color: var(--accent); }

.roster-name { font-weight: 500; flex: 1; }

.roster-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.add-form { display: flex; gap: 8px; }
.add-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: 16px; /* iOS Safari auto-zooms on focus below this */
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
}
.add-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.demo-note {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: var(--empty-ink);
}

/* ---------- popover ---------- */

.popover {
  position: absolute;
  z-index: 50;
  min-width: 230px;
  max-width: 280px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.popover-head {
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.popover-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.popover-list button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  font-family: var(--font-ui);
  font-size: 13.5px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.popover-list button:hover { background: var(--surface-2); }
.popover-list button.current { background: var(--accent-soft); font-weight: 600; }

.popover-list .p-name { flex: 1; }

.popover-list .p-load {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.popover-list .p-busy {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid var(--warn-line);
  border-radius: 4px;
  padding: 1px 5px;
}

.popover-list .p-unassign { color: var(--warn); font-weight: 600; }
.popover-list li.divider { border-top: 1px solid var(--line); margin: 5px 4px; }

/* ---------- confirm dialog ---------- */

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(20, 25, 27, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.confirm-overlay[hidden] { display: none; }

.confirm-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}

.confirm-msg {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--ink);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- language toggle ---------- */

.btn-lang {
  font-family: var(--font-mono);
  min-width: 64px;
}

/* ---------- access gate ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate[hidden] { display: none; }

.gate-lang-corner {
  position: absolute;
  top: 16px;
  right: 20px;
  font-family: var(--font-mono);
  min-width: 64px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 30px 30px;
  text-align: center;
}

.gate-card .brand-mark { margin: 0 auto 14px; }

.gate-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.gate-note {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--ink-soft);
}

.gate-form { display: flex; gap: 8px; }

.gate-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 16px; /* iOS Safari auto-zooms on focus below this */
  letter-spacing: 0.1em;
  text-align: center;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
}
.gate-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.gate-error {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--warn);
}
.gate-error[hidden] { display: none; }
