:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #637083;
  --panel: #ffffff;
  --panel-soft: #f5f7fa;
  --line: #d9e0e8;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --shadow: 0 16px 44px rgba(19, 35, 54, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #e8edf3;
}

button,
input {
  font: inherit;
}

button,
.file-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: #9db1c7;
  background: #f8fbff;
}

button:focus-visible,
input:focus-visible,
.file-button:focus-visible {
  outline: 3px solid rgba(11, 107, 203, 0.26);
  outline-offset: 2px;
}

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

.map-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #dce5ee;
}

.map-canvas,
.fallback-map {
  display: block;
  width: 100%;
  height: 100%;
}

.annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.map-stage::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: rgba(255, 255, 255, var(--presentation-fade, 0));
  content: "";
}

.map-stage.is-presenting .annotation-layer {
  z-index: 3;
}

.map-stage.is-drawing .annotation-layer {
  cursor: crosshair;
  pointer-events: auto;
}

.annotation-shape {
  pointer-events: visiblePainted;
  cursor: grab;
}

.annotation-shape.is-active {
  filter: drop-shadow(0 0 5px rgba(11, 107, 203, 0.95));
}

.annotation-shape.is-spotlight {
  filter: drop-shadow(0 0 7px rgba(255, 255, 255, 0.95));
}

.annotation-handle {
  cursor: move;
  pointer-events: all;
}

.map-controls {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(2, 42px);
  gap: 8px;
}

.map-controls button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border-color: rgba(23, 32, 42, 0.2);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 24px rgba(20, 34, 48, 0.18);
  font-weight: 800;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  color: #25364a;
  background: linear-gradient(135deg, #edf2f7, #dce6ef);
}

.empty-state h1 {
  margin: 0 0 8px;
  font-size: 44px;
  line-height: 1;
}

.empty-state p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
}

.api-key-form {
  display: grid;
  gap: 10px;
  width: min(520px, 90vw);
  margin-top: 22px;
  padding: 16px;
  border: 1px solid rgba(23, 32, 42, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 32px rgba(20, 34, 48, 0.12);
  text-align: left;
}

.api-key-form label {
  color: #35465c;
  font-size: 13px;
  font-weight: 800;
}

.api-key-form div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.api-key-form input {
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
}

.api-key-form button {
  min-height: 38px;
}

#clear-api-key {
  justify-self: start;
  color: #4b5966;
  background: #ffffff;
}

