/* City Planner — Team Tesla-inspired UI (Inter + zinc palette) */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

/* ── Theme tokens ─────────────────────────────────────────────────────────── */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --cp-font: 'Inter', ui-sans-serif, system-ui, sans-serif;
  --cp-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --cp-bg: #000000;
  --cp-bg-elevated: #13111c;
  --cp-surface: #1e1e1e;
  --cp-surface-2: #27272a;
  --cp-surface-hover: #3f3f46;
  --cp-border: #27272a;
  --cp-border-strong: #3f3f46;

  --cp-text: #fafafa;
  --cp-text-secondary: #d4d4d8;
  --cp-text-muted: #a1a1aa;

  --cp-accent: #6366f1;
  --cp-accent-hover: #818cf8;
  --cp-accent-soft: rgba(99, 102, 241, 0.12);
  --cp-accent-ring: rgba(99, 102, 241, 0.35);

  --cp-success: #22c55e;
  --cp-success-soft: rgba(34, 197, 94, 0.12);
  --cp-warning: #eab308;
  --cp-warning-soft: rgba(234, 179, 8, 0.12);
  --cp-danger: #ef4444;
  --cp-danger-soft: rgba(239, 68, 68, 0.12);

  --cp-canvas-bg: #18181b;
  --cp-grid-faint: rgba(255, 255, 255, 0.035);
  --cp-grid-line: rgba(255, 255, 255, 0.10);
  --cp-grid-block: rgba(255, 255, 255, 0.22);
  --cp-grid-unlocked: transparent;
  --cp-grid-hover-ok: rgba(34, 197, 94, 0.2);
  --cp-grid-hover-bad: rgba(239, 68, 68, 0.2);
  --cp-canvas-label: #e5e7eb;

  --cp-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --cp-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
  --cp-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.7);

  --cp-radius: 6px;
  --cp-radius-sm: 4px;
  --cp-radius-pill: 999px;

  --cp-header-h: 48px;
  --cp-layouts-w: 220px;
  --cp-sidebar-w: 260px;
  --cp-props-w: 280px;

  --cp-culture-accent: var(--cp-accent);
  --cp-culture-panel: var(--cp-bg-elevated);
  --cp-culture-header: var(--cp-accent);
}

[data-theme="light"] {
  color-scheme: light;

  --cp-bg: #fafafa;
  --cp-bg-elevated: #ffffff;
  --cp-surface: #ffffff;
  --cp-surface-2: #f4f4f5;
  --cp-surface-hover: #e4e4e7;
  --cp-border: #e4e4e7;
  --cp-border-strong: #d4d4d8;

  --cp-text: #18181b;
  --cp-text-secondary: #52525b;
  --cp-text-muted: #a1a1aa;

  --cp-accent: #4f46e5;
  --cp-accent-hover: #4338ca;
  --cp-accent-soft: rgba(79, 70, 229, 0.1);
  --cp-accent-ring: rgba(79, 70, 229, 0.25);

  --cp-success: #16a34a;
  --cp-success-soft: rgba(22, 163, 74, 0.1);
  --cp-warning: #ca8a04;
  --cp-warning-soft: rgba(202, 138, 4, 0.1);
  --cp-danger: #dc2626;
  --cp-danger-soft: rgba(220, 38, 38, 0.1);

  --cp-canvas-bg: #f6f6f7;
  --cp-grid-faint: rgba(15, 23, 42, 0.05);
  --cp-grid-line: rgba(15, 23, 42, 0.14);
  --cp-grid-block: rgba(15, 23, 42, 0.34);
  --cp-grid-unlocked: transparent;
  --cp-grid-hover-ok: rgba(22, 163, 74, 0.18);
  --cp-grid-hover-bad: rgba(220, 38, 38, 0.15);
  --cp-canvas-label: #1f2937;

  --cp-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --cp-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --cp-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
}

/* ── Scrollbars (TT-style thin) ─────────────────────────────────────────── */

