*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --text: #111827;
  --text-muted: #6B7280;
  --text-faint: #9CA3AF;
  --primary: #4F8EF7;
  --primary-dark: #2563EB;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* ── Layout ── */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Header ── */
.header {
  flex: 0 0 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 100;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -.3px; }
.header-actions { display: flex; gap: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-family: var(--font); font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent;
  transition: all .15s ease; white-space: nowrap; line-height: 1;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); border-color: #D1D5DB; }
.btn-toggle { color: var(--text-faint); }
.btn-toggle.active { color: #B45309; border-color: #FDE68A; background: #FFFBEB; }
.btn-toggle.active:hover { background: #FEF3C7; border-color: #FCD34D; color: #92400E; }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }

/* ── Main ── */
.main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ── Empty state ── */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; padding: 48px; color: var(--text-muted);
}
.empty-icon { opacity: .8; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-desc { font-size: 13px; color: var(--text-muted); text-align: center; max-width: 300px; }

/* ── Gantt wrapper ── */
.gantt-wrapper {
  flex: 1; display: flex;
  overflow: hidden;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* ── Sidebar ── */
.gantt-sidebar {
  flex: 0 0 220px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}
.sidebar-header {
  flex: 0 0 56px;
  display: flex; align-items: flex-end;
  padding: 0 16px 10px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.task-list {
  flex: 1;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-width: none;
}
.task-list::-webkit-scrollbar { display: none; }

.task-row {
  display: flex; align-items: center;
  height: 52px; padding: 0 8px 0 16px; gap: 8px;
  border-bottom: 1px solid var(--border-light);
  transition: background .1s;
}
.task-row:hover { background: var(--bg); }
.task-dot { flex: 0 0 10px; height: 10px; border-radius: 50%; }
.task-name {
  flex: 1; font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.task-row:hover .task-actions { opacity: 1; }
.icon-btn {
  background: none; border: none; cursor: pointer;
  padding: 4px; border-radius: 5px;
  color: var(--text-faint);
  display: flex; align-items: center;
  transition: all .1s;
}
.icon-btn:hover { background: var(--border-light); color: var(--text-muted); }
.icon-btn.del:hover { background: #FEF2F2; color: #B91C1C; }

/* ── Chart area ── */
.gantt-chart-area {
  flex: 1;
  overflow-x: auto;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: #D1D5DB transparent;
}
.gantt-chart-area::-webkit-scrollbar { width: 6px; height: 6px; }
.gantt-chart-area::-webkit-scrollbar-track { background: transparent; }
.gantt-chart-area::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
.svg-container { display: block; line-height: 0; }
.svg-container.dragging, .svg-container.dragging * { cursor: col-resize !important; }
.drag-handle { cursor: col-resize; }
.drag-handle:hover { fill: rgba(255,255,255,0.35) !important; }

/* ── Drag tooltip ── */
.drag-tooltip {
  position: fixed; transform: translateX(-50%);
  background: #1F2937; color: #fff;
  padding: 5px 12px; border-radius: 6px;
  font-family: var(--font); font-size: 12px; font-weight: 500;
  white-space: nowrap; pointer-events: none; z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  display: none;
}

/* ── Form panel ── */
.form-panel {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  box-shadow: 0 -2px 10px rgba(0,0,0,.04);
}
.form-inner { display: flex; align-items: flex-end; gap: 12px; }
.form-fields { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; align-items: flex-end; }
.form-actions { display: flex; gap: 8px; align-items: flex-end; flex: 0 0 auto; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-name { flex: 2; min-width: 140px; }
.field-month { flex: 1.2; min-width: 120px; }
.field-year { flex: 0 0 80px; }
.field-dur { flex: 0 0 110px; }
.field-color { flex: 0 0 auto; }

.field-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.field-input {
  height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font); font-size: 13px; color: var(--text);
  background: var(--surface); outline: none; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,142,247,.12); }
.field-select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 28px;
}

/* ── Color picker ── */
.color-picker { display: flex; gap: 5px; height: 36px; align-items: center; }
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  cursor: pointer; border: 2.5px solid transparent;
  transition: transform .15s, box-shadow .15s;
}
.color-swatch:hover { transform: scale(1.18); }
.color-swatch.selected { border-color: white; box-shadow: 0 0 0 2.5px var(--sw); }

.form-msg { margin-top: 8px; font-size: 12px; color: #EF4444; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 84px; left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: #1F2937; color: #fff;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; z-index: 999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.modal-overlay.open {
  opacity: 1; visibility: visible;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
  width: 400px; max-width: calc(100vw - 32px);
  transform: translateY(8px) scale(.98);
  transition: transform .2s;
}
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border-light);
}
.modal-title {
  font-size: 15px; font-weight: 600; color: var(--text);
}
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--text-faint);
  padding: 2px 6px; border-radius: 6px;
  line-height: 1; transition: all .1s;
}
.modal-close:hover { background: var(--bg); color: var(--text-muted); }
.modal-body {
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-row {
  display: flex; gap: 10px;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border-light);
}

/* ── Checkpoint pill (shown on hover in chart) ── */
.cp-delete-btn {
  position: absolute;
  transform: translateX(-50%);
  background: #1F2937; color: #fff;
  border: none; cursor: pointer;
  padding: 3px 10px; border-radius: 5px;
  font-family: var(--font); font-size: 11px; font-weight: 500;
  white-space: nowrap; z-index: 50;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.cp-delete-btn:hover { background: #B91C1C; }
.cp-delete-btn.visible { opacity: 1; pointer-events: auto; }

/* ── Checkpoint placement mode ── */
.cp-placing .svg-container { cursor: crosshair !important; }
.cp-placing .svg-container * { cursor: crosshair !important; }
.cp-placing-banner {
  position: fixed; top: 68px; left: 50%;
  transform: translateX(-50%);
  background: #1F2937; color: #fff;
  padding: 8px 20px; border-radius: 8px;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  z-index: 200; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: bannerIn .2s ease;
}
.cp-placing-banner kbd {
  background: rgba(255,255,255,.15); padding: 2px 6px;
  border-radius: 4px; font-size: 11px; font-family: var(--font);
}
@keyframes bannerIn { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Checkpoint preview (SVG overlay) ── */
.cp-preview-svg {
  position: absolute; top: 0; left: 0;
  pointer-events: none; z-index: 50;
  opacity: 0; transition: opacity .1s;
}
.cp-placing .cp-preview-svg { opacity: .6; }

/* ── Checkpoint context menu ── */
.cp-context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.06);
  padding: 4px;
  z-index: 1001;
  min-width: 140px;
  font-family: var(--font);
  animation: menuIn .12s ease;
}
@keyframes menuIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.cp-context-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 12px;
  border: none; background: none; cursor: pointer;
  font-family: var(--font); font-size: 13px; color: var(--text);
  border-radius: 5px; transition: background .1s;
}
.cp-context-menu button:hover { background: var(--bg); }
.cp-context-menu button.danger { color: #B91C1C; }
.cp-context-menu button.danger:hover { background: #FEF2F2; }
