:root {
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-weekend: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --success: #10b981;
  --warning: #f59e0b;
  --today: #ef4444;
  --today-soft: rgba(239, 68, 68, 0.08);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 18px 44px rgba(15, 23, 42, 0.18);
  --radius: 8px;
  --radius-sm: 6px;
  --header-h: 52px;
  --sidebar-w: 280px;
  --row-h: 40px;
  --group-h: 32px;
  --cal-h: 54px;
}

[data-theme="dark"] {
  --bg: #141416;
  --bg-subtle: #1b1c20;
  --bg-elevated: #1f2026;
  --bg-hover: #282a32;
  --bg-weekend: #18191e;
  --border: #2c2e38;
  --border-strong: #3d404f;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --today: #f87171;
  --today-soft: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.6);
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.boot-loader {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Buttons & Inputs */
button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 500;
  font-size: 12.5px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(0.5px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: var(--danger-soft);
}

.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-icon {
  width: 30px;
  padding: 0;
}

.btn-sm {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

/* Landing Page */
.landing {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  background:
    radial-gradient(circle at 15% 15%, var(--accent-soft), transparent 45%),
    var(--bg-subtle);
}

.landing-wrap {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.landing-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  color: var(--text-muted);
  font-size: 12.5px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

.card-desc {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.landing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 680px) {
  .landing-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  padding: 0;
  accent-color: var(--accent);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}

.recent-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.recent-info {
  min-width: 0;
  flex: 1;
}

.recent-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-meta {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Board Header */
.topbar {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 20;
}

.embed-mode .topbar {
  height: 44px;
  min-height: 44px;
  padding: 0 8px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.topbar-left {
  flex: 1;
}

.board-title-btn {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.board-title-btn:hover {
  background: var(--bg-hover);
}

.board-title-input {
  font-size: 14px;
  font-weight: 700;
  padding: 3px 8px;
  height: 28px;
  width: 210px;
}

.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.role-badge.view-only {
  background: var(--bg-hover);
  color: var(--text-muted);
}

.segmented {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.segmented button {
  height: 24px;
  padding: 0 9px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.segmented button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.search-input {
  height: 30px;
  width: 145px;
  font-size: 12px;
  padding: 0 9px;
}

.filter-select {
  height: 30px;
  font-size: 12px;
  padding: 0 7px;
}

@media (max-width: 860px) {
  .search-input {
    width: 100px;
  }
  .hide-narrow {
    display: none !important;
  }
}

/* Workspace Split */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.18s ease, min-width 0.18s ease;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  height: var(--cal-h);
  min-height: var(--cal-h);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.sidebar-body::-webkit-scrollbar {
  display: none;
}

.group-row {
  height: var(--group-h);
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.group-row:hover {
  background: var(--bg-hover);
}

.group-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.group-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-count {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-muted);
}

.task-row {
  height: var(--row-h);
  padding: 0 8px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.task-row:hover {
  background: var(--bg-hover);
}

.task-row.selected {
  background: var(--accent-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-todo { background: #94a3b8; }
.status-in_progress { background: #3b82f6; }
.status-done { background: #10b981; }
.status-blocked { background: #ef4444; }

.task-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.task-row-title {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-row-sub {
  font-size: 10.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.task-row-actions {
  display: none;
  align-items: center;
  gap: 2px;
}

.task-row:hover .task-row-actions {
  display: flex;
}

.mini-btn {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 11px;
}

.mini-btn:hover {
  background: var(--border);
  color: var(--text);
}

/* Timeline Canvas */
.timeline-pane {
  flex: 1;
  min-width: 0;
  overflow: auto;
  position: relative;
  background: var(--bg);
}

.timeline-inner {
  position: relative;
  min-height: 100%;
}

.cal-header {
  position: sticky;
  top: 0;
  height: var(--cal-h);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  z-index: 15;
  user-select: none;
}

.cal-months {
  position: relative;
  height: 26px;
  border-bottom: 1px solid var(--border);
}

.cal-month-cell {
  position: absolute;
  top: 0;
  height: 26px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
}

.cal-ticks {
  position: relative;
  height: 28px;
}

.cal-tick-cell {
  position: absolute;
  top: 0;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}

.cal-tick-cell.weekend {
  background: var(--bg-weekend);
  color: var(--text-faint);
}

.cal-tick-cell.is-today {
  background: var(--today-soft);
  color: var(--today);
  font-weight: 700;
}

/* Grid Body */
.grid-body {
  position: relative;
}

.grid-bg-cols {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grid-col {
  position: absolute;
  top: 0;
  bottom: 0;
  border-right: 1px solid var(--border);
  opacity: 0.65;
}

.grid-col.weekend {
  background: var(--bg-weekend);
  opacity: 1;
}

.today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--today);
  z-index: 8;
  pointer-events: none;
}

.today-line::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--today);
}

.grid-row-bg {
  position: absolute;
  left: 0;
  right: 0;
  border-bottom: 1px solid var(--border);
}

.grid-row-bg.is-group {
  background: var(--bg-subtle);
  opacity: 0.7;
}

/* Dependency SVG Layer */
.deps-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.dep-path {
  fill: none;
  stroke: var(--text-faint);
  stroke-width: 1.75;
  opacity: 0.85;
}

.dep-path.conflict {
  stroke: var(--danger);
  stroke-dasharray: 4 3;
}

/* Task Bars */
.task-bar {
  position: absolute;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 600;
  user-select: none;
  touch-action: none;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.16);
  transition: box-shadow 0.12s, filter 0.12s;
  cursor: grab;
  overflow: visible;
}

.task-bar.readonly {
  cursor: pointer;
}

.task-bar:hover {
  filter: brightness(1.04);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.22);
  z-index: 12;
}

.task-bar.dragging {
  cursor: grabbing;
  opacity: 0.92;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28);
  z-index: 25;
}

.task-bar-bg {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  pointer-events: none;
}

.task-bar-progress {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

.task-bar-content {
  position: relative;
  z-index: 2;
  padding: 0 10px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  overflow: hidden;
  pointer-events: none;
}

.task-bar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.task-bar-pct {
  font-size: 10px;
  opacity: 0.9;
  flex-shrink: 0;
}

.task-bar-outside-label {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 4;
}

.resize-handle.left {
  left: -2px;
  border-radius: 6px 0 0 6px;
}

.resize-handle.right {
  right: -2px;
  border-radius: 0 6px 6px 0;
}

.resize-handle::after {
  content: '';
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 3px;
  width: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0);
  transition: background 0.12s;
}

.task-bar:hover .resize-handle::after {
  background: rgba(255, 255, 255, 0.75);
}

.progress-handle {
  position: absolute;
  bottom: -4px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--text);
  cursor: ew-resize;
  opacity: 0;
  z-index: 5;
  transition: opacity 0.12s, transform 0.12s;
}

.task-bar:hover .progress-handle,
.task-bar.dragging .progress-handle {
  opacity: 1;
}

.progress-handle:hover {
  transform: scale(1.2);
}

/* Milestone */
.milestone-bar {
  position: absolute;
  width: 20px;
  height: 20px;
  z-index: 10;
  cursor: grab;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.milestone-bar.readonly {
  cursor: pointer;
}

.milestone-diamond {
  width: 15px;
  height: 15px;
  transform: rotate(45deg);
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
  border: 2px solid #ffffff;
}

.milestone-label {
  position: absolute;
  left: 26px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  pointer-events: none;
}

/* Empty State */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal {
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - 32px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 14.5px;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid transparent;
  transition: transform 0.12s;
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg-elevated) inset;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-row input[type="range"] {
  flex: 1;
  padding: 0;
  border: none;
  box-shadow: none;
  accent-color: var(--accent);
}

.copy-box {
  display: flex;
  gap: 6px;
}

.copy-box input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
}

.code-preview {
  width: 100%;
  min-height: 150px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  resize: vertical;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.tab-btn {
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Drag Tooltip & Toasts */
.drag-tooltip {
  position: fixed;
  padding: 5px 9px;
  border-radius: 6px;
  background: #0f172a;
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 600;
  pointer-events: none;
  z-index: 200;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.toast-root {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  padding: 9px 13px;
  border-radius: 8px;
  background: #0f172a;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: fadeIn 0.16s ease;
}

.toast.error {
  background: #dc2626;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Footer Stats */
.statusbar {
  height: 28px;
  min-height: 28px;
  padding: 0 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.statusbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