.cp-sidebar,
.cp-properties,
.cp-layouts-rail,
.cp-building-list,
.cp-panel-pane,
.cp-dashboard-body,
.cp-layouts-list {
  scrollbar-width: thin;
  scrollbar-color: #3f3f46 transparent;
}
.cp-sidebar::-webkit-scrollbar,
.cp-properties::-webkit-scrollbar,
.cp-layouts-rail::-webkit-scrollbar,
.cp-building-list::-webkit-scrollbar,
.cp-panel-pane::-webkit-scrollbar,
.cp-dashboard-body::-webkit-scrollbar,
.cp-layouts-list::-webkit-scrollbar { width: 6px; height: 6px; }
.cp-sidebar::-webkit-scrollbar-thumb,
.cp-properties::-webkit-scrollbar-thumb,
.cp-layouts-rail::-webkit-scrollbar-thumb,
.cp-building-list::-webkit-scrollbar-thumb,
.cp-panel-pane::-webkit-scrollbar-thumb,
.cp-dashboard-body::-webkit-scrollbar-thumb,
.cp-layouts-list::-webkit-scrollbar-thumb {
  background: #3f3f46;
  border-radius: 3px;
}
.cp-sidebar::-webkit-scrollbar-thumb:hover,
.cp-properties::-webkit-scrollbar-thumb:hover,
.cp-layouts-rail::-webkit-scrollbar-thumb:hover,
.cp-building-list::-webkit-scrollbar-thumb:hover,
.cp-panel-pane::-webkit-scrollbar-thumb:hover,
.cp-dashboard-body::-webkit-scrollbar-thumb:hover,
.cp-layouts-list::-webkit-scrollbar-thumb:hover { background: #52525b; }
.cp-sidebar::-webkit-scrollbar-track,
.cp-properties::-webkit-scrollbar-track,
.cp-layouts-rail::-webkit-scrollbar-track,
.cp-building-list::-webkit-scrollbar-track,
.cp-panel-pane::-webkit-scrollbar-track,
.cp-dashboard-body::-webkit-scrollbar-track,
.cp-layouts-list::-webkit-scrollbar-track { background: transparent; }

/* ── Base ─────────────────────────────────────────────────────────────────── */

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

.hidden { display: none !important; }

.label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--cp-text-muted);
  margin-bottom: 8px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.cp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--cp-header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--cp-border);
  background: var(--cp-bg-elevated);
  flex-shrink: 0;
}

.cp-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cp-brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--cp-radius-sm);
  background: var(--cp-surface-2);
  border: 1px solid var(--cp-border);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex-shrink: 0;
}

.cp-brand-text h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.cp-tagline {
  font-size: 12px;
  color: var(--cp-text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cp-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.cp-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--cp-text-muted);
  padding: 4px 8px;
  border-radius: var(--cp-radius-sm);
  background: var(--cp-surface);
  border: 1px solid var(--cp-border);
}

.cp-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cp-text-muted);
}
.cp-status-dot.ok {
  background: var(--cp-success);
  box-shadow: 0 0 0 2px var(--cp-success-soft);
}
.cp-status-dot.error {
  background: var(--cp-danger, #ef4444);
}

.cp-theme-toggle {
  width: 32px;
  height: 32px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.cp-theme-toggle:hover {
  background: var(--cp-surface-hover);
  border-color: var(--cp-border-strong);
  color: var(--cp-text);
}

.btn-back {
  padding: 6px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text-muted);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-back:hover {
  background: var(--cp-surface-hover);
  color: var(--cp-text);
  border-color: var(--cp-border-strong);
}

/* ── Layout grid ──────────────────────────────────────────────────────────── */

.cp-layout {
  display: grid;
  grid-template-columns: var(--cp-layouts-w) var(--cp-sidebar-w) 1fr var(--cp-props-w);
  height: calc(100vh - var(--cp-header-h));
}

.cp-layouts-rail,
.cp-sidebar,
.cp-properties {
  background: var(--cp-bg-elevated);
  overflow-y: auto;
}

.cp-layouts-rail {
  border-right: 1px solid var(--cp-border);
  display: flex;
  flex-direction: column;
}

.cp-sidebar { border-right: 1px solid var(--cp-border); }
.cp-properties { border-left: 1px solid var(--cp-border); }

.cp-layouts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--cp-border);
  flex-shrink: 0;
}

