:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --shell: #111827;
  --shell-soft: #182235;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #101827;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #d9e1ea;
  --border-strong: #c3ceda;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #e8f0ff;
  --success: #0f9f6e;
  --success-soft: #e4f7ef;
  --warning: #d97706;
  --warning-soft: #fff5df;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 22px 14px;
  color: #e5edf7;
  background: linear-gradient(180deg, var(--shell), #151d2f);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.38);
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
}

.brand small,
.sidebar-footer small,
.sync-card span {
  color: #93a3b8;
}

.nav-list {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
}

.nav-list button,
.ghost-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: #cbd5e1;
  padding: 0 12px;
  text-align: left;
}

.nav-list button.active,
.nav-list button:hover {
  background: #203457;
  color: #dce9ff;
}

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

.sidebar-metrics div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.sidebar-metrics strong {
  font-size: 22px;
}

.sidebar-metrics span {
  color: #9fb0c4;
  font-size: 13px;
}

.sync-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
}

.sync-card strong,
.sync-card span {
  display: block;
}

.sync-card strong {
  font-size: 13px;
}

.sync-card span {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.35;
}

.sync-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.14);
}

.sync-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(15, 159, 110, 0.16);
}

.sidebar-footer {
  display: grid;
  gap: 12px;
}

.ghost-button {
  justify-content: center;
  border-color: rgba(148, 163, 184, 0.22);
}

.main-shell {
  min-width: 0;
}

.page {
  padding: 34px 32px 56px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.page-header.compact {
  margin-bottom: 22px;
}

.page-header h1,
.plan-title h1 {
  margin: 0;
  color: var(--text);
  font-size: 30px;
  line-height: 1.12;
}

.page-header p,
.plan-title p,
.crumb {
  margin: 8px 0 0;
  color: var(--muted);
}

.crumb {
  margin-top: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.header-actions,
.toolbar-actions,
.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.tool-button,
.icon-button,
.breadcrumb-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.2);
}

.primary-button:hover {
  background: var(--primary-strong);
  transform: translateY(-1px);
}

.primary-button.small,
.secondary-button.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.secondary-button,
.tool-button,
.icon-button,
.breadcrumb-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.secondary-button:hover,
.tool-button:hover,
.icon-button:hover,
.breadcrumb-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.icon-button,
.tool-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.icon-button.danger {
  color: var(--danger);
}

.breadcrumb-button {
  margin: 0 0 12px;
  padding: 0;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.project-grid,
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.resource-card {
  display: grid;
  gap: 18px;
  min-height: 170px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.resource-card:hover,
.resource-card:focus {
  border-color: #b8c7db;
  outline: none;
  transform: translateY(-2px);
}

.card-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: var(--primary);
  background: var(--primary-soft);
}

.card-icon.success {
  color: var(--success);
  background: var(--success-soft);
}

.card-content h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.card-content p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.metric {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric strong {
  display: block;
  font-size: 26px;
}

.metric span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.section-block {
  margin-top: 26px;
}

.section-block h2 {
  margin: 0 0 14px;
  color: #475569;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.plan-workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}

.plan-toolbar {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
}

.plan-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.plan-title h1 {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-title p {
  margin: 0 0 3px;
  font-size: 12px;
}

.zoom-label,
.pin-counter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.zoom-label {
  min-width: 68px;
  justify-content: center;
}

.plan-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 344px;
  min-height: 0;
}

.plan-canvas-wrap {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: #e7ebf1;
}

.plan-scroll {
  overflow: auto;
  padding: 28px 30px 70px;
  cursor: grab;
  touch-action: none;
}

.plan-paper {
  position: relative;
  width: var(--paper-width);
  max-width: var(--paper-max);
  min-width: 420px;
  margin: 0 auto;
  transform: rotate(var(--rotation));
  transform-origin: center center;
}

.plan-scroll.is-panning,
.plan-scroll.is-pinching {
  cursor: grabbing;
  user-select: none;
}

.plan-scroll.is-panning *,
.plan-scroll.is-pinching * {
  cursor: grabbing !important;
}

.pdf-render-slot {
  position: relative;
  min-height: var(--paper-min-height, 640px);
  border: 1px solid #cad3df;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.16);
  pointer-events: none;
}

.plan-image,
.pdf-canvas {
  display: block;
  width: 100%;
  height: auto;
  min-height: var(--paper-min-height, 640px);
  object-fit: contain;
  background: #ffffff;
}

.pdf-fallback {
  position: relative;
  min-height: var(--pdf-fallback-height, 720px);
  pointer-events: none;
}

.pdf-fallback iframe {
  display: block;
  width: 100%;
  height: var(--pdf-fallback-height, 720px);
  border: 0;
  background: #ffffff;
  pointer-events: none;
}

.pdf-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.78);
  color: #ffffff;
  font-size: 13px;
  transform: translate(-50%, -50%);
}

.pin-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pin-marker {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.32);
  font-size: 13px;
  font-weight: 900;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  cursor: pointer;
}

