:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #6b7785;
  --border: #d8dee7;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, select, textarea {
  font: inherit;
}

button, .buttonish {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 0.55rem;
  cursor: pointer;
  user-select: none;
  line-height: 1;
}

button:hover, .buttonish:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.danger {
  border-color: #fecaca;
  color: var(--danger);
}

button.active, .tool-btn.active {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
}

input, select, textarea {
  width: 100%;
  margin-top: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: #fff;
  color: var(--text);
}

input[type="checkbox"] {
  width: auto;
  margin: 0;
}

label {
  display: block;
  font-size: 0.9rem;
  color: #334155;
  margin-bottom: 0.85rem;
}

h1, h2, h3 {
  margin-top: 0;
}

h1 { font-size: 1.35rem; }
h2 { font-size: 1rem; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }

summary { cursor: pointer; color: var(--primary-dark); font-weight: 600; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-note { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.row { display: flex; align-items: center; }
.gap { gap: 0.5rem; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; }
.compact label { margin-bottom: 0.55rem; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: #0f172a;
  color: #fff;
  border-bottom: 1px solid #020617;
}

.topbar button, .topbar .buttonish {
  background: #1e293b;
  color: #fff;
  border-color: #334155;
}

.topbar button:hover, .topbar .buttonish:hover {
  background: #334155;
}

.topbar button.primary {
  background: #2563eb;
  border-color: #2563eb;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.45rem;
  margin-left: 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #334155;
  color: #dbeafe;
}

.app-shell {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: 310px minmax(480px, 1fr) 380px;
  overflow: hidden;
}

.sidebar {
  overflow: auto;
  padding: 0.75rem;
  background: #edf2f7;
  border-right: 1px solid var(--border);
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.asset-palette {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.asset-chip {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem;
}

.asset-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: #e2e8f0;
  color: #0f172a;
  font-weight: 800;
  font-size: 0.75rem;
}

.asset-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.canvas-toolbar {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 0.8rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  overflow: hidden;
  background:
    linear-gradient(45deg, #f8fafc 25%, transparent 25%),
    linear-gradient(-45deg, #f8fafc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f8fafc 75%),
    linear-gradient(-45deg, transparent 75%, #f8fafc 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

#planCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.empty-hint h2 {
  color: #334155;
  font-size: 1.35rem;
}

.selection-panel dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.35rem 0.5rem;
  margin: 0.6rem 0;
}

.selection-panel dt { color: var(--muted); }
.selection-panel dd { margin: 0; color: var(--text); }

.inline-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.35rem 0;
}


.estimate-panel {
  overflow-x: auto;
}

.estimate-panel .estimate-table {
  min-width: 760px;
}

.estimate-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.estimate-table th,
.estimate-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.25rem;
  text-align: right;
  vertical-align: top;
}

.estimate-table th:first-child,
.estimate-table td:first-child {
  text-align: left;
}

.total-card {
  margin-top: 0.75rem;
  padding: 0.7rem;
  border-radius: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.total-line {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.total-line.final {
  font-size: 1.1rem;
  font-weight: 800;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.project-list button {
  width: 100%;
  text-align: left;
  margin-bottom: 0.45rem;
}

.project-list .project-item-title { font-weight: 700; }
.project-list .project-item-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.72);
  padding: 1rem;
}

.modal {
  width: min(460px, 100%);
  background: #fff;
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: min(720px, calc(100vw - 2rem));
  text-align: center;
}

@media (max-width: 1150px) {
  .app-shell {
    grid-template-columns: 280px minmax(380px, 1fr);
  }

  .sidebar.right {
    position: fixed;
    right: 0;
    top: 58px;
    bottom: 0;
    width: min(380px, 94vw);
    z-index: 20;
    box-shadow: var(--shadow);
  }
}

@media print {
  .topbar, .sidebar.left, .workspace, .panel:not(.estimate-panel) { display: none !important; }
  .app-shell { display: block; height: auto; }
  .sidebar.right { position: static; width: auto; border: 0; background: #fff; overflow: visible; }
  .panel { box-shadow: none; border: 0; }
}

.pricing-editor {
  margin: 0.65rem 0;
  overflow-x: auto;
}

.pricing-editor input {
  min-width: 64px;
  padding: 0.35rem;
  margin: 0;
  font-size: 0.8rem;
}

.section-subhead {
  margin: 0.8rem 0 0.35rem;
  color: #334155;
}

.bom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin: 0.55rem 0 0.8rem;
}

.bom-grid label {
  margin-bottom: 0;
  font-size: 0.78rem;
}

.bom-grid input {
  padding: 0.35rem;
  margin-top: 0.25rem;
}

.material-table input {
  min-width: 60px;
}

.estimate-panel {
  overflow-x: auto;
}

/* ── Canvas nav controls ── */

.canvas-nav {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

.nav-row {
  display: flex;
  align-items: center;
}

.nav-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--border);
  color: #334155;
  cursor: pointer;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  transition: all 0.12s;
}

.nav-btn:hover {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
}

.nav-btn:active {
  background: #bfdbfe;
  transform: scale(0.93);
}

.nav-center { font-size: 1.05rem; }

.nav-zoom {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}

.nav-zoom .nav-btn {
  width: 36px;
  font-size: 1.1rem;
}
