:root {
  /* backgrounds — layered "floating card" look, dark by default */
  --bg: #0d0d0f;
  --bg-elevated: #16171a;
  --bg-hover: #1e1f24;
  --bg-input: #1c1d22;

  /* text */
  --fg: #f2f2f3;
  --fg-secondary: #9a9ba3;
  --muted: #9a9ba3;

  /* borders / shadow */
  --border: rgba(255, 255, 255, 0.08);
  --shadow-color: rgba(0, 0, 0, 0.45);
  --shadow-card: 0 4px 20px var(--shadow-color);

  /* radius scale */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* accent / status */
  --accent: #4f8cff;
  --accent-fg: #ffffff;
  --accent-bg: rgba(79, 140, 255, 0.16);
  --danger: #f2555a;
  --danger-bg: rgba(242, 85, 90, 0.16);
  --success: #3ecf8e;
  --success-bg: rgba(62, 207, 142, 0.16);
  --warn-bg: rgba(245, 158, 11, 0.14);
  --warn-border: #f59e0b;
  --tentative-fg: #fbbf24;
  --purple: #9d6bff;
  --purple-bg: rgba(157, 107, 255, 0.16);

  /* project color palette — vivid flat colors, white text on top; must match
     PROJECT_COLOR_HEX in app/models/enums.py */
  --pcolor-blue: #4f8cff;
  --pcolor-pink: #e8618c;
  --pcolor-teal: #22b8b0;
  --pcolor-tan: #d2a24c;
  --pcolor-purple: #9d6bff;
  --pcolor-red: #f2555a;
  --pcolor-green: #3ecf8e;
  --pcolor-slate: #8b93a1;

  /* utilization badge */
  --util-bg: rgba(255, 255, 255, 0.1);
  --util-fg: var(--fg-secondary);
  --util-over-bg: var(--danger-bg);
  --util-over-fg: var(--danger);

  --sidebar-width: 220px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --bg-elevated: #f7f7f8;
    --bg-hover: #eef0f2;
    --bg-input: #ffffff;
    --fg: #1a1a1a;
    --fg-secondary: #6b7280;
    --muted: #6b7280;
    --border: #e2e2e2;
    --shadow-color: rgba(0, 0, 0, 0.12);
    --accent: #2563eb;
    --accent-bg: #eff6ff;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --warn-bg: #fff7ed;
    --tentative-fg: #92400e;
    --util-bg: #f0f0f0;
    --purple: #7c3aed;
    --purple-bg: #f5f3ff;
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- app shell / sidebar ---- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.15s ease, padding 0.15s ease;
}
html.sidebar-collapsed .sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: none;
}
.sidebar-brand {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.1rem 0.5rem 1.25rem 2.6rem;
  white-space: nowrap;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-nav a {
  display: block;
  color: var(--fg-secondary);
  font-weight: 500;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.sidebar-nav a:hover { background: var(--bg-hover); text-decoration: none; color: var(--fg); }
.sidebar-nav a.active { background: var(--accent-bg); color: var(--accent); }
.sidebar-spacer { flex: 1; }
.sidebar-logout { margin: 0; white-space: nowrap; }
.sidebar-logout button { width: 100%; }

.sidebar-toggle {
  position: fixed;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 50;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.sidebar-toggle:hover { background: var(--bg-hover); }

.app-content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; margin-top: 2rem; }

/* ---- tables (card treatment) ---- */

table {
  border-collapse: collapse;
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
th { color: var(--fg-secondary); font-weight: 600; font-size: 0.85em; }
tbody tr:last-child td { border-bottom: none; }

button, input[type="submit"] {
  font: inherit;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--fg);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.danger { color: var(--danger); }

input, select, textarea {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
  background: var(--bg-input);
  color: var(--fg);
}

form.inline { display: flex; gap: 0.5rem; align-items: center; }

form.inline.filters-dropdowns {
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.filters-dropdowns > div:not(.msdrop) { display: flex; flex-direction: column; gap: 0.3rem; }
.filters-dropdowns > div:not(.msdrop) > label { color: var(--fg-secondary); font-size: 0.85em; }
.filters-submit { padding-top: 0; }

.filter-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem 0.8rem;
  margin-bottom: 0.75rem;
}
.filter-block-label {
  font-size: 0.72em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--fg-secondary);
  margin-bottom: 0.5rem;
}
.filter-block .filters-dropdowns { margin-bottom: 0; }

/* ---- multi-select dropdown filter (checkbox list in a popover) ---- */
.msdrop { position: relative; }
.msdrop-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 220px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.msdrop-trigger:hover { background: var(--bg-hover); }
.msdrop-trigger::after { content: "▾"; color: var(--fg-secondary); flex-shrink: 0; }
.msdrop-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msdrop-count {
  flex-shrink: 0;
  min-width: 1.3em;
  padding: 0.05rem 0.4rem;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 0.75em;
  font-weight: 700;
  border-radius: 999px;
  text-align: center;
}
.msdrop-count:empty { display: none; }
.msdrop-panel {
  display: none;
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  z-index: 40;
  width: 280px;
  max-height: 320px;
  overflow-y: auto;
  padding: 0.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.msdrop.open .msdrop-panel { display: block; }
.msdrop-panel label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.5rem;
  color: var(--fg);
  font-weight: 400;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: normal;
}
.msdrop-panel label:hover { background: var(--bg-hover); }
.msdrop-panel input[type="checkbox"] { width: auto; flex-shrink: 0; margin: 0; }
.msdrop-clear {
  display: block;
  padding: 0.3rem 0.5rem 0.4rem;
  margin-bottom: 0.2rem;
  font-size: 0.8em;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0.6rem 1rem;
  align-items: center;
  max-width: 520px;
}
.form-grid label { color: var(--fg-secondary); }
.form-actions { margin-top: 1rem; display: flex; gap: 0.5rem; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8em;
}
.badge.confirmed { background: var(--accent-bg); color: var(--accent); }
.badge.tentative { background: var(--warn-bg); color: var(--tentative-fg); border: 1px dashed var(--warn-border); }
.badge.status-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge.status-finished { background: var(--success-bg); color: var(--success); }
.badge.status-planned, .badge.status-new { background: var(--util-bg); color: var(--fg-secondary); }
.badge.status-in_progress { background: var(--accent-bg); color: var(--accent); }
.badge.status-support { background: var(--purple-bg); color: var(--purple); }
.badge.status-acceptance { background: var(--warn-bg); color: var(--tentative-fg); }
.badge.status-new_hire { background: var(--util-bg); color: var(--fg-secondary); }
.badge.status-active { background: var(--success-bg); color: var(--success); }
.badge.status-inactive { background: var(--danger-bg); color: var(--danger); }
.badge.status-fixed { background: var(--accent-bg); color: var(--accent); }

.swatch-picker { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatch-option { cursor: pointer; }
.swatch-option input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--swatch-color);
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
}
.swatch-option input:checked + .swatch { border-color: var(--fg); }

.error { color: var(--danger); margin: 0.5rem 0; }
.muted { color: var(--fg-secondary); }

.login-card {
  max-width: 320px;
  margin: 15vh auto;
  padding: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.login-card h1 { font-size: 1.2rem; margin-top: 0; }

/* ---- avatar ---- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  background: hsl(var(--avatar-hue), 55%, 42%);
  color: #fff;
  font-weight: 600;
  font-size: 0.72em;
  width: 28px;
  height: 28px;
}

/* ---- timeline ---- */

#timeline {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.tl-group { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0; max-width: 200px; }
.tl-group-info { min-width: 0; flex: 1; }
.tl-group-name { font-weight: 600; font-size: 0.85em; line-height: 1.05; }
.tl-group-role {
  font-size: 0.72em;
  line-height: 1.1;
  color: var(--fg-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.util-badge {
  font-size: 0.68em;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--util-bg);
  color: var(--util-fg);
  flex-shrink: 0;
}
.util-badge.over { background: var(--util-over-bg); color: var(--util-over-fg); }

.vis-item.vis-range {
  border: none;
  padding: 0;
  background: none;
  /* item height is now scaled by load % (see .tl-item) and can exceed the
     row's normal slot — must not clip it */
  overflow: visible;
}
.vis-item .vis-item-content { padding: 0; width: 100%; }
.tl-item {
  /* NOT position:absolute — vis-timeline measures this element's real
     offsetHeight to size its own outer item box and lay out stacked/
     overlapping items, so it must stay a normal in-flow box (its height
     comes from the inline px style set by the server) rather than be
     pulled out of flow, which would measure as ~0px and collapse the row. */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.05rem;
  padding: 0.2rem 0.4rem;
  color: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  line-height: 1.2;
  overflow: hidden;
  /* height set inline per-item by the server, in px, scaled by load % —
     see MIN/MAX_ITEM_HEIGHT_PX in timeline.py; kept tight enough to fit
     these two compact lines even at the minimum */
}
.tl-item-head { display: flex; align-items: baseline; gap: 0.35rem; min-width: 0; }
.tl-item-title {
  font-weight: 600;
  font-size: 0.78em;
  /* NOT white-space:nowrap — vis-timeline measures this element's natural
     content width and uses it as a floor under the item's date-computed
     width (see minWidth in the vendored source); nowrap text can't wrap, so
     that measurement is the FULL unwrapped title, which for long project
     names silently forced short-duration bars to render far wider than
     their actual date span, making nearby bars "collide" and get pushed to
     separate lanes even with a generous date gap between them. Letting the
     text wrap keeps that natural-width measurement down to roughly its
     longest single word instead. */
  overflow: hidden;
  overflow-wrap: break-word;
  /* flex-grow:0 (not 1) so the percent badge sits right next to the title
     text instead of being pushed out to the far right edge of the whole bar
     — on a wide (long-duration) bar that edge can be scrolled off-screen
     while the title itself is still visible, taking the percent with it */
  flex: 0 1 auto;
  min-width: 0;
}
.tl-item-pct { font-size: 0.68em; font-weight: 600; flex: 0 0 auto; opacity: 0.95; }
.tl-item-sub { font-size: 0.64em; opacity: 0.85; overflow: hidden; overflow-wrap: break-word; }

.vis-item.pcolor-blue .tl-item { background: var(--pcolor-blue); }
.vis-item.pcolor-pink .tl-item { background: var(--pcolor-pink); }
.vis-item.pcolor-teal .tl-item { background: var(--pcolor-teal); }
.vis-item.pcolor-tan .tl-item { background: var(--pcolor-tan); }
.vis-item.pcolor-purple .tl-item { background: var(--pcolor-purple); }
.vis-item.pcolor-red .tl-item { background: var(--pcolor-red); }
.vis-item.pcolor-green .tl-item { background: var(--pcolor-green); }
.vis-item.pcolor-slate .tl-item { background: var(--pcolor-slate); }
.vis-item.status-tentative .tl-item {
  border: 1.5px dashed rgba(255, 255, 255, 0.7);
  opacity: 0.75;
}

#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
}
#modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  min-width: 320px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* ---- finance ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
  max-width: 720px;
}
.stat-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.25rem;
}
.stat-label { color: var(--fg-secondary); font-size: 0.8em; margin-bottom: 0.35rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; }
.stat-tile.positive .stat-value { color: var(--success); }
.stat-tile.negative .stat-value { color: var(--danger); }

.finance-table { margin-bottom: 1.5rem; }
.margin-positive { color: var(--success); }
.margin-negative { color: var(--danger); }
.finance-table tr.text-success td { color: var(--success); }
.finance-table tr.text-danger td { color: var(--danger); }

/* ---- read-only write-blocked notification ---- */
#toast-root {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 0.7rem 1rem;
  font-size: 0.9em;
  max-width: 320px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
