:root {
  --navy-950: #081827;
  --navy-900: #0c2236;
  --navy-800: #123552;
  --navy-700: #18486e;
  --orange-600: #e75b16;
  --orange-500: #f06a22;
  --orange-100: #fff0e8;
  --ink-900: #17202a;
  --ink-700: #3c4956;
  --ink-500: #66727e;
  --line: #d9e0e6;
  --line-strong: #c3cdd6;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --surface-3: #eef2f5;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --success: #137a4d;
  --shadow-sm: 0 1px 3px rgba(8, 24, 39, 0.08);
  --shadow-md: 0 10px 30px rgba(8, 24, 39, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--surface-2);
  color: var(--ink-900);
  overflow: hidden;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100%; height: 100%; display: flex; flex-direction: column; }
.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto minmax(380px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  color: white;
  background: linear-gradient(135deg, var(--navy-950), var(--navy-800));
  border-bottom: 3px solid var(--orange-500);
  box-shadow: var(--shadow-md);
  z-index: 10;
}
.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 900; letter-spacing: -0.03em;
  background: var(--orange-500); color: white;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}
.brand-block h1 { margin: 0; font-size: 19px; line-height: 1.1; }
.brand-block p { margin: 4px 0 0; color: #c6d5e2; font-size: 12px; }
.project-status { display: flex; align-items: center; gap: 10px; min-width: 0; }
.project-status strong { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill {
  display: inline-flex; align-items: center; min-height: 26px;
  padding: 4px 9px; border-radius: 999px;
  background: rgba(255,255,255,.12); color: #dbe7f0; font-size: 11px;
}
.status-pill.saving { color: #ffe1c7; background: rgba(240,106,34,.18); }
.status-pill.saved { color: #c7f5dc; background: rgba(19,122,77,.25); }
.top-actions { display: flex; justify-content: flex-end; gap: 8px; }

.btn {
  min-height: 38px; border-radius: 8px; padding: 8px 13px;
  border: 1px solid transparent; font-weight: 700; font-size: 13px;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--orange-500); color: white; border-color: var(--orange-500); }
.btn-primary:hover { background: var(--orange-600); border-color: var(--orange-600); }
.btn-ghost { background: rgba(255,255,255,.07); color: inherit; border-color: rgba(255,255,255,.2); }
.editor-pane .btn-ghost, .preview-pane .btn-ghost, .sidebar .btn-ghost {
  background: white; color: var(--navy-800); border-color: var(--line-strong);
}
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #f5b7b1; }
.btn-block { width: 100%; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--orange-500); color: white; border: 0;
  font-size: 23px; line-height: 1;
}

.app-body { flex: 1; min-height: 0; display: flex; }
.sidebar {
  width: 268px; min-width: 268px; display: flex; flex-direction: column;
  padding: 18px 14px 14px;
  background: var(--navy-900); color: white;
  border-right: 1px solid rgba(255,255,255,.08);
  overflow: hidden;
}
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 14px; }
.sidebar h2 { margin: 2px 0 0; font-size: 18px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 800; color: var(--orange-500); }
.search-box { display: grid; gap: 5px; font-size: 11px; color: #aac0d1; margin-bottom: 12px; }
.search-box input {
  width: 100%; min-height: 38px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.08);
  color: white; padding: 8px 10px; outline: none;
}
.search-box input::placeholder { color: #8ea7ba; }
.search-box input:focus { border-color: var(--orange-500); box-shadow: 0 0 0 3px rgba(240,106,34,.18); }
.project-list { flex: 1; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 8px; padding-right: 3px; }
.project-card {
  width: 100%; text-align: left; color: white;
  background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.1);
  border-radius: 9px; padding: 10px 11px;
}
.project-card:hover { background: rgba(255,255,255,.09); }
.project-card.active { border-color: var(--orange-500); background: rgba(240,106,34,.13); }
.project-card strong { display: block; font-size: 13px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-card span { display: block; margin-top: 4px; color: #a9bfd0; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-card small { display: block; margin-top: 6px; color: #7e9aaf; font-size: 10px; }
.project-list-empty { color: #91a9bb; font-size: 12px; text-align: center; padding: 28px 12px; }
.sidebar-footer { display: grid; gap: 7px; padding-top: 13px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer .btn { min-height: 36px; font-size: 12px; }

.workspace { flex: 1; min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(500px, 0.92fr) minmax(520px, 1.08fr); }
.editor-pane, .preview-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.editor-pane { background: var(--surface-2); border-right: 1px solid var(--line); }
.editor-header, .preview-header {
  min-height: 74px; display: flex; justify-content: space-between; align-items: center;
  gap: 14px; padding: 14px 18px; background: white; border-bottom: 1px solid var(--line);
}
.editor-header h2, .preview-header h2 { margin: 2px 0 0; font-size: 18px; }
.editor-header .btn { font-size: 12px; }
.tabs {
  display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto;
  background: white; border-bottom: 1px solid var(--line);
}
.tab {
  white-space: nowrap; border: 1px solid transparent; background: transparent;
  color: var(--ink-500); border-radius: 7px; padding: 8px 10px; font-size: 12px; font-weight: 700;
}
.tab:hover { background: var(--surface-3); color: var(--navy-800); }
.tab.active { background: var(--navy-900); color: white; border-color: var(--navy-900); }
#project-form { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px 32px; }
.form-panel { display: none; }
.form-panel.active { display: block; }
.section-card {
  background: white; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.section-card h3 { margin: 0 0 13px; font-size: 15px; color: var(--navy-900); }
.section-card h4 { margin: 0; font-size: 13px; color: var(--navy-900); }
.card-heading-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.card-heading-row h3 { margin: 0; }
.card-heading-row.subheading { margin: 16px 0 9px; padding-top: 13px; border-top: 1px solid var(--line); }
.inline-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.small-action, .text-button {
  border: 0; background: transparent; color: var(--orange-600); font-size: 12px; font-weight: 800; padding: 3px 4px;
}
.small-action:hover, .text-button:hover { text-decoration: underline; }
.helper-text { margin: 4px 0 0; color: var(--ink-500); font-size: 11px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-span-2 { grid-column: span 2; }
.field {
  display: grid; gap: 6px; color: var(--ink-700); font-size: 11px; font-weight: 750;
}
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 7px;
  background: white; color: var(--ink-900); padding: 9px 10px; outline: none;
  font-size: 13px; font-weight: 500;
}
.field input { min-height: 39px; }
.field textarea { resize: vertical; min-height: 80px; line-height: 1.42; }
.field select { min-height: 39px; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--orange-500); box-shadow: 0 0 0 3px rgba(240,106,34,.12);
}
.directory-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.directory-grid .section-card { margin-bottom: 0; }

.list-editor { display: grid; gap: 8px; }
.list-row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) 34px; align-items: start; gap: 8px;
  padding: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
}
.list-row-index { display: grid; place-items: center; min-height: 36px; font-size: 11px; font-weight: 800; color: var(--ink-500); }
.list-row textarea, .list-row input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; background: white;
  padding: 8px 9px; font-size: 12px; outline: none;
}
.list-row textarea { min-height: 54px; resize: vertical; line-height: 1.35; }
.list-editor.compact .list-row textarea { min-height: 38px; }
.remove-row {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid #efc1bd;
  background: var(--danger-bg); color: var(--danger); font-weight: 900;
}
.table-editor { display: grid; gap: 7px; }
.table-row {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, .85fr) minmax(0, .95fr) 34px;
  gap: 7px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2);
}
.table-row.sheet-row { grid-template-columns: minmax(110px, .7fr) minmax(220px, 2fr) 34px; }
.table-row.revision-row { grid-template-columns: minmax(110px, .7fr) minmax(220px, 2fr) 34px; }
.table-row input {
  min-width: 0; width: 100%; min-height: 36px; padding: 7px 8px; font-size: 12px;
  border: 1px solid var(--line-strong); border-radius: 6px; outline: none;
}
.table-labels {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, .85fr) minmax(0, .95fr) 34px;
  gap: 7px; padding: 0 8px; color: var(--ink-500); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
}
.sheet-table .table-labels { grid-template-columns: minmax(110px, .7fr) minmax(220px, 2fr) 34px; }