.cp-layouts-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cp-text-muted);
}

.cp-layouts-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.cp-layout-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--cp-text-secondary);
  transition: all 0.12s;
  margin-bottom: 2px;
}
.cp-layout-item:hover {
  background: var(--cp-surface-2);
  color: var(--cp-text);
}
.cp-layout-item.active {
  background: var(--cp-surface-2);
  border-color: var(--cp-border-strong);
  color: var(--cp-text);
}
.cp-layout-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.cp-layout-item-meta {
  font-size: 10px;
  color: var(--cp-text-muted);
  white-space: nowrap;
}

.cp-section {
  padding: 12px;
  border-bottom: 1px solid var(--cp-border);
}

/* ── Controls ─────────────────────────────────────────────────────────────── */

.cp-select, .cp-input, .cp-textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text);
  font-family: var(--cp-font);
  font-size: 13px;
  transition: border-color 0.15s, outline 0.15s;
}
.cp-select:focus, .cp-input:focus, .cp-textarea:focus {
  outline: none;
  border-color: var(--cp-border-strong);
  box-shadow: 0 0 0 2px var(--cp-accent-ring);
}
.cp-textarea {
  font-family: var(--cp-mono);
  font-size: 12px;
  resize: vertical;
}

.cp-tool-row { display: flex; flex-wrap: wrap; gap: 4px; }

.cp-btn {
  padding: 6px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text-secondary);
  font-family: var(--cp-font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.cp-btn:hover {
  background: var(--cp-surface-hover);
  color: var(--cp-text);
  border-color: var(--cp-border-strong);
}
.cp-btn.active {
  border-color: var(--cp-accent);
  color: var(--cp-accent);
  background: var(--cp-accent-soft);
}
.cp-btn-primary {
  border-color: transparent;
  background: var(--cp-accent);
  color: #fff;
}
.cp-btn-primary:hover {
  background: var(--cp-accent-hover);
  color: #fff;
}
.cp-btn-danger {
  border-color: transparent;
  background: var(--cp-danger-soft);
  color: var(--cp-danger);
}
.cp-btn-danger:hover { filter: brightness(1.08); }
.cp-btn-muted { opacity: 0.65; font-size: 11px; }
.cp-btn-sm { padding: 4px 8px; font-size: 11px; }
.cp-btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-grid; place-items: center;
}

/* ── Building list ────────────────────────────────────────────────────────── */

.cp-building-list {
  margin-top: 6px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cp-building-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12px;
  color: var(--cp-text-secondary);
  transition: all 0.1s;
}
.cp-building-item:hover {
  background: var(--cp-surface-2);
  color: var(--cp-text);
}
.cp-building-item.selected {
  border-color: var(--cp-accent);
  background: var(--cp-accent-soft);
  color: var(--cp-accent);
}
.cp-building-size {
  font-family: var(--cp-mono);
  font-size: 10px;
  color: var(--cp-text-muted);
  background: var(--cp-surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}
.cp-building-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.cp-category-filters {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 4px;
}
.cp-cat-chip {
  padding: 3px 8px;
  border-radius: var(--cp-radius-pill);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text-muted);
  cursor: pointer;
  transition: all 0.1s;
}
.cp-cat-chip:hover { color: var(--cp-text-secondary); }
.cp-cat-chip.active {
  border-color: var(--cp-accent);
  color: var(--cp-accent);
  background: var(--cp-accent-soft);
}

.cp-empty {
  font-size: 12px;
  color: var(--cp-text-muted);
  padding: 10px 0;
  line-height: 1.5;
}

/* ── Main / canvas ────────────────────────────────────────────────────────── */

.cp-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cp-bg);
}

.cp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--cp-border);
  background: var(--cp-bg-elevated);
  flex-shrink: 0;
  min-height: 42px;
}
.cp-toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.cp-toolbar-meta {
  font-family: var(--cp-mono);
  font-size: 10px;
  color: var(--cp-text-muted);
  white-space: nowrap;
}
.cp-toolbar-divider {
  width: 1px; height: 20px;
  background: var(--cp-border);
  margin: 0 2px;
}

