:root {
  --bg: #17191e;
  --bg-raised: #1e2127;
  --bg-card: #262a31;
  --bg-card-hover: #2c313a;
  --border: #2e333c;
  --border-soft: #262b33;
  --text: #e8eaed;
  --text-dim: #9aa1ab;
  --accent: #4f8ef7;
  --danger: #ef4444;
  --radius: 10px;
  --week-w: 168px;
  --row-h: 118px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Top chrome ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px 4px;
}
.crumbs { color: var(--text-dim); font-size: 13px; }
.crumbs .brand { color: var(--text); font-weight: 600; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.demo-badge {
  background: #4b3a11; color: #fbbf24; border: 1px solid #6b5416;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; cursor: pointer;
}

.title-row {
  display: flex; align-items: baseline; gap: 12px;
  padding: 6px 20px 2px;
}
.title-row h1 { margin: 0; font-size: 26px; }
.subtitle { color: var(--text-dim); font-size: 13px; }
.count-pill {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--text-dim);
}
.count-pill.small { padding: 0 6px; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  flex-wrap: wrap;
}
.range-pill {
  border: 1px solid var(--border); background: var(--bg-raised);
  border-radius: 8px; padding: 7px 14px; font-weight: 600; font-size: 13px;
  cursor: pointer;
}
.range-pill:hover { border-color: var(--accent); }

/* View settings popover (opens from the range pill) */
.toolbar { position: relative; }
.popover {
  position: absolute; top: 44px; left: 20px; z-index: 180;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; width: 320px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.6);
}
.popover h3 { margin: 0 0 4px; font-size: 14px; }
.pop-hint { color: var(--text-dim); font-size: 12px; margin: 0 0 12px; }
.pop-grid { display: flex; gap: 10px; margin-bottom: 12px; }
.popover label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-dim); flex: 1;
}
.popover input[type="month"], .popover select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; color-scheme: dark; width: 100%;
}
.popover .pop-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.pop-check {
  flex-direction: row !important; align-items: center; gap: 8px !important;
  color: var(--text) !important; font-size: 13px !important;
}
.pop-check input { accent-color: var(--accent); width: auto; }
.ctl { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 13px; }
select, .search {
  background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 13px; outline: none;
}
select:focus, .search:focus { border-color: var(--accent); }
.search { margin-left: auto; width: 300px; }

