:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --fill: #f2f2f5;
  --fill-2: #e8e8ed;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --hair: rgba(0, 0, 0, 0.1);
  --accent: #0071e3;
  --accent-text: #ffffff;
  --danger: #d70015;
  --radius: 10px;
  --radius-s: 8px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #161617;
    --fill: #1f1f21;
    --fill-2: #2c2c2e;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --hair: rgba(255, 255, 255, 0.12);
    --accent: #2997ff;
    --accent-text: #000000;
    --danger: #ff453a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input { font: inherit; color: inherit; }

/* Header */
.bar { border-bottom: 1px solid var(--hair); background: var(--surface); }
.bar-inner {
  max-width: 1280px; margin: 0 auto; padding: 16px 24px;
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
}
.brand { font-size: 21px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.tagline { margin: 0; color: var(--text-2); font-size: 14px; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

/* Empty state */
.empty { padding: 48px 0; }
.drop {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: 280px; padding: 40px;
  border: 1px dashed var(--text-3); border-radius: 14px;
  background: var(--surface); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); }
.drop-title { font-size: 34px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.drop-sub { margin-top: 8px; font-size: 17px; color: var(--text-2); }
.link { color: var(--accent); }
.features {
  list-style: none; padding: 0; margin: 40px 0 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 32px;
}
.features li { border-top: 1px solid var(--hair); padding-top: 16px; display: flex; flex-direction: column; gap: 4px; }
.features strong { font-size: 15px; font-weight: 600; }
.features span { color: var(--text-2); font-size: 14px; }

/* Workspace */
.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start;
}
.toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding-bottom: 16px; flex-wrap: wrap;
}
.toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }
.count { font-size: 15px; font-weight: 600; }

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 16px;
}
.card {
  position: relative; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--hair); overflow: hidden; cursor: pointer; user-select: none;
  outline: none;
}
.card:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 50%, transparent); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb { aspect-ratio: 4 / 3; background: var(--fill); display: block; width: 100%; object-fit: cover; }
.thumb-ph { aspect-ratio: 4 / 3; background: var(--fill); display: flex; align-items: center; justify-content: center; color: var(--text-3); font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.card-body { padding: 8px 12px 12px; }
.card-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta.warn { color: var(--danger); }
.check {
  position: absolute; top: 4px; left: 4px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.check::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid #fff; background: rgba(0, 0, 0, 0.25);
}
.card.selected .check::before {
  background: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 16px; background-position: center; background-repeat: no-repeat;
}
.badge {
  position: absolute; top: 12px; right: 12px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--text);
  border: 1px solid var(--hair);
}
.hint { color: var(--text-3); font-size: 12px; margin: 16px 0 0; }
kbd { font-family: inherit; font-size: 11px; padding: 0 4px; border: 1px solid var(--hair); border-radius: 4px; }

/* Inspector */
.inspector {
  position: sticky; top: 16px;
  background: var(--surface); border: 1px solid var(--hair); border-radius: 14px;
  max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden;
}
.inspector-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--hair); }
.inspector-head h2 { margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--text-2); margin: 2px 0 0; font-size: 13px; }
#inspector-body { overflow-y: auto; flex: 1; }
#inspector-body.disabled { opacity: .4; pointer-events: none; }
.group { padding: 16px 20px 20px; border-bottom: 1px solid var(--hair); }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

.facts { margin: 0; display: grid; grid-template-columns: 84px 1fr; gap: 4px 12px; font-size: 13px; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; word-break: break-word; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 12px; color: var(--text-2); }
input[type="datetime-local"], input[type="number"], input[type="search"] {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--hair); border-radius: var(--radius-s); background: var(--fill);
  font-size: 15px; outline: none; -webkit-appearance: none; appearance: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.note { font-size: 12px; color: var(--text-2); margin: 0 0 12px; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--fill); border-radius: var(--radius-s); padding: 2px; margin-bottom: 16px;
}
.segmented button {
  border: 0; background: none; padding: 6px 8px; min-height: 32px; border-radius: 6px;
  font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text);
}
.segmented button[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 0 0 .5px var(--hair); font-weight: 600; }
.segmented button:disabled { color: var(--text-3); cursor: default; }

.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.btn {
  min-height: 36px; padding: 6px 16px; border-radius: 999px;
  border: 1px solid var(--hair); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--fill); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.inspector-foot {
  display: flex; justify-content: space-between; gap: 8px; padding: 12px 20px;
  border-top: 1px solid var(--hair); background: var(--surface);
}
.inspector-foot .btn { min-height: 44px; flex: 1; }

/* Search */
.search { position: relative; margin-bottom: 12px; }
.results {
  position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 4px);
  list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius-s);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); max-height: 260px; overflow-y: auto;
}
.results li button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; min-height: 40px;
}
.results li button:hover, .results li button:focus { background: var(--fill); outline: none; }
.results .empty-r { padding: 8px 10px; font-size: 13px; color: var(--text-2); }

.map { height: 220px; border-radius: var(--radius-s); border: 1px solid var(--hair); background: var(--fill); }
.leaflet-container { font-family: var(--font); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 2000; max-width: calc(100vw - 32px);
}

.dropveil {
  position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 85%, transparent); border: 2px dashed var(--accent);
  font-size: 22px; font-weight: 600; pointer-events: none;
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .inspector { position: static; max-height: none; }
  #inspector-body { overflow: visible; }
  .inspector-foot { position: sticky; bottom: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .features { grid-template-columns: 1fr; gap: 16px; }
  main { padding: 16px; }
  .bar-inner { padding: 12px 16px; }
  .drop { min-height: 220px; padding: 24px; }
  .drop-title { font-size: 28px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
}

@media (prefers-color-scheme: dark) {
  .map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9); }
  .map { background: #1f1f21; }
}