.cp-banner {
  padding: 8px 12px;
  background: var(--cp-warning-soft);
  border-bottom: 1px solid var(--cp-border);
  color: var(--cp-warning);
  font-size: 12px;
}

.cp-canvas-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--cp-bg);
}
.cp-canvas-stage {
  transform-origin: 0 0;
  will-change: transform;
  display: inline-block;
}
#grid-canvas { display: block; cursor: crosshair; }

/* ── Inventory ────────────────────────────────────────────────────────────── */

.cp-inventory {
  border-top: 1px solid var(--cp-border);
  background: var(--cp-bg-elevated);
  max-height: 140px;
  display: flex;
  flex-direction: column;
}
.cp-inventory-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--cp-border);
  font-size: 12px;
}
.cp-inventory-hint { color: var(--cp-text-muted); font-size: 11px; flex: 1; }
.cp-inventory-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px; overflow-y: auto; flex: 1;
}
.cp-inventory-item {
  padding: 5px 10px;
  border-radius: var(--cp-radius-pill);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  font-size: 11px;
  cursor: pointer;
  color: var(--cp-text-secondary);
  transition: all 0.1s;
}
.cp-inventory-item:hover { border-color: var(--cp-accent); color: var(--cp-accent); }
.cp-inventory-item.selected {
  border-color: var(--cp-accent);
  background: var(--cp-accent-soft);
  color: var(--cp-accent);
}

/* ── Right panel ──────────────────────────────────────────────────────────── */

.cp-panel-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: var(--cp-bg-elevated);
  border-bottom: 1px solid var(--cp-border);
}
.cp-panel-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.45;
  color: var(--cp-text-muted);
  transition: all 0.12s;
}
.cp-panel-tab:hover { opacity: 0.75; background: var(--cp-surface-2); }
.cp-panel-tab.active {
  opacity: 1;
  color: var(--cp-text);
  border-bottom-color: var(--cp-accent);
  background: transparent;
}

.cp-panel-pane {
  display: none;
  overflow-y: auto;
  max-height: calc(100vh - var(--cp-header-h) - 42px);
}
.cp-panel-pane.active { display: block; }

[data-culture] .cp-panel-tab.active {
  color: var(--cp-culture-accent);
  border-bottom-color: var(--cp-culture-accent);
}
[data-culture] #editor-subtitle {
  color: var(--cp-culture-accent);
  font-weight: 600;
}

.cp-stats-panel {
  font-size: 12px;
  color: var(--cp-text-secondary);
  line-height: 1.6;
}
.cp-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--cp-border);
}
.cp-stat-row:last-child { border-bottom: none; }
.cp-stat-label { color: var(--cp-text-muted); }
.cp-stat-value { font-family: var(--cp-mono); font-size: 11px; color: var(--cp-text); }

.cp-stat-note {
  margin-top: 10px;
  padding: 10px;
  border-radius: var(--cp-radius-sm);
  background: var(--cp-warning-soft);
  color: var(--cp-warning);
  font-size: 11px;
  line-height: 1.5;
}

.cp-production-table,
.cp-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.cp-production-table th,
.cp-production-table td,
.cp-compare-table th,
.cp-compare-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--cp-border);
  text-align: right;
}
.cp-production-table th:first-child,
.cp-production-table td:first-child,
.cp-compare-table th:first-child,
.cp-compare-table td:first-child { text-align: left; }
.cp-compare-table th {
  background: var(--cp-surface-2);
  color: var(--cp-text-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.cp-compare-best {
  background: var(--cp-success-soft);
  color: var(--cp-success);
  font-weight: 600;
}

.cp-snapshot-list { display: flex; flex-direction: column; gap: 4px; }
.cp-snapshot-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  font-size: 12px;
  color: var(--cp-text-secondary);
}
.cp-snapshot-item button {
  margin-left: auto;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 500;
  border: 1px solid var(--cp-border);
  background: var(--cp-surface-2);
  color: var(--cp-text-secondary);
  border-radius: var(--cp-radius-sm);
  cursor: pointer;
  font-family: var(--cp-font);
}
.cp-snapshot-item button:hover {
  border-color: var(--cp-accent);
  color: var(--cp-accent);
}

.cp-label-hint { font-weight: 400; color: var(--cp-text-muted); font-size: 10px; }
.cp-compare-body { font-size: 12px; overflow-x: auto; }

.cp-shortcuts { display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: var(--cp-text-muted); }
.cp-shortcuts kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--cp-border);
  background: var(--cp-surface-2);
  font-family: var(--cp-mono);
  font-size: 10px;
  color: var(--cp-text-secondary);
  margin-right: 4px;
}