.pin-marker.selected {
  width: 40px;
  height: 40px;
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(217, 119, 6, 0.2), 0 12px 26px rgba(180, 83, 9, 0.24);
}

.canvas-help {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.86);
  color: #ffffff;
  font-size: 13px;
  transform: translateX(-50%);
}

.pin-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
}

.pin-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.pin-panel-header p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.pin-panel-header h2 {
  margin: 0;
  font-size: 24px;
}

.pin-switcher {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pin-switcher button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pin-switcher button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.pin-photo {
  min-height: 190px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-muted);
}

.pin-photo img {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.photo-empty,
.panel-empty,
.empty-state,
.loading-state {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 190px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.panel-empty {
  min-height: 100%;
}

.panel-empty span {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: var(--radius);
  color: var(--primary);
  background: var(--primary-soft);
}

.panel-empty h2 {
  margin: 0;
  color: var(--text);
}

.panel-empty p,
.empty-state p {
  margin: 0;
  line-height: 1.45;
}

.pin-details {
  display: grid;
  gap: 10px;
  margin: 0;
}

.pin-details div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.pin-details dt {
  color: var(--muted);
  font-size: 13px;
}

.pin-details dd {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.note-box {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.note-box strong,
.form-stack label,
.field-label {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.note-box p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.66);
}

.modal {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 32px 18px 0;
  font-size: 22px;
}

.modal-copy {
  margin: -4px 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-close {
  position: absolute;
  right: 14px;
  top: 14px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
}

.modal-close:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.form-stack {
  display: grid;
  gap: 16px;
}

.form-stack label {
  display: grid;
  gap: 8px;
}

.photo-picker,
.file-choice {
  display: grid;
  gap: 8px;
}

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

.form-stack input,
.form-stack textarea,
.form-stack select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

.form-stack input:focus,
.form-stack textarea:focus,
.form-stack select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.file-drop {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 114px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.file-drop.compact {
  min-height: 88px;
  padding: 12px;
}

.file-drop.has-file,
.file-drop.is-dragging {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}

.file-drop-title {
  display: block;
  max-width: min(420px, 100%);
  overflow-wrap: anywhere;
}

.file-drop-help {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.file-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.form-photo-preview {
  display: block;
  width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  object-fit: cover;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.toast-area {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #0f172a;
  color: #ffffff;
  box-shadow: var(--shadow-soft);
  font-weight: 700;
}

.toast.error {
  background: var(--danger);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .sidebar-metrics,
  .sync-card {
    display: none;
  }

  .sidebar-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .sidebar-footer small {
    display: none;
  }

  .sidebar-footer .ghost-button {
    width: 100%;
    min-height: 44px;
  }

  .page {
    padding: 24px 18px 40px;
  }

  .page-header,
  .plan-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-row,
  .plan-body {
    grid-template-columns: 1fr;
  }

  .plan-workspace {
    height: auto;
    min-height: 100vh;
  }

  .plan-canvas-wrap {
    height: 78vh;
    height: 78dvh;
    min-height: 520px;
  }

  .plan-scroll {
    height: 100%;
    min-height: 0;
    padding: 18px 14px 82px;
    overscroll-behavior: contain;
  }

  .pin-panel {
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 620px) {
  .project-grid,
  .resource-grid {
    grid-template-columns: 1fr;
  }

  .photo-picker-grid {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .toolbar-actions {
    width: 100%;
  }

  .primary-button,
  .secondary-button {
    flex: 1 1 auto;
  }

  .page-header h1 {
    font-size: 26px;
  }

  .canvas-help {
    width: calc(100% - 24px);
    justify-content: center;
  }
}

@media print {
  .sidebar,
  .plan-toolbar,
  .pin-panel,
  .canvas-help,
  .toast-area {
    display: none !important;
  }

  .app-shell,
  .plan-body,
  .plan-workspace {
    display: block;
    height: auto;
  }

  .plan-scroll {
    overflow: visible;
    padding: 0;
  }

  .plan-paper {
    width: 100%;
    transform: none !important;
  }
}
