:root {
  color-scheme: light;
  --ink: #142033;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #dce4ec;
  --surface: #ffffff;
  --surface-soft: #f4f7fb;
  --surface-tint: #e9f7f6;
  --teal: #008f8c;
  --teal-dark: #06716f;
  --navy: #13243b;
  --warning: #d97706;
  --danger: #dc2626;
  --success: #169c62;
  --shadow: 0 18px 48px rgba(23, 42, 70, .13);
  --shadow-soft: 0 8px 24px rgba(23, 42, 70, .09);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--surface-soft);
  color: var(--ink);
  font: 16px/1.5 Inter, Manrope, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body.locked { overflow: hidden; }
body.locked > .app-header,
body.locked > .app-shell { visibility: hidden; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0; color: var(--teal-dark); font-size: .72rem; font-weight: 850; letter-spacing: .13em; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}
.button.primary { background: var(--teal); color: #fff; }
.button.primary:hover { background: var(--teal-dark); }
.button.secondary { border-color: var(--line); background: var(--surface); }
.button.secondary:hover { border-color: #9ccfcd; background: var(--surface-tint); color: var(--teal-dark); }

.app-header {
  position: relative;
  z-index: 40;
  height: 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 3px 16px rgba(24, 43, 70, .05);
  backdrop-filter: blur(15px);
}
.brand { width: max-content; display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand img { width: 42px; height: 42px; object-fit: contain; }
.brand span { display: grid; line-height: 1.05; }
.brand strong { font-size: 1.18rem; }
.brand small { margin-top: 5px; color: var(--muted); font-size: .75rem; }
.view-switch { display: flex; gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.view-switch a { min-width: 76px; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: .84rem; font-weight: 750; text-align: center; text-decoration: none; }
.view-switch a:hover { color: var(--teal-dark); }
.view-switch a.active { background: var(--surface); box-shadow: 0 2px 7px rgba(24, 43, 70, .08); color: var(--ink); }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 11px; }
.storage-status { color: var(--muted); font-size: .78rem; }
.storage-status.saving { color: var(--warning); }
.storage-status.offline { color: var(--danger); }
.storage-status.synced { color: var(--success); }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.icon-button:hover { border-color: #9ccfcd; background: var(--surface-tint); }

.planning-shell { height: calc(100vh - 72px); display: grid; grid-template-rows: auto minmax(0, 1fr); }
.planning-toolbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(500px, auto);
  align-items: center;
  gap: 26px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.project-heading { display: flex; align-items: center; gap: 26px; }
.project-heading h1 { margin: 2px 0 0; font-size: clamp(1.45rem, 2.2vw, 2rem); line-height: 1.05; }
.overall-progress { min-width: 240px; display: grid; gap: 7px; }
.overall-progress > span { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.overall-progress strong { font-size: 1.18rem; }
.overall-progress small { color: var(--muted); font-size: .75rem; }
.progress-track { height: 7px; overflow: hidden; border-radius: 99px; background: #e6edf3; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #2fc3a7); transition: width .2s ease; }
.map-filters { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.search-field { flex: 1 1 290px; }
.map-filters input, .map-filters select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background: var(--surface-soft);
  color: var(--ink);
}
.map-filters input:focus, .map-filters select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 143, 140, .1); }
.map-filters select { min-width: 175px; }

.planning-workspace { min-height: 0; display: grid; grid-template-columns: 292px minmax(0, 1fr); }
.next-panel {
  position: relative;
  z-index: 10;
  overflow: auto;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}
.panel-heading { display: flex; align-items: center; gap: 11px; }
.panel-heading h2 { margin: 2px 0 0; font-size: 1.1rem; }
.panel-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-tint); color: var(--teal-dark); font-size: 1.25rem; font-weight: 850; }
.panel-copy { margin: 14px 0 18px; color: var(--muted); font-size: .82rem; }
.next-task-list { display: grid; gap: 8px; }
.next-task {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: inherit;
  text-align: left;
}
.next-task:hover { border-color: #9ccfcd; box-shadow: var(--shadow-soft); }
.next-task .status-dot { margin-top: 5px; }
.next-task strong { display: block; overflow: hidden; font-size: .82rem; line-height: 1.35; text-overflow: ellipsis; }
.next-task small { display: block; margin-top: 4px; color: var(--muted); font-size: .7rem; }
.next-task.overdue small { color: var(--danger); font-weight: 750; }
.empty-next { padding: 20px 10px; border: 1px dashed var(--line); border-radius: 13px; color: var(--muted); font-size: .82rem; text-align: center; }
.map-legend { display: grid; gap: 8px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: .72rem; }
.map-legend span { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 9px; height: 9px; display: inline-block; flex: 0 0 auto; border-radius: 50%; background: #aeb9c7; }
.status-dot.in-progress { background: var(--warning); }
.status-dot.completed { background: var(--success); }

.canvas-panel { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--surface-soft); }
.canvas-hint {
  position: absolute;
  z-index: 8;
  top: 12px;
  left: 50%;
  display: flex;
  gap: 14px;
  padding: 7px 11px;
  border: 1px solid rgba(210, 220, 230, .9);
  border-radius: 10px;
  background: rgba(255, 255, 255, .88);
  color: var(--muted);
  font-size: .7rem;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
  pointer-events: none;
}
.canvas-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  outline: none;
  cursor: grab;
  touch-action: none;
  background-color: #f5f8fb;
  background-image: radial-gradient(circle, #cdd8e4 1.2px, transparent 1.3px);
  background-size: 24px 24px;
}
.canvas-viewport:focus-visible { box-shadow: inset 0 0 0 3px rgba(0, 143, 140, .35); }
.canvas-viewport.is-panning { cursor: grabbing; }
.canvas-world { position: absolute; left: 0; top: 0; width: 2500px; height: 1800px; transform-origin: 0 0; will-change: transform; }
.connections { position: absolute; inset: 0; width: 2500px; height: 1800px; overflow: visible; pointer-events: none; }
.connection-path { fill: none; stroke: var(--branch, #8bc7c5); stroke-width: 4; stroke-linecap: round; opacity: .58; transition: opacity .2s ease; }
.connection-dot { fill: var(--branch, #8bc7c5); opacity: .9; }
.connection-group.is-dimmed { opacity: .12; }

.project-node {
  position: absolute;
  left: 1075px;
  top: 790px;
  z-index: 3;
  width: 350px;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 26px 28px;
  border: 1px solid #243b58;
  border-radius: 24px;
  background: linear-gradient(145deg, #172b46, #102035);
  box-shadow: 0 26px 60px rgba(14, 35, 58, .26);
  color: #fff;
}
.project-node::after { content: ""; position: absolute; inset: 9px; border: 1px solid rgba(255, 255, 255, .08); border-radius: 17px; pointer-events: none; }
.project-kicker { color: #63d5cc; font-size: .67rem; font-weight: 850; letter-spacing: .14em; }
.project-node h2 { margin: 6px 0 1px; font-size: 2rem; line-height: 1.05; }
.project-node p { margin: 0; color: #b9c8d9; font-size: .88rem; }
.project-node-progress { display: flex; align-items: baseline; justify-content: space-between; margin-top: 19px; padding-top: 13px; border-top: 1px solid rgba(255, 255, 255, .13); }
.project-node-progress strong { font-size: 1.35rem; }
.project-node-progress span { color: #b9c8d9; font-size: .78rem; }

.stage-node {
  --branch: #159d99;
  position: absolute;
  z-index: 4;
  width: 330px;
  min-height: 238px;
  overflow: hidden;
  border: 1px solid #d4dfe9;
  border-top: 4px solid var(--branch);
  border-radius: 18px;
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow-soft);
  transition: opacity .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.stage-node:hover { border-color: color-mix(in srgb, var(--branch) 48%, #d4dfe9); box-shadow: var(--shadow); }
.stage-node.is-dimmed { opacity: .23; }
.stage-node.is-complete { background: #f8fcfa; }
.stage-node-header { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 13px 14px 10px; }
.stage-number { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: color-mix(in srgb, var(--branch) 11%, white); color: var(--branch); font-size: .72rem; font-weight: 900; }
.stage-title-button { min-width: 0; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.stage-title-button strong { display: block; overflow: hidden; font-size: .93rem; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.stage-title-button small { display: block; margin-top: 4px; color: var(--muted); font-size: .68rem; }
.stage-drag-handle { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--faint); cursor: grab; font-size: 1rem; letter-spacing: -2px; }
.stage-drag-handle:hover { background: var(--surface-soft); color: var(--ink); }
.stage-drag-handle:active { cursor: grabbing; }
.stage-progress { height: 5px; margin: 0 14px 9px; overflow: hidden; border-radius: 99px; background: #e9eef3; }
.stage-progress i { display: block; height: 100%; border-radius: inherit; background: var(--branch); }
.node-task-list { min-height: 124px; display: grid; align-content: start; gap: 3px; padding: 0 10px 10px; }
.node-task {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 3px 6px;
  border-radius: 9px;
}
.node-task:hover { background: var(--surface-soft); }
.node-task.completed .node-task-open { color: var(--faint); text-decoration: line-through; }
.map-checkbox { appearance: none; width: 22px; height: 22px; display: grid; place-items: center; margin: 0; border: 1.5px solid #aebbc8; border-radius: 7px; background: #fff; cursor: pointer; }
.map-checkbox::after { content: "✓"; color: transparent; font-size: .82rem; font-weight: 900; line-height: 1; }
.map-checkbox:checked { border-color: var(--success); background: var(--success); }
.map-checkbox:checked::after { color: #fff; }
.map-checkbox:focus-visible { outline: 3px solid rgba(0, 143, 140, .18); outline-offset: 2px; }
.node-task-open { overflow: hidden; padding: 3px 0; border: 0; background: transparent; color: var(--ink); font-size: .74rem; font-weight: 650; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.node-task-open:hover { color: var(--teal-dark); }
.more-tasks { width: calc(100% - 28px); min-height: 29px; margin: 0 14px 11px; border: 0; border-radius: 8px; background: color-mix(in srgb, var(--branch) 8%, white); color: var(--branch); font-size: .7rem; font-weight: 800; }
.more-tasks:hover { background: color-mix(in srgb, var(--branch) 14%, white); }
.node-empty { padding: 22px 10px; color: var(--muted); font-size: .72rem; text-align: center; }

.zoom-controls {
  position: absolute;
  z-index: 9;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
}
.zoom-controls button { min-width: 38px; height: 36px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font-weight: 800; }
.zoom-controls button:hover { background: var(--surface-tint); color: var(--teal-dark); }
.zoom-controls span { min-width: 50px; color: var(--muted); font-size: .72rem; text-align: center; }

.drawer-backdrop { position: fixed; z-index: 70; inset: 0; background: rgba(16, 32, 53, .28); backdrop-filter: blur(2px); }
.map-drawer {
  position: fixed;
  z-index: 80;
  inset: 0 0 0 auto;
  width: min(650px, 100%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -22px 0 55px rgba(23, 42, 70, .15);
  transform: translateX(102%);
  transition: transform .22s ease;
}
.map-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.drawer-header span { color: var(--teal-dark); font-size: .68rem; font-weight: 850; letter-spacing: .12em; }
.drawer-header h2 { margin: 4px 0 0; font-size: 1.45rem; line-height: 1.15; }
.drawer-close { width: 42px; height: 42px; border: 0; border-radius: 11px; background: var(--surface-soft); color: var(--ink); font-size: 1.7rem; }
.drawer-close:hover { background: var(--surface-tint); }
.drawer-body { overflow: auto; padding: 22px 24px 50px; }
.drawer-stage-goal { margin: 0; color: var(--muted); font-size: .9rem; }
.drawer-stage-progress { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 13px; margin: 17px 0 23px; color: var(--muted); font-size: .75rem; }
.drawer-stage-progress > div { height: 6px; overflow: hidden; border-radius: 99px; background: #e8edf2; }
.drawer-stage-progress i { display: block; height: 100%; border-radius: inherit; background: var(--teal); }
.drawer-section { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: #fbfcfe; }
.drawer-section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.drawer-section-heading h3 { margin: 0; font-size: 1rem; }
.drawer-section-heading span { color: var(--muted); font-size: .7rem; }
.drawer-task-list { display: grid; gap: 6px; }
.drawer-task-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 7px; border-radius: 10px; }
.drawer-task-row:hover, .drawer-task-row.active { background: var(--surface); box-shadow: 0 2px 10px rgba(23, 42, 70, .06); }
.drawer-task-row.completed .drawer-task-open { color: var(--faint); text-decoration: line-through; }
.drawer-task-open { min-width: 0; padding: 3px 0; border: 0; background: transparent; color: inherit; font-size: .82rem; font-weight: 680; text-align: left; }
.drawer-task-open:hover { color: var(--teal-dark); }
.mini-status { padding: 4px 7px; border-radius: 99px; background: #edf1f5; color: var(--muted); font-size: .62rem; font-weight: 800; white-space: nowrap; }
.mini-status.in_progress { background: #fff3dc; color: #a65a00; }
.mini-status.completed { background: #e5f6ee; color: #087848; }

.task-detail { margin-top: 18px; padding: 20px; border: 1px solid #cae4e2; border-radius: 17px; background: #f5fbfa; }
.task-detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.task-detail-heading p { margin: 0 0 3px; color: var(--muted); font-size: .7rem; }
.task-detail-heading h3 { margin: 0; font-size: 1.15rem; line-height: 1.25; }
.detail-status { flex: 0 0 auto; padding: 5px 8px; border-radius: 99px; background: #edf1f5; color: var(--muted); font-size: .66rem; font-weight: 800; }
.detail-status.in_progress { background: #fff3dc; color: #a65a00; }
.detail-status.completed { background: #e1f5eb; color: #087848; }
.task-detail-description { margin: 10px 0 18px; color: var(--muted); font-size: .84rem; }
.task-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-bottom: 20px; }
.task-controls label, .note-field { display: grid; gap: 6px; color: var(--muted); font-size: .72rem; font-weight: 750; }
.task-controls input, .task-controls select, .note-field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; outline: none; background: var(--surface); color: var(--ink); }
.task-controls input, .task-controls select { min-height: 42px; }
.task-controls input:focus, .task-controls select:focus, .note-field textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 143, 140, .1); }
.detail-copy { padding: 13px 0; border-top: 1px solid #dceae8; }
.detail-copy h4 { margin: 0 0 6px; color: var(--teal-dark); font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; }
.detail-copy p, .detail-copy ol { margin: 0; font-size: .83rem; }
.detail-copy ol { padding-left: 20px; }
.detail-copy li + li { margin-top: 5px; }
.note-field { margin-top: 14px; }
.note-field textarea { min-height: 130px; resize: vertical; line-height: 1.5; }
.note-field small { color: var(--faint); font-size: .68rem; font-weight: 500; }

.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; max-width: min(370px, calc(100vw - 44px)); padding: 11px 15px; border-radius: 11px; background: var(--navy); color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); transition: .18s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }

.access-gate { position: fixed; z-index: 200; inset: 0; display: grid; place-items: center; padding: 20px; background-color: #eef3f8; background-image: radial-gradient(circle, #cbd8e4 1.2px, transparent 1.3px); background-size: 25px 25px; }
.access-gate[hidden] { display: none; }
.access-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255, 255, 255, .96); box-shadow: var(--shadow); }
.access-card img { width: 56px; height: 56px; object-fit: contain; }
.access-card h1 { margin: 8px 0 5px; font-size: 2rem; }
.access-card > p:not(.eyebrow):not(.access-error) { margin: 0 0 22px; color: var(--muted); }
.access-card label { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: .78rem; font-weight: 750; }
.access-card input { width: 100%; min-height: 46px; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; outline: none; background: var(--surface-soft); }
.access-card input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 143, 140, .1); }
.access-card .button { width: 100%; }
.access-card small { display: block; margin-top: 12px; color: var(--faint); font-size: .7rem; text-align: center; }
.access-error { margin: -3px 0 11px !important; color: var(--danger) !important; font-size: .78rem; }

@media (max-width: 1180px) {
  .planning-toolbar { grid-template-columns: 1fr; gap: 14px; }
  .project-heading { justify-content: space-between; }
  .map-filters { justify-content: stretch; }
  .planning-shell { grid-template-rows: auto minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .app-header { grid-template-columns: 1fr auto; }
  .view-switch { order: 3; position: absolute; left: 50%; transform: translateX(-50%); }
  .storage-status { display: none; }
  .planning-workspace { grid-template-columns: 1fr; }
  .next-panel { display: none; }
}

@media (max-width: 680px) {
  .app-header { height: 64px; padding: 0 12px; }
  .brand img { width: 36px; height: 36px; }
  .brand strong { font-size: 1rem; }
  .brand small { display: none; }
  .view-switch { position: static; order: initial; transform: none; }
  .view-switch a { min-width: auto; padding: 6px 10px; font-size: .75rem; }
  .planning-shell { height: calc(100vh - 64px); }
  .planning-toolbar { padding: 13px 12px; gap: 11px; }
  .project-heading h1 { font-size: 1.3rem; }
  .project-heading .eyebrow { display: none; }
  .overall-progress { min-width: 130px; }
  .overall-progress > span { gap: 8px; }
  .overall-progress small { display: none; }
  .map-filters { display: grid; grid-template-columns: minmax(0, 1fr) 138px; }
  .map-filters .button { display: none; }
  .map-filters select { min-width: 0; font-size: .78rem; }
  .canvas-hint { display: none; }
  .zoom-controls { right: 10px; bottom: 10px; }
  .map-drawer { inset: 0; width: 100%; }
  .drawer-header { padding: 15px 16px; }
  .drawer-body { padding: 18px 14px 40px; }
  .drawer-section { padding: 13px 10px; }
  .drawer-section-heading span, .mini-status { display: none; }
  .drawer-task-row { grid-template-columns: 30px minmax(0, 1fr); }
  .task-detail { padding: 16px 13px; }
  .task-controls { grid-template-columns: 1fr; }
  .access-card { padding: 27px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