.cp-selected-panel.hidden { display: none; }
.cp-selected-info { font-size: 12px; color: var(--cp-text-secondary); margin-bottom: 8px; line-height: 1.5; }

/* ── Dashboard (TT-style landing) ─────────────────────────────────────────── */

.cp-dashboard {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cp-bg);
}

.cp-dashboard-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  min-height: 0;
}

.cp-dashboard-center {
  width: 100%;
  max-width: 480px;
}

.cp-dashboard-hero {
  text-align: center;
  margin-bottom: 32px;
}
.cp-dashboard-hero h2 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}
.cp-dashboard-hero p {
  color: var(--cp-text-muted);
  font-size: 14px;
}

.cp-layouts-card {
  background: var(--cp-bg-elevated);
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  overflow: hidden;
  box-shadow: var(--cp-shadow-md);
}

.cp-layouts-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--cp-border);
}
.cp-layouts-card-header h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cp-text-muted);
}

.cp-layouts-card-body {
  padding: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.cp-layouts-card-empty {
  padding: 32px 24px;
  text-align: center;
}
.cp-layouts-card-empty p {
  color: var(--cp-text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.cp-dashboard-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--cp-border);
}

.cp-profile-grid { display: contents; }

.cp-profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
}
.cp-profile-card:hover {
  background: var(--cp-surface-2);
}
.cp-profile-card h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cp-profile-card-meta {
  font-size: 11px;
  color: var(--cp-text-muted);
  white-space: nowrap;
}
.cp-profile-card-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.12s;
}
.cp-profile-card:hover .cp-profile-card-actions { opacity: 1; }

/* ── Modals ─────────────────────────────────────────────────────────────────── */

.cp-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.cp-modal.hidden { display: none; }
.cp-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
[data-theme="light"] .cp-modal-backdrop { background: rgba(0, 0, 0, 0.4); }

.cp-modal-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--cp-bg-elevated);
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  padding: 20px;
  box-shadow: var(--cp-shadow-lg);
}
.cp-modal-wide { width: min(680px, 100%); }
.cp-modal-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}
.cp-modal-hint {
  font-size: 12px;
  color: var(--cp-text-muted);
  margin-bottom: 14px;
  line-height: 1.55;
}
.cp-modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.cp-error { margin-top: 10px; font-size: 12px; color: var(--cp-danger); }
.cp-error.hidden { display: none; }

.cp-import-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.cp-tab {
  padding: 6px 12px;
  border-radius: var(--cp-radius-pill);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
}
.cp-tab.active {
  border-color: var(--cp-accent);
  color: var(--cp-accent);
  background: var(--cp-accent-soft);
}

.cp-city-picker {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.cp-city-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  cursor: pointer;
  font-size: 13px;
  background: var(--cp-surface);
  transition: all 0.1s;
}
.cp-city-option:hover { border-color: var(--cp-border-strong); }
.cp-city-option.selected {
  border-color: var(--cp-accent);
  background: var(--cp-accent-soft);
}
.cp-city-option-meta {
  margin-left: auto;
  font-family: var(--cp-mono);
  font-size: 10px;
  color: var(--cp-text-muted);
}

.cp-share-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--cp-radius-sm);
  background: var(--cp-success-soft);
  border: 1px solid var(--cp-border);
  font-size: 12px;
  word-break: break-all;
  color: var(--cp-success);
}
.cp-share-result.hidden { display: none; }
.cp-share-result a { color: var(--cp-accent); }