.control-panel {
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  padding: 20px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-row h2,
.status-box h3,
.annotation-list h3 {
  margin: 0;
}

.brand-row h2 {
  font-size: 24px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-weight: 800;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-group label,
.style-row label,
.project-card label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.project-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.project-card input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.project-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

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

.search-row input {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-row button,
.tool-button.active,
.action-row button.primary {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
}

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

.tool-button {
  padding: 0 10px;
  text-align: center;
}

.shape-drawer {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.shape-drawer summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.shape-button {
  min-height: 38px;
  font-size: 20px;
  font-weight: 800;
}

.shape-button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef6ff;
}

.style-row {
  display: grid;
  grid-template-columns: auto 52px auto minmax(100px, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.style-row input[type="color"] {
  width: 52px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.style-row input[type="range"] {
  width: 100%;
}

.palette-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.color-swatch {
  min-width: 0;
  min-height: 32px;
  border: 2px solid #ffffff;
  border-radius: 8px;
  background: var(--swatch-color);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.color-swatch.active {
  outline: 3px solid rgba(11, 107, 203, 0.35);
  outline-offset: 1px;
}

.layer-controls,
.presentation-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.layer-controls h3,
.presentation-controls h3 {
  grid-column: 1 / -1;
  margin: 0;
}

.layer-controls label,
.presentation-controls label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #35465c;
  font-size: 13px;
  font-weight: 700;
}

.layer-controls input,
.presentation-controls input {
  accent-color: var(--accent);
}

.presentation-controls input[type="range"],
.presentation-controls button {
  grid-column: 1 / -1;
}

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

.note-editor {
  display: grid;
  gap: 8px;
}

.note-editor label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.note-editor textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
}

.note-editor input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
}

.annotation-note-label {
  pointer-events: none;
}

.file-button {
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
}

.status-box,
.annotation-list,
.project-stats {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.status-box p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.project-stats h3 {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-pill {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.stat-pill strong {
  font-size: 17px;
}

.stat-pill span {
  color: var(--muted);
  font-size: 11px;
}

.annotation-list {
  min-height: 160px;
}

.annotation-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.annotation-delete {
  min-height: 30px;
  padding: 0 8px;
  border-color: #f0b7b3;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.annotation-item.active {
  border-color: var(--accent);
}

.annotation-item.muted {
  opacity: 0.48;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.18);
}

.annotation-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annotation-meta {
  color: var(--muted);
  font-size: 12px;
}

.annotation-note-preview {
  overflow: hidden;
  color: #35465c;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Deal status ─────────────────────────────────────────────────────── */

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-button {
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0.55;
}

.status-button[data-status="prospecting"] { background: #00BCD4; }
.status-button[data-status="active"]       { background: #2196F3; }
.status-button[data-status="under-contract"] { background: #FFC107; }
.status-button[data-status="closed"]       { background: #4CAF50; }
.status-button[data-status="passed"]       { background: #F44336; }
.status-button[data-status=""] {
  background: #e8edf3;
  color: #4b5966;
  font-size: 14px;
  font-weight: 800;
  opacity: 1;
}

.status-button.active,
.status-button:hover {
  opacity: 1;
  outline: 3px solid rgba(11, 107, 203, 0.35);
  outline-offset: 2px;
}

.annotation-status-pill {
  display: inline-block;
  padding: 1px 6px;
  margin-top: 2px;
  border-radius: 4px;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.status-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.status-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Slideshow walk-through ──────────────────────────────────────────── */

.slideshow-overlay[hidden] {
  display: none;
}

.slideshow-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px 56px;
  pointer-events: none;
  background: linear-gradient(to top, rgba(0,0,0,0.52) 0%, transparent 55%);
}

.slideshow-label {
  max-width: 680px;
  text-align: center;
  color: #ffffff;
  font-size: 26px;
  font-weight: 800;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
  line-height: 1.2;
}

.slideshow-note {
  max-width: 640px;
  margin-top: 8px;
  text-align: center;
  color: rgba(255, 255, 255, 0.88);
  font-size: 15px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
  line-height: 1.5;
}

.slideshow-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  pointer-events: auto;
}

.slideshow-nav button {
  min-height: 40px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
  backdrop-filter: blur(8px);
  font-weight: 700;
}

.slideshow-nav button:hover {
  background: rgba(255, 255, 255, 0.26);
  border-color: rgba(255, 255, 255, 0.6);
}

#slideshow-counter {
  min-width: 56px;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 700;
}

.app-shell.slideshow-active .control-panel {
  display: none;
}

/* ── Annotation tooltip ──────────────────────────────────────────────── */

.annotation-tooltip {
  position: fixed;
  z-index: 999;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(23, 32, 42, 0.93);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
  max-width: 220px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transform: translate(14px, -50%);
  visibility: hidden;
}

.annotation-tooltip.is-visible {
  visibility: visible;
}

.tooltip-status {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Status filter ───────────────────────────────────────────────────── */

.status-filter-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.status-filter-box h3 {
  margin: 0;
}

.status-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.status-filter-btn {
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0.4;
  transition: opacity 0.15s;
}

.status-filter-btn[data-status="prospecting"] { background: #00BCD4; }
.status-filter-btn[data-status="active"]       { background: #2196F3; }
.status-filter-btn[data-status="under-contract"] { background: #FFC107; }
.status-filter-btn[data-status="closed"]       { background: #4CAF50; }
.status-filter-btn[data-status="passed"]       { background: #F44336; }

.status-filter-btn.active,
.status-filter-btn:hover {
  opacity: 1;
  outline: 3px solid rgba(11, 107, 203, 0.35);
  outline-offset: 2px;
}

#clear-status-filter {
  padding: 0 10px;
  height: 32px;
  min-height: 32px;
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 58vh) auto;
  }

  .control-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: none;
  }
}

@media (max-width: 460px) {
  .control-panel {
    padding: 14px;
  }

  .tool-grid,
  .action-row,
  .search-row {
    grid-template-columns: 1fr;
  }

  .style-row {
    grid-template-columns: auto 52px;
  }
}

#print-map-bg {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  pointer-events: none;
}

@media print {
  @page { margin: 0; size: landscape; }

  body {
    background: #000;
    margin: 0;
    padding: 0;
  }

  .app-shell {
    display: block;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }

  .control-panel,
  .map-controls,
  .annotation-tooltip,
  .empty-state,
  .slideshow-overlay {
    display: none !important;
  }

  .map-stage {
    position: fixed;
    inset: 0;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden;
  }

  .map-canvas {
    display: none !important;
  }

  #print-map-bg {
    display: block !important;
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    z-index: 0;
  }

  .annotation-layer {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    overflow: hidden;
  }
}
