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

:root {
  --bg: #111214;
  --sidebar-bg: #191b1f;
  --sidebar-border: #2b2f36;
  --main-bg: #15171a;
  --panel: #20242a;
  --panel-hover: #262b32;
  --surface: #24282f;
  --surface2: #303640;
  --text: #edf0f5;
  --text-muted: #9aa3b2;
  --text-dim: #687180;
  --accent: #ed2224;
  --accent-dark: #c91618;
  --accent-soft: rgba(237, 34, 36, 0.12);
  --accent-glow: rgba(237, 34, 36, 0.22);
  --teal: #14b8a6;
  --teal-soft: rgba(20, 184, 166, 0.1);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.08);
  --danger-border: rgba(248, 113, 113, 0.3);
  --line: #2b2f36;
  --line2: #343a44;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

input.mono, .mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-top {
  padding: 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

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

.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.logo-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.logo-sub {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 86px;
}

.form-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.form-section-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field.wide {
  grid-column: 1 / -1;
}

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

input, select {
  width: 100%;
  height: 34px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius-xs);
  color: var(--text);
  padding: 0 9px;
  outline: none;
  transition: border-color 150ms, box-shadow 150ms, opacity 150ms;
  -webkit-appearance: none;
}

input:disabled, select:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

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

input:hover:not(:focus):not(:disabled), select:hover:not(:focus):not(:disabled) {
  border-color: var(--surface2);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239aa3b2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 26px;
  cursor: pointer;
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.checkbox-field.compact {
  margin-bottom: 10px;
}

.inline-check {
  align-self: end;
  height: 34px;
}

.calculated-info {
  margin-top: 10px;
  border: 1px solid var(--line2);
  border-radius: var(--radius-xs);
  background: rgba(237, 34, 36, 0.08);
  color: #ffb4b5;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  padding: 8px 9px;
}

.checkbox-field input[type="checkbox"] {
  width: 15px;
  height: 15px;
  min-height: 0;
  padding: 0;
  border-radius: 3px;
  appearance: auto;
  -webkit-appearance: checkbox;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-error {
  min-height: 18px;
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
  padding: 0 16px;
  margin-top: 8px;
}

.form-footer {
  display: flex;
  gap: 6px;
  padding: 14px 16px;
  border-top: 1px solid var(--sidebar-border);
  position: sticky;
  bottom: 0;
  background: var(--sidebar-bg);
  flex-wrap: wrap;
}

.btn-primary {
  flex: 1 1 100%;
  min-height: 36px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  transition: background 150ms, box-shadow 150ms, transform 80ms;
}

.btn-primary:hover {
  background: var(--accent-dark);
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost, .btn-cancel {
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
}

.btn-ghost {
  border: 1px solid var(--line2);
  color: var(--text-muted);
}

.btn-ghost:hover {
  border-color: var(--surface2);
  color: var(--text);
}

.btn-cancel {
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-cancel:hover {
  border-color: var(--danger);
}

.is-hidden {
  display: none !important;
}

.main-area {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--main-bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.topbar-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.topbar-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius-sm);
}

.mode-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: background 150ms, color 150ms;
}

.mode-link:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.mode-link.is-active {
  background: var(--accent);
  color: #fff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.tbtn {
  height: 30px;
  padding: 0 11px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  transition: background 150ms, border-color 150ms, color 150ms;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tbtn:hover {
  background: var(--panel-hover);
  border-color: var(--surface2);
  color: var(--text);
}

.tbtn-sep {
  width: 1px;
  height: 20px;
  background: var(--line2);
  margin: 0 4px;
}

.tbtn-danger {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.tbtn-danger:hover {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.14);
  color: var(--danger);
}

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  min-height: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.preview-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.preview-scale {
  font-size: 11px;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

.preview-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.preview-facts span {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius-xs);
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
}

.preview-canvas {
  flex: 1;
  min-height: 320px;
  display: grid;
  place-items: center;
  background: #b8bcc4;
  border: 1px solid #8f96a1;
  border-radius: var(--radius);
  overflow: hidden;
}

.facade-preview-svg {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 620px;
}

.preview-facade-contour,
.preview-frame,
.preview-strip {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.preview-facade-contour,
.preview-frame {
  stroke: #222;
  stroke-width: 2.5;
}

.preview-strip {
  stroke: #7f93a5;
  stroke-width: var(--strip-stroke, 3);
}

.preview-dimensions {
  fill: #000;
  font-size: 13px;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
}

.preview-dimensions line {
  stroke: #000;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.preview-dimensions text {
  dominant-baseline: middle;
  text-anchor: middle;
  fill: #000;
}

.preview-dimensions .rotated-label {
  text-anchor: middle;
}

.empty-preview {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.status-bar {
  padding: 4px 20px;
  min-height: 26px;
}

.status-msg {
  font-size: 11px;
  font-weight: 600;
  color: var(--teal);
  min-height: 16px;
}

.table-section {
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  max-height: 260px;
  display: flex;
  flex-direction: column;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--sidebar-bg);
}

.table-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.table-count {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 10px;
  font-family: 'JetBrains Mono', monospace;
}

.table-wrap {
  overflow: auto;
  flex: 1;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  z-index: 1;
}

td {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(43, 47, 54, 0.72);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  vertical-align: middle;
}

td:nth-child(2) {
  color: var(--text);
  font-weight: 700;
}

td:nth-child(3),
td:nth-child(5),
td:nth-child(6) {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #d25b5d;
}

tbody tr {
  transition: background 100ms;
}

tbody tr:hover td {
  background: var(--panel-hover);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-table {
  height: 64px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

.action-cell {
  white-space: nowrap;
}

.action-cell .table-button + .table-button {
  margin-left: 4px;
}

.table-button {
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line2);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  transition: background 150ms, border-color 150ms, color 150ms;
}

.table-button:hover {
  background: var(--panel-hover);
  border-color: var(--surface2);
  color: var(--text);
}

.danger-link {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.danger-link:hover {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.14);
}

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  background: #581112;
  border: 1px solid #9f181a;
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  color: #ffc6c6;
  font-size: 12px;
  font-weight: 700;
  padding: 10px 16px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px) scale(0.97);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .form-footer {
    position: static;
  }

  .main-area {
    min-height: 560px;
  }

  .preview-area {
    min-height: 440px;
  }
}

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

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

  .topbar-left,
  .mode-switch {
    width: 100%;
  }

  .mode-link {
    flex: 1;
  }

  .topbar-actions {
    width: 100%;
  }

  .tbtn {
    flex: 1;
  }

  .preview-header,
  .preview-header-left {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-canvas {
    min-height: 280px;
  }
}