/* ── Toast ────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 14px;
  border-radius: var(--cp-radius-sm);
  background: var(--cp-surface-2);
  border: 1px solid var(--cp-border);
  box-shadow: var(--cp-shadow-md);
  font-size: 12px;
  font-weight: 500;
  color: var(--cp-text);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 200;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: none; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 1200px) {
  .cp-layout {
    grid-template-columns: var(--cp-layouts-w) var(--cp-sidebar-w) 1fr;
  }
  .cp-properties { display: none; }
}

@media (max-width: 900px) {
  .cp-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }
  .cp-layouts-rail {
    max-height: 120px;
    border-right: none;
    border-bottom: 1px solid var(--cp-border);
  }
  .cp-layout-item { flex-shrink: 0; }
  .cp-sidebar {
    max-height: 38vh;
    border-right: none;
    border-bottom: 1px solid var(--cp-border);
  }
  .cp-dashboard-body { padding: 20px 16px; }
  .btn-back, .cp-tagline { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Team Tesla floating shell — full-bleed canvas + floating panels + dock
   (supersedes the docked .cp-layout / .cp-header / .cp-dashboard grid above)
   ═══════════════════════════════════════════════════════════════════════════ */

body { background: var(--cp-bg); }

.cp-canvas-wrap {
  position: fixed;
  inset: 0;
  flex: none;
  overflow: hidden;
  background: var(--cp-bg);
  z-index: 0;
}
#grid-canvas { cursor: default; }

.cp-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  box-shadow: var(--cp-shadow-md);
  text-align: center;
}

/* ── Floating panels ──────────────────────────────────────────────────────── */

.cp-float {
  position: fixed;
  z-index: 20;
  background: var(--cp-surface);
  border: 1px solid var(--cp-border);
  border-radius: 12px;
  box-shadow: var(--cp-shadow-md);
}

.cp-layouts-panel {
  top: 16px;
  left: 16px;
  width: 234px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cp-info-panel {
  top: 16px;
  right: 16px;
  width: 304px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cp-float-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 10px 14px;
  border-bottom: 1px solid var(--cp-border);
  flex-shrink: 0;
}
.cp-float-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cp-text-muted);
  flex: 1;
}
.cp-float-head-actions { display: flex; align-items: center; gap: 2px; }

.cp-icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--cp-text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
}
.cp-icon-btn:hover { background: var(--cp-surface-2); color: var(--cp-text); }
.cp-icon-btn.active { background: var(--cp-accent-soft); color: var(--cp-accent); }

.cp-layouts-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  min-height: 44px;
}
.cp-layouts-list:empty::after {
  content: "No layouts yet — press + to start";
  display: block;
  padding: 14px 10px;
  font-size: 12px;
  color: var(--cp-text-muted);
}
.cp-layout-item { position: relative; }
.cp-layout-item-del {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s;
}
.cp-layout-item:hover .cp-layout-item-del,
.cp-layout-item.active .cp-layout-item-del { opacity: 0.7; }
.cp-layout-item-del:hover { opacity: 1; color: var(--cp-danger); background: var(--cp-danger-soft); }

/* ── City filter popover ──────────────────────────────────────────────────── */

.cp-popover {
  z-index: 45;
  min-width: 168px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 5px;
  border-radius: 10px;
  background: #1f1f22;
  border: 1px solid #35353a;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
/* Fixed (not absolute) so the Layouts panel's overflow:hidden can't clip it. */
.cp-city-filter-menu {
  position: fixed;
  top: 54px;
  left: 22px;
}
.cp-popover-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #e6e6e9;
  font-family: var(--cp-font);
  font-size: 13px;
  cursor: pointer;
}
.cp-popover-item:hover { background: #33333a; }
.cp-popover-item.active { color: #a5b4fc; }

/* ── Info panel ───────────────────────────────────────────────────────────── */

.cp-info-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--cp-border);
  flex-shrink: 0;
}
.cp-city-select {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--cp-text);
  font-family: var(--cp-font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 4px 2px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.cp-city-select:focus { outline: none; }
.cp-city-select option { color: #18181b; background: #fff; font-weight: 500; }

.cp-info-head .cp-status {
  border: none;
  background: transparent;
  padding: 2px 2px;
  font-size: 10px;
  max-width: 70px;
  overflow: hidden;
  white-space: nowrap;
  flex-shrink: 0;
}
.cp-info-head .cp-status #status-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.cp-info-body { overflow-y: auto; flex: 1; }

.cp-acc { border-bottom: 1px solid var(--cp-border); }
.cp-acc:last-child { border-bottom: none; }
.cp-acc > summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--cp-text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.cp-acc > summary::-webkit-details-marker { display: none; }
.cp-acc > summary:hover { color: var(--cp-text); }
.cp-acc-chevron {
  width: 8px; height: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  opacity: 0.6;
}
.cp-acc[open] > summary .cp-acc-chevron { transform: rotate(45deg); }
.cp-acc-body { padding: 0 14px 14px; }
.cp-acc-sub-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cp-text-muted);
  margin: 14px 0 6px;
}
.cp-sub-section { border-top: 1px solid var(--cp-border); margin-top: 12px; padding-top: 4px; }