.btn {
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--text);
}
.btn:hover { background: var(--bg-card-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }

/* ---- Layout ---- */
.layout { flex: 1; display: flex; min-height: 0; border-top: 1px solid var(--border-soft); }

.tray {
  width: 250px; flex: none; border-right: 1px solid var(--border-soft);
  background: var(--bg-raised); padding: 14px; overflow-y: auto;
}
.tray-head { display: flex; align-items: center; gap: 8px; }
.tray-hint { color: var(--text-dim); font-size: 12px; }
.tray-list { display: flex; flex-direction: column; gap: 8px; }
.tray-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; cursor: grab; user-select: none;
}
.tray-card:active { cursor: grabbing; }
.tray-card .t-name { font-weight: 600; font-size: 13px; }
.tray-card .t-meta { display: flex; gap: 6px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.tray-empty { color: var(--text-dim); font-size: 12px; font-style: italic; }

/* ---- Gantt ---- */
.gantt-wrap { flex: 1; overflow: auto; position: relative; }
.gantt { position: relative; min-height: 100%; }

.gantt-header {
  display: flex; position: sticky; top: 0; z-index: 30;
  background: var(--bg-raised); border-bottom: 1px solid var(--border);
}
.week-head {
  width: var(--week-w); flex: none; text-align: center;
  padding: 10px 4px; font-size: 12.5px; font-weight: 600; color: var(--text-dim);
  border-right: 1px dashed transparent;
}
.week-head.current { color: var(--text); }

.gantt-body { position: relative; }
.grid-lines { position: absolute; inset: 0; pointer-events: none; }
.grid-line {
  position: absolute; top: 0; bottom: 0; width: 0;
  border-left: 1px dashed var(--border-soft);
}
.today-line {
  position: absolute; top: 0; bottom: 0; width: 0;
  border-left: 2px solid var(--danger); z-index: 4; pointer-events: none;
}
.today-badge {
  position: absolute; bottom: 2px; transform: translateX(-50%);
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 8px; border-radius: 4px; pointer-events: none;
}

.group-band {
  position: absolute; left: 0; right: 0; z-index: 6;
  padding: 8px 0 2px; pointer-events: none;
}
.band-inner {
  position: sticky; left: 14px;
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: 14px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim);
}
.band-inner .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ---- Cards ---- */
.card {
  position: absolute; z-index: 10;
  display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  cursor: grab; user-select: none;
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.card:hover { background: var(--bg-card-hover); box-shadow: 0 4px 14px rgba(0,0,0,0.5); }
.card.dragging { opacity: 0.85; cursor: grabbing; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,0.6); }
.card .c-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card .c-name { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-menu-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 4px; flex: none;
}
.card .c-menu-btn:hover { background: var(--border); color: var(--text); }
.card .c-desc {
  color: var(--text-dim); font-size: 12.5px; margin-top: 4px;
  flex: 1; min-height: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .c-chips {
  display: flex; gap: 6px; margin-top: auto; padding-top: 6px;
  flex-wrap: nowrap; overflow: hidden; align-items: center;
}

.chip {
  font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 6px;
  border: 1px solid transparent; white-space: nowrap;
}
.chip.status { background: rgba(255,255,255,0.06); }
.chip.topic { background: #17335f; color: #7fb1ff; border-color: #23477e; }
.chip.votes { background: rgba(255,255,255,0.06); color: var(--text-dim); }
.chip.health-on_track { background: #10331d; color: #4ade80; border-color: #1c5230; }
.chip.health-at_risk { background: #4b3a11; color: #fbbf24; border-color: #6b5416; }
.chip.health-off_track { background: #451a1a; color: #f87171; border-color: #6b2525; }

/* Narrow cards: progressively hide detail so content never spills */
.card.compact .c-desc { display: none; }
.card.compact .c-chips .chip.topic, .card.compact .c-chips .chip.votes { display: none; }
.card.tiny .c-chips { display: none; }
.card.tiny { padding: 8px; }

/* Bar mode (quarters zoom): slim single-line bars */
.card.bar {
  flex-direction: row; align-items: center; gap: 8px;
  padding: 0 26px 0 12px; border-radius: 8px;
}
.card.bar .c-name { font-size: 13px; font-weight: 600; }
.card.bar .c-menu-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.h-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* Bars too narrow for their title: the label floats outside, to the right */
.card.spill { overflow: visible; }
.card.spill .c-chips, .card.spill .c-desc { display: none; }
.card.spill .c-name {
  position: absolute; left: calc(100% + 8px); top: 10px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
  background: rgba(13, 15, 19, 0.85); border: 1px solid var(--border-soft);
  padding: 3px 8px; border-radius: 6px; font-size: 12.5px;
  pointer-events: none;
}
.card.bar.spill .c-name { top: 50%; transform: translateY(-50%); }
.card.spill:not(.bar) .h-dot { position: absolute; left: 12px; bottom: 12px; }
.card.spill .c-head { position: static; }
.card.spill:not(.bar) .c-menu-btn { position: absolute; top: 8px; right: 8px; }

.resize-handle {
  position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 12;
}
.resize-handle.left { left: 0; border-radius: var(--radius) 0 0 var(--radius); }
.resize-handle.right { right: 0; border-radius: 0 var(--radius) var(--radius) 0; }
.resize-handle:hover { background: rgba(79,142,247,0.35); }

/* ---- Drop preview / drag tooltip ---- */
.drop-ghost {
  position: absolute; z-index: 8; border: 2px dashed var(--accent);
  border-radius: var(--radius); background: rgba(79,142,247,0.08); pointer-events: none;
}
.drag-tip {
  position: fixed; z-index: 100; pointer-events: none;
  background: #000; border: 1px solid var(--border); color: var(--text);
  font-size: 12px; padding: 4px 10px; border-radius: 6px; white-space: nowrap;
}

/* ---- Modal & menu ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: 440px; max-width: 90vw;
}
.modal h2 { margin: 0 0 8px; }
.modal p { color: var(--text-dim); font-size: 13px; }
.modal input {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.error { color: var(--danger); font-size: 12.5px; }

.menu {
  position: fixed; z-index: 210; background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6); min-width: 200px;
}
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--text); padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.menu button:hover { background: var(--bg-card-hover); }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---- Tray category toggles ---- */
.tray-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.tray-filter {
  font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  cursor: pointer; user-select: none;
}
.tray-filter.off { opacity: 0.35; text-decoration: line-through; }

/* ---- Idea detail drawer ---- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 92vw;
  background: var(--bg-raised); border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,0.5); z-index: 150;
  padding: 18px 22px 30px; overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.drawer-crumb { color: var(--text-dim); font-size: 12.5px; }
.drawer-close { padding: 4px 10px; }
.drawer h2 { margin: 4px 0 10px; font-size: 21px; line-height: 1.3; }
.dw-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.dw-desc { color: var(--text); font-size: 13.5px; line-height: 1.55; }
.dw-desc p { margin: 0 0 8px; }
.dw-desc img { max-width: 100%; border-radius: 8px; }
.dw-section {
  border-top: 1px solid var(--border); margin-top: 18px; padding-top: 14px;
}
.dw-section h3 {
  margin: 0 0 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-dim);
}
.dw-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.dw-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.dw-grid input, .dw-grid select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; color-scheme: dark;
}
.dw-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.dw-meta { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; margin: 0 0 14px; }
.dw-meta dt { color: var(--text-dim); }
.dw-meta dd { margin: 0; }
#dw-link { display: inline-block; text-decoration: none; }

.hidden { display: none !important; }

/* ---- Touch support ---- */
/* Cards intercept touch for drag/resize; empty grid still pans the chart. */
.card, .resize-handle { touch-action: none; }

.tray-toggle { display: none; }
.tray-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 135; }

/* ---- Mobile (portrait phones / narrow windows) ---- */
@media (max-width: 900px) {
  .tray-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .tray {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(85vw, 320px);
    z-index: 140; transform: translateX(-105%);
    transition: transform 0.22s ease; box-shadow: 12px 0 40px rgba(0,0,0,0.5);
  }
  .tray.open { transform: none; }

  .topbar, .title-row, .toolbar { padding-left: 12px; padding-right: 12px; }
  .title-row h1 { font-size: 20px; }
  .subtitle { display: none; }
  .toolbar { gap: 8px; }
  .search { width: 100%; margin-left: 0; order: 9; }
  .ctl { font-size: 12px; }

  .drawer { width: 100vw; max-width: 100vw; border-left: none; }
  .popover { left: 12px; right: 12px; width: auto; }
  .modal { padding: 18px; }
}

/* ---- Landscape phones: shrink chrome so the chart gets the height ---- */
@media (max-height: 520px) {
  .title-row { display: none; }
  .topbar { padding: 6px 12px 2px; }
  .toolbar { padding: 6px 12px; gap: 6px; }
  .search { width: 180px; order: 0; }
  .tray-hint { display: none; }
  .week-head { padding: 6px 4px; }
}

::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
