:root {
  --ink: #101418;
  --muted: #65717e;
  --line: #d9e0e7;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-solid: #f8fafc;
  --accent: #0f766e;
  --accent-2: #b91c1c;
  --gold: #b7791f;
  --blue: #1d4ed8;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

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

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

button, .icon-link {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  border-radius: 6px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  text-decoration: none;
}

button:hover, .icon-link:hover { border-color: #aab7c4; }

button.active, .primary-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.danger { color: #fff; background: var(--accent-2); border-color: var(--accent-2); }

select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 8px 9px;
}

textarea { min-height: 82px; resize: vertical; }

label {
  display: grid;
  gap: 6px;
  color: #34404b;
  font-size: 12px;
  font-weight: 650;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 310px 1fr 390px;
  grid-template-rows: 56px 1fr;
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(248, 250, 252, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  z-index: 10;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.identity strong, .identity span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

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

.top-actions select { width: 190px; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-height: 32px;
}

.role-pill {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  border: 1px solid #a7f3d0;
  color: #065f46;
  background: #ecfdf5;
  border-radius: 999px;
  padding: 6px 10px;
}

.left-rail, .right-rail {
  padding: 10px;
  display: grid;
  gap: 10px;
  align-content: start;
  overflow: auto;
  background: #edf2f6;
  border-right: 1px solid var(--line);
}

.right-rail {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(203, 213, 225, 0.85);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.panel.compact { max-height: 230px; }

.panel-title {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.panel-title h2, .dialog-card h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0;
}

.site-tree, .layers-list, .tab-body, .inspector-body {
  padding: 10px;
}

.tree-node {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 7px 6px;
  border-radius: 6px;
}

.tree-node.active { background: #e0f2fe; }

.tree-node small { color: var(--muted); }

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

.tool-grid button {
  justify-content: flex-start;
  min-height: 38px;
  padding: 0 10px;
}

.tool-grid svg, .asset-marker svg { width: 17px; height: 17px; }

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

#map {
  height: 100%;
  width: 100%;
  background: #c9d4dc;
}

.map-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  display: flex;
  gap: 8px;
}

.map-hud span {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 750;
}

.drop-zone {
  position: absolute;
  inset: auto 28px 24px 28px;
  z-index: 520;
  background: rgba(16, 20, 24, 0.78);
  color: #fff;
  border: 1px dashed rgba(255,255,255,0.65);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  transform: translateY(140%);
  transition: transform 160ms ease;
  pointer-events: none;
}

.drop-zone.visible { transform: translateY(0); }

.asset-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  color: #fff;
  box-shadow: 0 9px 24px rgba(15, 23, 42, 0.32);
}

.asset-marker.unchecked { outline: 2px solid rgba(245, 158, 11, 0.8); }
.asset-marker.checked { outline: 2px solid rgba(22, 163, 74, 0.8); }

.leaflet-marker-icon.drop-target .asset-marker {
  outline: 4px solid rgba(20, 184, 166, 0.9);
  transform: scale(1.08);
}

.coverage-handle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.28);
}

.coverage-handle.range {
  border-color: #111827;
}

.coverage-handle.fov-left,
.coverage-handle.fov-right {
  border-color: #b91c1c;
}

.map-context-menu {
  position: absolute;
  z-index: 900;
  min-width: 160px;
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: grid;
  gap: 4px;
}

.map-context-menu button {
  justify-content: flex-start;
  border: 0;
  background: transparent;
}

.map-context-menu button.active {
  background: #ecfdf5;
  color: var(--accent);
}

.photo-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #111827;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
}

.evidence-card {
  cursor: grab;
}

.evidence-card:active {
  cursor: grabbing;
}

.item-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  display: grid;
  gap: 7px;
  margin-bottom: 8px;
}

.item-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-card strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.item-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.chip {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 750;
}

.sev-critical { background: #7f1d1d; color: #fff; border-color: #7f1d1d; }
.sev-high { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.sev-medium { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.sev-low { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.sev-undefined { background: #f1f5f9; color: #475569; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.tabs button {
  border: 0;
  border-radius: 0;
  background: #fff;
  min-height: 38px;
}

.tabs button.active {
  color: var(--accent);
  background: #ecfdf5;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.hidden { display: none !important; }

.empty-state {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
}

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

.form-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.check-list {
  max-height: 176px;
  overflow: auto;
  display: grid;
  gap: 6px;
  padding: 4px 0;
}

.check-line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  font-size: 12px;
  color: #26323e;
}

.check-line input { width: auto; margin-top: 2px; }

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

.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.layer-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.layer-control input[type="range"] { padding: 0; }

dialog {
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(15, 23, 42, 0.36); }

.dialog-card {
  width: min(460px, 94vw);
  padding: 16px;
  display: grid;
  gap: 12px;
  background: #fff;
}

.dialog-card menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgba(248, 250, 252, 0.55), rgba(248, 250, 252, 0.90)),
    url("https://images.unsplash.com/photo-1494526585095-c41746248156?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.login-panel {
  width: min(390px, calc(100vw - 32px));
  background: rgba(255,255,255,0.94);
  border: 1px solid rgba(255,255,255,0.68);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}

.login-panel h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.login-panel form { display: grid; gap: 13px; }
.login-panel .primary-btn { width: 100%; }
.form-error { color: var(--accent-2); margin: 0; font-size: 13px; }

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

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 48vh auto auto;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
  .topbar, .left-rail, .map-stage, .right-rail { grid-column: 1; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .left-rail, .right-rail { border: 0; }
  .map-stage { height: 48vh; }
}