.image-upload-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.upload-card { display: flex; flex-direction: column; gap: 11px; }
.upload-card h3 { margin-bottom: 0; }
.image-preview-box {
  position: relative; aspect-ratio: 2.15 / 1; overflow: hidden; display: grid; place-items: center;
  border: 1px dashed var(--line-strong); border-radius: 9px; background: var(--surface-3); color: var(--ink-500); font-size: 12px;
}
.image-preview-box.map { aspect-ratio: 1 / 1; max-height: 250px; }
.image-preview-box img { display: none; width: 100%; height: 100%; object-fit: cover; }
.image-preview-box.has-image img { display: block; }
.image-preview-box.has-image span { display: none; }
.upload-button {
  min-height: 39px; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid var(--orange-500); background: var(--orange-100); color: var(--orange-600); font-size: 12px; font-weight: 850; cursor: pointer;
}
.notice-card { border-left: 4px solid var(--navy-700); background: white; border-radius: 8px; padding: 12px 14px; color: var(--ink-700); font-size: 12px; }
.notice-card p { margin: 5px 0 0; line-height: 1.45; }

.preview-pane { background: #dfe5ea; }
.preview-actions { display: flex; gap: 8px; }
.preview-stage { position: relative; flex: 1; min-height: 0; padding: 14px; }
#pdf-preview {
  width: 100%; height: 100%; border: 1px solid #bfc9d1; border-radius: 8px;
  background: #cfd7de; box-shadow: var(--shadow-md); display: none;
}
.preview-stage.has-pdf #pdf-preview { display: block; }
.preview-empty, .preview-loading {
  position: absolute; inset: 14px; display: grid; place-items: center; align-content: center; gap: 10px;
  color: var(--ink-500); background: rgba(255,255,255,.7); border: 1px dashed #aab7c2; border-radius: 8px; text-align: center;
}
.preview-stage.has-pdf .preview-empty { display: none; }
.preview-loading { display: none; z-index: 3; background: rgba(255,255,255,.9); }
.preview-stage.loading .preview-loading { display: grid; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 4px solid #dbe3e9; border-top-color: var(--orange-500);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.preview-footnote { padding: 8px 16px 11px; color: var(--ink-500); font-size: 10px; background: white; border-top: 1px solid var(--line); }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  max-width: 380px; padding: 12px 15px; border-radius: 9px;
  color: white; background: var(--navy-900); box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: .18s ease;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #b9c4cd; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
.sidebar ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.25); background-clip: padding-box; }

