:root {
  --bg: #0b1120;
  --panel: #111827;
  --panel-elev: #1e293b;
  --border: #263248;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #10b981;
  --accent-hover: #059669;
  --blue: #38bdf8;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

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

/* Topbar */
.topbar {
  height: 54px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

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

.brand-icon {
  font-size: 22px;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar-stats {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

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

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--panel-elev);
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #273549;
}

.btn-primary {
  background: var(--accent);
  color: #032217;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #ecfdf5;
}

.btn-accent {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent);
  border-color: rgba(16, 185, 129, 0.35);
}

.btn-accent:hover {
  background: rgba(16, 185, 129, 0.25);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--panel-elev);
}

.btn-ghost.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--blue);
  color: var(--blue);
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.15);
}

.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 7px;
  font-size: 11px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.btn-icon:hover {
  background: var(--panel-elev);
  color: var(--text);
}

.input, .textarea, .select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
}

.input-sm, .select-sm {
  padding: 5px 8px;
  font-size: 12px;
}

.input-xs {
  padding: 4px 7px;
  font-size: 11.5px;
}

.textarea {
  resize: vertical;
  line-height: 1.45;
}

/* Badges */
.badge {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-neutral { background: #334155; color: #e2e8f0; }
.badge-ok { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-warn { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.badge-err { background: rgba(239, 68, 68, 0.22); color: #f87171; }

/* 3-Pane Workspace */
.workspace {
  display: grid;
  grid-template-columns: 270px 1fr 410px;
  flex: 1;
  min-height: 0;
}

/* Left Sidebar */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--panel-elev);
  color: var(--text);
}

.set-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.set-item {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.12s, border-color 0.12s;
}

.set-item:hover {
  background: rgba(30, 41, 59, 0.65);
}

.set-item.active {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.45);
}

.set-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.set-item-id {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.set-item-title {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.set-item-ja {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qa-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.qa-dot.ok { background: var(--accent); }
.qa-dot.warn { background: var(--amber); }
.qa-dot.err { background: var(--red); }

/* Center Pane */
.center-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #070c17;
}

.set-bar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.set-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.set-bar-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.set-id-pill {
  background: rgba(16, 185, 129, 0.18);
  color: var(--accent);
  font-weight: 700;
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.set-bar-title {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.set-bar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.set-meta-form {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.set-meta-footer {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

/* Quiz Strip */
.quiz-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #0d1526;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.quiz-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.quiz-pill:hover {
  border-color: #475569;
}

.quiz-pill.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--blue);
  color: #e0f2fe;
}

.quiz-pill-num {
  font-weight: 700;
  color: var(--text-muted);
}

.quiz-pill.active .quiz-pill-num {
  color: var(--blue);
}

/* Map Section */
.map-section {
  position: relative;
  flex: 1;
  min-height: 0;
}

.mapkit-container {
  width: 100%;
  height: 100%;
}

.map-toolbar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.map-toolbar > * {
  pointer-events: auto;
}

.map-search-box {
  position: relative;
  display: flex;
  gap: 4px;
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(8px);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  width: 260px;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
  z-index: 30;
}

.search-result-item {
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid rgba(38, 50, 72, 0.5);
}

.search-result-item:hover {
  background: var(--panel-elev);
}

.map-toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(8px);
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text);
  padding: 3px 6px;
  cursor: pointer;
  user-select: none;
}

.map-status-bar {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(8px);
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.status-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.status-ok { background: rgba(16, 185, 129, 0.22); color: #34d399; }
.status-err { background: rgba(239, 68, 68, 0.25); color: #fca5a5; }
.status-neutral { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; }

.map-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.mapkit-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #0f172a, #020617);
  padding: 24px;
  z-index: 10;
}

.fallback-card {
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.5;
}

.fallback-card code {
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--blue);
}

/* MapKit custom vertex handle */
.kyt-vertex-handle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  border: 2.5px solid #10b981;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  cursor: grab;
}

/* Right Inspector */
.inspector {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inspector-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.inspector-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dirty-indicator {
  font-size: 11px;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  padding: 2px 8px;
  border-radius: 999px;
}

.inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inspector-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f172a;
}

.footer-right {
  display: flex;
  gap: 8px;
}

.card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

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

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

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

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

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

.raw-poly-details {
  font-size: 12px;
  color: var(--text-muted);
}

.raw-poly-details summary {
  cursor: pointer;
  margin-bottom: 6px;
}

.qa-box {
  border-radius: 8px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
}

.qa-box.has-err {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.qa-box.has-warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  width: 560px;
  max-width: 100%;
  max-height: 85vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal-lg {
  width: 780px;
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.qa-summary-bar {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 600;
}

.qa-filter-row {
  display: flex;
  gap: 6px;
}

.qa-issue-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 440px;
  overflow-y: auto;
}

.qa-issue-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.snapshot-create-row {
  display: flex;
  gap: 8px;
}

.snapshot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.snapshot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.empty-state {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--panel-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--red); }