/* Enriched-stats sub-blocks (production cost, wonder goods, building area) */
.cp-stat-sub { margin-top: 12px; }
.cp-stat-sub:empty, .cp-stat-sub.hidden { display: none; }
.cp-stat-sub-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cp-text-muted);
  margin-bottom: 5px;
}
.cp-stat-goods {
  font-family: var(--cp-mono);
  font-size: 11px;
  color: var(--cp-text);
}

.cp-meta-line {
  margin-top: 8px;
  font-family: var(--cp-mono);
  font-size: 10px;
  color: var(--cp-text-muted);
}

/* ── Bottom dock ──────────────────────────────────────────────────────────── */

.cp-dock {
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border-radius: 14px;
}
.cp-dock-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--cp-text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.cp-dock-btn:hover { background: var(--cp-surface-2); color: var(--cp-text); }
.cp-dock-btn.active { background: var(--cp-accent); color: #fff; }

/* ── Guide timeline rail ─────────────────────────────────────────────────── */

.cp-guide-rail {
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  max-height: 200px;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  z-index: 30;
}
.cp-guide-rail-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--cp-border);
  flex-shrink: 0;
}
.cp-guide-counter {
  font-family: var(--cp-mono);
  font-size: 11px;
  color: var(--cp-text-muted);
  min-width: 44px;
  text-align: center;
}
.cp-guide-rail-sep { flex: 1; }
.cp-guide-steps {
  display: flex;
  gap: 6px;
  padding: 8px;
  overflow-x: auto;
  overflow-y: hidden;
}
.cp-guide-step {
  flex-shrink: 0;
  min-width: 116px;
  max-width: 160px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--cp-border);
  background: var(--cp-surface-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--cp-text-secondary);
  transition: border-color 0.12s, background 0.12s;
}
.cp-guide-step:hover { border-color: var(--cp-border-strong); color: var(--cp-text); }
.cp-guide-step.active {
  border-color: var(--cp-accent);
  background: var(--cp-accent-soft);
  color: var(--cp-accent);
}
.cp-guide-step-top {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}
.cp-guide-step-idx { font-family: var(--cp-mono); font-size: 10px; opacity: 0.7; }
.cp-guide-step-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cp-guide-step-kind {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cp-text-muted);
  margin-top: 2px;
}
.cp-guide-step.kind-checkpoint { border-left: 3px solid var(--cp-accent); }
.cp-guide-step.kind-overview   { border-left: 3px solid var(--cp-text-muted); }
.cp-guide-step.kind-research   { border-left: 3px solid var(--cp-warning); }
.cp-guide-step.kind-layout     { border-left: 3px solid var(--cp-success); }
.cp-guide-step-tools {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}
.cp-guide-step-tools button {
  flex: 1;
  padding: 2px 0;
  font-size: 11px;
  line-height: 1;
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text-muted);
  border-radius: 4px;
  cursor: pointer;
}
.cp-guide-step-tools button:hover { color: var(--cp-text); border-color: var(--cp-border-strong); }