@media (max-width: 1450px) {
  .workspace { grid-template-columns: minmax(480px, .95fr) minmax(480px, 1.05fr); }
  .topbar { grid-template-columns: minmax(220px, 1fr) auto minmax(340px, 1fr); gap: 12px; }
  .top-actions .btn { padding-inline: 10px; }
}

@media (max-width: 1120px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; }
  .topbar { position: sticky; top: 0; grid-template-columns: 1fr auto; }
  .project-status { display: none; }
  .app-body { min-height: calc(100vh - 76px); }
  .sidebar { width: 240px; min-width: 240px; }
  .workspace { display: flex; flex-direction: column; }
  .editor-pane { min-height: 760px; border-right: 0; }
  .preview-pane { min-height: 760px; }
  #project-form { max-height: none; }
}

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; gap: 10px; }
  .top-actions { justify-content: flex-start; flex-wrap: wrap; }
  .app-body { display: block; }
  .sidebar { width: 100%; min-width: 0; max-height: 360px; }
  .workspace { width: 100%; }
  .editor-header, .preview-header { align-items: flex-start; flex-direction: column; }
  .form-grid.two-col, .form-grid.three-col, .directory-grid, .image-upload-grid { grid-template-columns: 1fr; }
  .field-span-2 { grid-column: span 1; }
  .table-row, .table-labels { grid-template-columns: 1fr; }
  .table-labels { display: none; }
}
