* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #1f2937;
  --muted: #6b7280;
  --heading: #1f2937;
  --primary: #147d73;
  --primary-strong: #0f6a61;
  --border: #d5dde8;
  --border-strong: #aab5c5;
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.05);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(1680px, calc(100vw - 32px));
  margin: 20px auto;
}

.topbar {
  padding: 0 4px 14px;
}

.topbar-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand-block {
  max-width: 560px;
}

.eyebrow,
.canvas-kicker,
.section-tag,
.sidebar-intro,
.topbar-meta,
.tool-tabs,
.canvas-summary-strip {
  display: none;
}

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.1;
  color: var(--heading);
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.tab-btn,
.tool-btn,
.component-card,
.element-actions button,
.canvas-actions button,
.sidebar button {
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text);
  transition: 0.18s ease;
}

.tab-btn:hover,
.tool-btn:hover,
.component-card:hover,
.element-actions button:hover,
.canvas-actions button:hover,
.sidebar button:hover {
  border-color: var(--primary);
}

.tab-btn.active,
.tool-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  min-height: calc(100vh - 110px);
}

.sidebar,
.canvas-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.sidebar {
  padding: 22px;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
  overscroll-behavior: contain;
}

.sidebar section {
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.sidebar section + section {
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.section-heading {
  display: block;
  margin-bottom: 14px;
}

.sidebar h2,
.canvas-section h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--heading);
}

.toolbar,
.component-list,
.element-actions,
.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tool-btn,
.element-actions button,
.sidebar button {
  padding: 12px 16px;
  font-weight: 600;
}

.tool-btn {
  min-width: 142px;
  min-height: 58px;
  font-size: 0.98rem;
}

.component-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.component-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 14px 12px;
  text-align: center;
  font-weight: 600;
  background: var(--panel-soft);
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-grid {
  align-items: end;
}

.span-two {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 500;
  color: var(--heading);
  font-size: 0.98rem;
}

input,
select {
  width: 100%;
  min-height: 58px;
  padding: 12px 16px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: 0.18s ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(20, 125, 115, 0.1);
}

.color-control input[type="color"] {
  min-height: 58px;
  padding: 6px;
}

.inline-option {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  color: var(--heading);
}

.inline-option input {
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 8px;
  box-shadow: none;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--muted);
}

.canvas-section {
  min-width: 0;
  min-height: calc(100vh - 36px);
  max-height: calc(100vh - 36px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-panel-header {
  margin-bottom: 16px;
}

.canvas-header-stack {
  display: block;
}

.canvas-header-top {
  display: block;
}

.canvas-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--heading);
  font-weight: 700;
}

.canvas-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

#canvasMeta {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 600;
}

.canvas-actions button {
  min-width: 46px;
  height: 46px;
  padding: 0 14px;
  font-weight: 700;
}

.canvas-wrapper {
  overflow: auto;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #e7edf4;
  padding: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

#drawingCanvas {
  width: 100%;
  min-width: 720px;
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}

#drawingLayer .canvas-item {
  transition: filter 0.12s ease, opacity 0.12s ease;
}

#drawingLayer g.canvas-item.selected {
  filter: drop-shadow(0 0 0.6px #0ea5e9) drop-shadow(0 0 8px rgba(14, 165, 233, 0.42));
}

#drawingLayer line.canvas-item.selected {
  stroke: #0ea5e9 !important;
  stroke-width: 5 !important;
  filter: drop-shadow(0 0 6px rgba(14, 165, 233, 0.55));
}

#selectionHandlesLayer .resize-handle {
  fill: #ffffff;
  stroke: #0ea5e9;
  stroke-width: 2;
  cursor: nwse-resize;
  vector-effect: non-scaling-stroke;
}

.hidden {
  display: none !important;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.8);
  border: 3px solid rgba(255, 255, 255, 0.9);
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1120px) {
  .app-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .canvas-section {
    min-height: auto;
    max-height: none;
    overflow: visible;
  }

  .canvas-wrapper {
    min-height: 0;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100vw - 12px, 100%);
    margin: 8px auto;
  }

  .topbar {
    display: none;
  }

  .sidebar,
  .canvas-section {
    padding: 14px;
    border-radius: 22px;
  }

  .field-grid-two,
  .component-grid {
    grid-template-columns: 1fr;
  }

  .tool-btn {
    min-width: 0;
    flex: 1 1 140px;
  }

  .canvas-info {
    flex-direction: column;
    align-items: flex-start;
  }
}