/* Guide-step meta editor (in the info panel) */
#guide-step-meta .cp-input,
#guide-step-meta .cp-select,
#guide-step-meta textarea { margin-bottom: 8px; }
#guide-step-meta textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px 10px;
  border-radius: var(--cp-radius-sm);
  border: 1px solid var(--cp-border);
  background: var(--cp-surface);
  color: var(--cp-text);
  font-family: var(--cp-font);
  font-size: 13px;
  resize: vertical;
}
.cp-guide-view-note {
  font-size: 13px;
  color: var(--cp-text-secondary);
  line-height: 1.55;
  white-space: pre-wrap;
}
.cp-guide-kind-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--cp-radius-pill);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--cp-surface-2);
  color: var(--cp-text-muted);
  margin-bottom: 8px;
}

/* Guide mode chrome toggles */
body.cp-guide-edit .cp-guide-rail,
body.cp-guide-view .cp-guide-rail { display: flex; }
body:not(.cp-guide-edit) .cp-guide-edit-only { display: none; }
body.cp-guide-edit #btn-guide,
body.cp-guide-view #btn-guide { background: var(--cp-accent); color: #fff; }
body.cp-guide-view #btn-building-menu,
body.cp-guide-view .cp-dock-btn[data-mode="grid"],
body.cp-guide-view #sec-selected,
body.cp-guide-view #building-menu { display: none !important; }

/* ── Building dropdown (always dark, TT-style) ────────────────────────────── */

.cp-building-menu {
  position: fixed;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: 276px;
  max-height: min(52vh, 460px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: #1c1c1f;
  border: 1px solid #34343a;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}
.cp-building-search {
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid #3a3a42;
  background: #101013;
  color: #f2f2f5;
  font-family: var(--cp-font);
  font-size: 13px;
}
.cp-building-search:focus { outline: none; border-color: #6366f1; }
.cp-building-menu .cp-category-filters { margin: 0; max-height: 66px; overflow-y: auto; }
.cp-building-menu .cp-cat-chip {
  background: #26262b;
  border-color: #3a3a42;
  color: #b8b8c0;
}
.cp-building-menu .cp-cat-chip.active {
  background: rgba(99, 102, 241, 0.22);
  border-color: #6366f1;
  color: #c7d2fe;
}
.cp-building-menu .cp-building-list {
  margin: 0;
  max-height: none;
  flex: 1;
  overflow-y: auto;
}
.cp-building-menu .cp-building-item { color: #d8d8de; }
.cp-building-menu .cp-building-item:hover { background: #2c2c33; color: #fff; }
.cp-building-menu .cp-building-item.selected {
  background: rgba(99, 102, 241, 0.22);
  color: #c7d2fe;
}
.cp-building-menu .cp-building-size { background: #101013; color: #8a8a93; }
.cp-building-menu .cp-empty { color: #8a8a93; padding-left: 10px; }

/* ── Shelf / inventory (floating) ─────────────────────────────────────────── */

.cp-inventory {
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  max-height: 180px;
  border-radius: 12px;
  overflow: hidden;
  z-index: 30;
}

/* ── Modal head + help ────────────────────────────────────────────────────── */

.cp-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.cp-modal-head .cp-modal-title { margin-bottom: 0; }

.cp-help-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.cp-help-pane p { font-size: 13px; color: var(--cp-text-secondary); line-height: 1.6; }
.cp-help-group {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cp-text-muted);
  margin: 16px 0 8px;
}
.cp-help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
.cp-help-key {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--cp-radius-sm);
  background: var(--cp-surface-2);
  font-size: 12px;
  color: var(--cp-text-secondary);
}
.cp-help-key span { flex: 1; }
.cp-help-key kbd,
.cp-modal-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--cp-border-strong);
  background: var(--cp-surface);
  font-family: var(--cp-mono);
  font-size: 10px;
  color: var(--cp-text);
}

/* ── Responsive: stack panels on small screens ───────────────────────────── */

@media (max-width: 820px) {
  .cp-layouts-panel { width: 200px; max-height: 40vh; }
  .cp-info-panel {
    top: auto;
    bottom: 74px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 44vh;
  }
  .cp-inventory { bottom: 128px; }
  .cp-building-menu { bottom: 128px; }
}
