:root {
  color-scheme: dark;
  --bg: #070b12;
  --surface: #0c1320;
  --surface-2: #111b2c;
  --surface-3: #172338;
  --border: #22304a;
  --border-soft: rgba(148, 163, 184, 0.16);
  --text: #ecf2ff;
  --muted: #93a4bd;
  --accent: #22c55e;
  --accent-strong: #16a34a;
  --blue: #38bdf8;
  --danger: #fb7185;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); }
button, select, input { font: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, select:focus-visible, .drawing-viewport:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.app-shell { height: 100%; display: grid; grid-template-rows: 66px minmax(0, 1fr); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 0 22px; border-bottom: 1px solid var(--border); background: rgba(10, 16, 27, 0.96);
  backdrop-filter: blur(16px); z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px;
  background: linear-gradient(145deg, #22c55e, #0ea5e9); color: #03120a; font-weight: 900; letter-spacing: -0.05em;
  box-shadow: 0 8px 26px rgba(34, 197, 94, .22);
}
.brand-copy { display: grid; line-height: 1.12; }
.brand-copy strong { font-size: 15px; letter-spacing: .01em; }
.brand-copy small { color: var(--muted); font-size: 12px; margin-top: 3px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.privacy-pill {
  display: inline-flex; align-items: center; gap: 8px; color: #b9c8db; font-size: 12px;
  border: 1px solid var(--border-soft); border-radius: 999px; padding: 7px 10px; background: rgba(255,255,255,.025);
}
.privacy-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(34,197,94,.10); }

.button, .tool-button, .icon-button {
  border: 1px solid transparent; cursor: pointer; color: var(--text); transition: .18s ease;
}
.button { min-height: 39px; padding: 0 15px; border-radius: 10px; font-weight: 720; }
.button-primary { background: var(--accent); color: #04150a; }
.button-primary:hover { background: #4ade80; transform: translateY(-1px); }
.button-ghost { background: transparent; border-color: var(--border); }
.button-ghost:hover { background: var(--surface-3); }
.button-block { width: 100%; }
button:disabled { opacity: .42; cursor: not-allowed; transform: none !important; }

.workspace { min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); transition: grid-template-columns .22s ease; }
.workspace.sidebar-hidden { grid-template-columns: 0 minmax(0, 1fr); }
.sidebar {
  min-width: 0; overflow: auto; border-right: 1px solid var(--border); background: var(--surface); padding: 16px;
  scrollbar-color: #34435d transparent; transition: opacity .15s ease, transform .22s ease;
}
.workspace.sidebar-hidden .sidebar { opacity: 0; transform: translateX(-24px); pointer-events: none; padding-left: 0; padding-right: 0; }
.panel { border: 1px solid var(--border-soft); background: rgba(255,255,255,.025); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.intro-panel { background: radial-gradient(circle at 0 0, rgba(34,197,94,.12), transparent 48%), rgba(255,255,255,.025); }
.eyebrow { margin: 0 0 8px; color: #4ade80; font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .12em; }
.intro-panel h1 { margin: 0; font-size: 22px; line-height: 1.16; letter-spacing: -.025em; }
.intro-panel > p:not(.eyebrow) { margin: 11px 0 15px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.intro-actions { display: grid; gap: 8px; }
.panel h2 { margin: 0; font-size: 13px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.status-badge { border-radius: 999px; padding: 4px 8px; font-size: 10px; font-weight: 800; background: #1d293b; color: #aab8cd; }
.status-badge.loading { background: rgba(56,189,248,.12); color: #7dd3fc; }
.status-badge.success { background: rgba(34,197,94,.12); color: #86efac; }
.status-badge.error { background: rgba(251,113,133,.12); color: #fda4af; }
.file-metadata { margin: 0; display: grid; gap: 0; }
.file-metadata div { display: grid; grid-template-columns: 82px minmax(0,1fr); gap: 10px; padding: 9px 0; border-top: 1px solid var(--border-soft); }
.file-metadata div:first-child { border-top: 0; }
.file-metadata dt { color: var(--muted); font-size: 11px; }
.file-metadata dd { margin: 0; font-size: 11px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tips-panel ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.75; }
.warning-panel { border-color: rgba(245,158,11,.22); background: rgba(245,158,11,.055); }
.warning-panel h2 { color: #fbbf24; }
.warning-panel p { color: #c8b997; font-size: 11px; line-height: 1.55; margin: 8px 0 0; }

.viewer-section { min-width: 0; min-height: 0; display: grid; grid-template-rows: 51px minmax(0, 1fr); }
.toolbar {
  min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 12px;
  border-bottom: 1px solid var(--border); background: #0a111d; overflow-x: auto; scrollbar-width: thin;
}
.toolbar-group { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.toolbar-group-right { margin-left: auto; }
.toolbar-divider { width: 1px; height: 25px; background: var(--border); margin: 0 2px; }
.icon-button, .tool-button {
  height: 34px; border-radius: 8px; background: var(--surface-2); border-color: var(--border-soft); font-weight: 720;
}
.icon-button { width: 35px; padding: 0; font-size: 17px; }
.tool-button { padding: 0 11px; font-size: 11px; }
.icon-button:hover, .tool-button:hover { background: var(--surface-3); border-color: #34455f; }
.tool-button-accent { color: #86efac; border-color: rgba(34,197,94,.28); background: rgba(34,197,94,.08); }
.zoom-label { width: 49px; text-align: center; color: #c1cee0; font-size: 11px; font-variant-numeric: tabular-nums; }
.select-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.select-label select {
  height: 34px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 8px; padding: 0 27px 0 9px;
}

.viewer { position: relative; min-width: 0; min-height: 0; overflow: hidden; isolation: isolate; }
.viewer-dark { background: #06090f; }
.viewer-light { background: #f5f7fa; }
.viewer-blueprint { background: #071b33; }
.grid-layer { position: absolute; inset: 0; opacity: .32; pointer-events: none; z-index: -1; }
.viewer-dark .grid-layer { background-image: linear-gradient(rgba(255,255,255,.035) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.035) 1px,transparent 1px); background-size: 24px 24px; }
.viewer-light .grid-layer { background-image: linear-gradient(rgba(15,23,42,.055) 1px,transparent 1px),linear-gradient(90deg,rgba(15,23,42,.055) 1px,transparent 1px); background-size: 24px 24px; }
.viewer-blueprint .grid-layer { background-image: linear-gradient(rgba(125,211,252,.055) 1px,transparent 1px),linear-gradient(90deg,rgba(125,211,252,.055) 1px,transparent 1px); background-size: 24px 24px; }
.empty-state {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 28px; transition: opacity .2s ease;
}
.empty-state.hidden { opacity: 0; pointer-events: none; }
.drop-icon { width: 86px; height: 86px; display: grid; place-items: center; border-radius: 24px; margin-bottom: 18px; background: rgba(34,197,94,.07); border: 1px dashed rgba(74,222,128,.40); }
.drop-icon svg { width: 48px; fill: none; stroke: #6ee7a2; stroke-width: 2.3; stroke-linejoin: round; stroke-linecap: round; }
.empty-state h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.empty-state p { margin: 7px 0 18px; color: var(--muted); font-size: 13px; }
.empty-state small { color: #6f819b; margin-top: 12px; font-size: 10px; }
.viewer.drag-active .empty-state { background: rgba(34,197,94,.10); }
.viewer.drag-active .drop-icon { transform: scale(1.05); }

.drawing-viewport { position: absolute; inset: 0 0 28px; overflow: hidden; cursor: grab; touch-action: none; }
.drawing-viewport.panning { cursor: grabbing; }
.drawing-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; user-select: none; }
.drawing-stage svg { display: block; width: 100%; height: 100%; overflow: visible; }
.viewer-light .drawing-stage svg { filter: none; }

.loading-overlay, .error-overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(4,8,14,.78); backdrop-filter: blur(8px); }
.loading-overlay[hidden], .error-overlay[hidden] { display: none; }
.loading-overlay { flex-direction: column; text-align: center; padding: 30px; }
.loader { width: 42px; height: 42px; border: 3px solid rgba(255,255,255,.13); border-top-color: #4ade80; border-radius: 50%; animation: spin .8s linear infinite; margin-bottom: 16px; }
.loading-overlay strong { font-size: 15px; }
.loading-overlay span { max-width: 480px; margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.5; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-card { width: min(430px, calc(100% - 36px)); background: #111927; border: 1px solid rgba(251,113,133,.24); border-radius: 18px; padding: 24px; text-align: center; box-shadow: var(--shadow); }
.error-icon { width: 42px; height: 42px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 50%; background: rgba(251,113,133,.12); color: #fda4af; font-weight: 900; }
.error-card h2 { margin: 0; font-size: 18px; }
.error-card p { margin: 9px 0 18px; color: #bdc8d8; font-size: 12px; line-height: 1.55; white-space: pre-line; }
.viewer-footer { position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; height: 28px; padding: 0 11px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: #8291a8; background: rgba(8,13,22,.92); border-top: 1px solid rgba(148,163,184,.11); font-size: 10px; pointer-events: none; }
.viewer-light .viewer-footer { background: rgba(241,245,249,.94); color: #526078; }
.viewer-blueprint .viewer-footer { background: rgba(5,22,43,.94); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 260px minmax(0,1fr); }
  .privacy-pill { display: none; }
  .toolbar { align-items: flex-start; }
  .select-label > span { display: none; }
}
@media (max-width: 700px) {
  .app-shell { grid-template-rows: 60px minmax(0,1fr); }
  .topbar { padding: 0 12px; }
  .brand-copy strong { font-size: 13px; }
  .brand-copy small { display: none; }
  .topbar .button { padding: 0 11px; }
  .workspace, .workspace.sidebar-hidden { grid-template-columns: minmax(0,1fr); }
  .sidebar { position: absolute; z-index: 30; top: 60px; bottom: 0; left: 0; width: min(310px, 88vw); box-shadow: var(--shadow); transform: translateX(-105%); opacity: 0; pointer-events: none; }
  .workspace:not(.sidebar-hidden) .sidebar { transform: translateX(0); opacity: 1; pointer-events: auto; }
  .viewer-section { grid-column: 1; }
  .toolbar-group-right .select-label { display: none; }
  .tool-button { padding: 0 9px; }
  .empty-state h2 { font-size: 18px; }
}
