:root {
  --bg:#f4f7f8;
  --card:#fff;
  --text:#152126;
  --muted:#64747b;
  --border:#dfe7ea;
  --accent:#1677ff;
  --danger:#c62828;
  --working:#2da864;
  --broken:#e53935;
  --repair:#f2b53b;
  --disabled:#666;
}
* { box-sizing:border-box; }
html { scroll-behavior:smooth; }
body {
  margin:0;
  font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color:var(--text);
  background:var(--bg);
  -webkit-text-size-adjust:100%;
}
a { color:var(--accent); text-decoration:none; }
.topbar {
  min-height:62px;
  background:#fff;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:0 22px;
  position:sticky;
  top:0;
  z-index:1100;
}
.brand-wrap { display:flex; align-items:baseline; gap:10px; min-width:0; }
.topbar strong { font-size:20px; white-space:nowrap; }
.topbar nav { display:flex; gap:16px; white-space:nowrap; }
.muted { color:var(--muted); font-size:13px; }

.stats {
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
  padding:12px;
  max-width:1400px;
  margin:auto;
}
.stats div { background:#fff; border:1px solid var(--border); border-radius:14px; padding:12px 16px; min-width:0; }
.stats b { display:block; font-size:24px; }
.stats span { color:var(--muted); font-size:13px; }

.scheme-public {
  display:grid;
  grid-template-columns:minmax(0,1fr) 370px;
  grid-template-areas:
    "controls controls"
    "scheme report";
  gap:12px;
  padding:0 12px 14px;
  max-width:1600px;
  margin:0 auto;
}
.panel,.card {
  background:#fff;
  border:1px solid var(--border);
  border-radius:16px;
  padding:18px;
}
.scheme-controls { grid-area:controls; display:flex; align-items:end; gap:22px; justify-content:space-between; }
.scheme-controls h2 { margin:0 0 5px; }
.compact-help { margin:0; }
.filter-grid {
  display:grid;
  grid-template-columns:210px 170px minmax(220px,320px);
  gap:10px;
  align-items:end;
  flex:0 1 auto;
}
.filter-grid label { margin:0; }
.scheme-card {
  grid-area:scheme;
  position:relative;
  background:#e8edef;
  border:1px solid var(--border);
  border-radius:16px;
  overflow:hidden;
  min-width:0;
}
#scheme {
  width:100%;
  height:calc(100vh - 240px);
  min-height:620px;
  background-color:#eef2f3;
  background-image:
    linear-gradient(rgba(140,150,155,.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140,150,155,.13) 1px, transparent 1px);
  background-size:28px 28px;
}
.scheme-image { image-rendering:auto; }
.scheme-empty-hint {
  pointer-events:none;
  position:absolute;
  left:50%; top:50%;
  transform:translate(-50%,-50%);
  z-index:500;
  width:min(560px,80%);
  background:rgba(255,255,255,.93);
  border:1px solid var(--border);
  border-radius:14px;
  padding:18px;
  text-align:center;
  box-shadow:0 10px 30px rgba(0,0,0,.08);
}
.scheme-empty-hint b { display:block; margin-bottom:5px; }
.scheme-empty-hint span { color:var(--muted); font-size:13px; }
.scheme-legend {
  position:absolute;
  left:12px;
  bottom:12px;
  z-index:700;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  background:rgba(255,255,255,.92);
  border:1px solid var(--border);
  border-radius:10px;
  padding:7px 10px;
  font-size:12px;
}
.scheme-legend span { display:inline-flex; align-items:center; gap:5px; }
.legend-dot { width:10px; height:10px; border-radius:50%; display:inline-block; }
.legend-dot.working { background:var(--working); }
.legend-dot.broken { background:var(--broken); }
.legend-dot.repair { background:var(--repair); }
.report-panel { grid-area:report; align-self:start; max-height:calc(100vh - 240px); overflow:auto; }

h1,h2,h3 { margin-top:0; }
h2 { margin-bottom:8px; }
label { display:block; font-size:14px; margin:12px 0; }
input,select,textarea {
  width:100%;
  margin-top:6px;
  padding:11px 12px;
  min-height:44px;
  border:1px solid var(--border);
  border-radius:10px;
  background:#fff;
  font:inherit;
  font-size:16px;
}
textarea { min-height:90px; resize:vertical; }
button,.button {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  border:0;
  border-radius:10px;
  min-height:44px;
  padding:10px 14px;
  background:var(--accent);
  color:#fff;
  font-weight:600;
  font-size:15px;
  cursor:pointer;
  touch-action:manipulation;
}
button:disabled { opacity:.65; cursor:wait; }
button.secondary,.button.secondary { background:#eaf2ff; color:#245fa5; }
button.danger { background:#feeaea; color:var(--danger); }
button.small { min-height:36px; padding:7px 10px; font-size:13px; }
.primary-submit { width:100%; }
.row2 { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.selected {
  background:#f1f6f8;
  border-radius:10px;
  padding:11px 12px;
  font-size:13px;
  line-height:1.4;
}
.warning-selection { border:1px dashed #d0a843; background:#fff8dc; }
.warning-selection.ready-selection { border-style:solid; border-color:#9ed6b4; background:#ebf8ef; }
.notice { max-width:1400px; margin:0 auto 10px; border-radius:10px; padding:10px 14px; }
.notice.success { background:#e8f6ed; }
.notice.error { background:#ffebee; color:#a31313; }

.lamp-marker {
  width:30px;
  height:30px;
  border-radius:50% 50% 46% 46%;
  border:4px solid #fff;
  box-shadow:0 0 0 1px rgba(0,0,0,.25), 0 3px 7px rgba(0,0,0,.22);
  position:relative;
}
.lamp-marker::after {
  content:"";
  position:absolute;
  width:7px;
  height:9px;
  left:50%;
  bottom:-10px;
  transform:translateX(-50%);
  background:#5d676b;
  border-radius:1px 1px 3px 3px;
}
.lamp-marker.working { background:var(--working); }
.lamp-marker.broken { background:var(--broken); }
.lamp-marker.repair { background:var(--repair); }
.lamp-marker.disabled { background:var(--disabled); }
.lamp-marker.admin-lamp { width:34px; height:34px; }
.lamp-marker.admin-lamp span {
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:10px;
  font-weight:800;
  color:#fff;
  text-shadow:0 1px 2px rgba(0,0,0,.4);
}
.placement-marker {
  width:40px;
  height:40px;
  border-radius:50%;
  background:#1677ff;
  border:4px solid #fff;
  box-shadow:0 0 0 2px rgba(22,119,255,.4),0 4px 10px rgba(0,0,0,.2);
  display:flex;
  align-items:center;
  justify-content:center;
  color:#fff;
  font-size:24px;
  font-weight:700;
}
.free-point-marker {
  width:26px;
  height:26px;
  border-radius:50%;
  background:#1677ff;
  border:4px solid #fff;
  box-shadow:0 0 0 2px rgba(22,119,255,.35),0 3px 8px rgba(0,0,0,.2);
}
.scheme-popup { min-width:190px; line-height:1.4; }
.scheme-popup button { width:100%; margin-top:9px; min-height:38px; font-size:13px; }
.popup-status { font-weight:700; margin-top:3px; }
.popup-notes { color:var(--muted); font-size:12px; margin-top:5px; }
.status-working { color:#1e7b48; }
.status-broken { color:#be2828; }
.status-repair { color:#9b6b00; }
.mobile-report-action { display:none; }

.auth-card { max-width:420px; margin:70px auto; background:#fff; padding:24px; border:1px solid var(--border); border-radius:16px; }
.admin-wrap { max-width:1450px; margin:20px auto; padding:0 14px 30px; }
.admin-head { display:flex; justify-content:space-between; align-items:center; gap:12px; }
.card { margin-bottom:16px; }
.card-title-row { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; }
.card-title-row h2 { margin-bottom:5px; }
.card-title-row p { margin:0; }
.status-pill { background:#eef1f2; color:var(--muted); border-radius:999px; padding:5px 9px; font-size:12px; white-space:nowrap; }
.status-pill.ok { background:#e6f6ec; color:#227746; }
.scheme-upload-form { display:grid; grid-template-columns:minmax(260px,1fr) auto; gap:10px; align-items:end; margin-top:10px; }
.scheme-upload-form label { margin:0; }
.scheme-delete-form { margin-top:10px; }
.admin-grid { display:grid; grid-template-columns:370px minmax(0,1fr); gap:18px; }
#admin-scheme {
  width:100%;
  height:620px;
  min-height:500px;
  border-radius:12px;
  overflow:hidden;
  background-color:#eef2f3;
  background-image:
    linear-gradient(rgba(140,150,155,.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140,150,155,.13) 1px, transparent 1px);
  background-size:28px 28px;
  border:1px solid var(--border);
}
.admin-scheme-warning { margin-top:7px; color:#9a6b00; font-size:12px; }
.form-actions { display:grid; grid-template-columns:1fr auto; gap:8px; }
.table-wrap { overflow:auto; -webkit-overflow-scrolling:touch; }
table { width:100%; border-collapse:collapse; font-size:14px; }
th,td { border-bottom:1px solid var(--border); padding:10px; text-align:left; vertical-align:top; }
th { background:#f7fafb; }
.inline-form { margin:0; }
.inline-form select { margin:0; min-width:120px; font-size:14px; min-height:38px; padding:7px 8px; }
.action-cell { display:flex; gap:6px; align-items:center; }
.action-cell form { margin:0; }

@media (max-width: 900px) {
  body { padding-bottom:env(safe-area-inset-bottom); }
  .topbar {
    min-height:54px;
    padding:0 12px;
    padding-top:env(safe-area-inset-top);
  }
  .brand-wrap { gap:6px; }
  .topbar strong { font-size:18px; }
  .topbar .muted { display:none; }
  .topbar nav { gap:12px; font-size:14px; }
  .stats { grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; padding:8px; }
  .stats div { border-radius:11px; padding:8px 4px; text-align:center; }
  .stats b { font-size:20px; line-height:1.05; }
  .stats span { display:block; margin-top:3px; font-size:10px; line-height:1.1; }

  .scheme-public {
    grid-template-columns:1fr;
    grid-template-areas:
      "controls"
      "scheme"
      "report";
    gap:8px;
    padding:0 8px 10px;
  }
  .panel,.card { border-radius:12px; padding:13px; }
  .scheme-controls { display:block; }
  .scheme-controls h2 { font-size:18px; margin-bottom:3px; }
  .filter-grid { grid-template-columns:1fr 1fr; gap:7px; margin-top:9px; }
  .filter-grid .search-field { grid-column:1/-1; }
  .filter-grid label { font-size:12px; }
  .filter-grid input,.filter-grid select { margin-top:4px; min-height:42px; }
  .scheme-card { border-radius:12px; }
  #scheme { height:62svh; min-height:390px; max-height:720px; }
  .scheme-legend { left:7px; bottom:7px; right:7px; justify-content:center; gap:8px; font-size:10px; padding:6px; }
  .scheme-empty-hint { width:82%; padding:14px; }
  .report-panel { max-height:none; overflow:visible; scroll-margin-top:62px; }
  .report-panel h3 { font-size:18px; margin-bottom:10px; }
  .primary-submit { min-height:50px; font-size:16px; }
  .row2 { grid-template-columns:1fr; gap:0; }
  .mobile-report-action:not([hidden]) {
    display:flex;
    position:fixed;
    left:12px;
    right:12px;
    bottom:max(12px, env(safe-area-inset-bottom));
    z-index:1200;
    min-height:50px;
    box-shadow:0 8px 24px rgba(0,0,0,.18);
  }

  .admin-wrap { margin:10px auto; padding:0 8px 20px; }
  .admin-head { margin-bottom:8px; }
  .admin-head h1 { font-size:22px; margin:0; }
  .card { margin-bottom:10px; }
  .card h2 { font-size:18px; }
  .scheme-upload-form { grid-template-columns:1fr; }
  .scheme-upload-form button { width:100%; }
  .admin-grid { grid-template-columns:1fr; }
  .admin-map-box { order:-1; }
  #admin-scheme { height:58svh; min-height:390px; max-height:700px; }
  .form-actions { grid-template-columns:1fr; }
  .form-actions button { width:100%; }
  .table-wrap { overflow:visible; }
  table.mobile-cards, table.mobile-cards thead, table.mobile-cards tbody, table.mobile-cards tr, table.mobile-cards td { display:block; width:100%; }
  table.mobile-cards thead { display:none; }
  table.mobile-cards tr {
    border:1px solid var(--border);
    border-radius:12px;
    background:#fff;
    margin-bottom:10px;
    padding:7px 10px;
  }
  table.mobile-cards td {
    border:0;
    border-bottom:1px solid #eef2f3;
    padding:8px 0 8px 42%;
    min-height:38px;
    position:relative;
    overflow-wrap:anywhere;
  }
  table.mobile-cards td:last-child { border-bottom:0; }
  table.mobile-cards td::before {
    content:attr(data-label);
    position:absolute;
    left:0;
    top:8px;
    width:38%;
    color:var(--muted);
    font-size:12px;
    font-weight:600;
  }
  table.mobile-cards td[colspan] { padding-left:0; }
  table.mobile-cards td[colspan]::before { display:none; }
  table.mobile-cards .inline-form select { width:100%; }
  .action-cell { display:grid !important; grid-template-columns:1fr 1fr; padding-left:0 !important; }
  .action-cell::before { display:none !important; }
  .action-cell button { width:100%; }
  .action-cell form { width:100%; }
}

@media (max-width: 420px) {
  .topbar nav a:first-child { display:none; }
  .filter-grid { grid-template-columns:1fr; }
  .filter-grid .search-field { grid-column:auto; }
  #scheme { height:58svh; min-height:360px; }
  .scheme-legend span:nth-child(1) { display:none; }
  .card-title-row { display:block; }
  .status-pill { display:inline-block; margin-top:8px; }
}

/* Coordinate-free scheme viewer */
.scheme-viewport {
  position:relative;
  overflow:hidden;
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
  cursor:grab;
}
.scheme-viewport:active { cursor:grabbing; }
.scheme-stage {
  position:absolute;
  left:0;
  top:0;
  transform-origin:0 0;
  will-change:transform;
  --marker-inv-scale:1;
}
.scheme-stage-image,
.scheme-stage-placeholder,
.scheme-marker-layer {
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
}
.scheme-stage-image {
  display:block;
  object-fit:fill;
  pointer-events:none;
  -webkit-user-drag:none;
}
.scheme-stage-placeholder {
  pointer-events:none;
  background-color:#eef2f3;
  background-image:
    linear-gradient(rgba(140,150,155,.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140,150,155,.16) 1px, transparent 1px);
  background-size:50px 50px;
}
.scheme-marker-layer { pointer-events:none; }
.scheme-marker {
  position:absolute;
  z-index:20;
  pointer-events:auto;
  transform:translate(-50%,-100%) scale(var(--marker-inv-scale));
  transform-origin:50% 100%;
  will-change:transform;
}
button.scheme-marker {
  min-height:0;
  padding:0;
  margin:0;
  border:4px solid #fff;
  cursor:pointer;
}
.placement-marker.scheme-marker {
  transform:translate(-50%,-50%) scale(var(--marker-inv-scale));
  transform-origin:50% 50%;
}
.scheme-zoom-controls {
  position:absolute;
  top:10px;
  right:10px;
  z-index:80;
  display:grid;
  gap:5px;
}
.scheme-zoom-controls button {
  width:42px;
  height:42px;
  min-height:42px;
  padding:0;
  border:1px solid rgba(0,0,0,.12);
  background:rgba(255,255,255,.94);
  color:#24333a;
  border-radius:10px;
  font-size:22px;
  box-shadow:0 2px 8px rgba(0,0,0,.12);
}
.scheme-object-card {
  position:absolute;
  left:12px;
  right:12px;
  bottom:48px;
  z-index:90;
  background:rgba(255,255,255,.96);
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 11px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  box-shadow:0 8px 24px rgba(0,0,0,.14);
}
.scheme-object-card[hidden] { display:none; }
.scheme-object-card div { min-width:0; }
.scheme-object-card b,.scheme-object-card span,.scheme-object-card small { display:block; }
.scheme-object-card b { font-size:14px; }
.scheme-object-card span { font-size:12px; color:var(--muted); overflow-wrap:anywhere; }
.scheme-object-card small { font-size:12px; font-weight:700; margin-top:2px; }
.scheme-object-card button { min-height:40px; white-space:nowrap; }
.status-text.status-working { color:#1e7b48; }
.status-text.status-broken { color:#be2828; }
.status-text.status-repair { color:#9b6b00; }
.status-text.status-disabled { color:#555; }

@media (max-width: 900px) {
  .scheme-zoom-controls { top:7px; right:7px; gap:4px; }
  .scheme-zoom-controls button { width:40px; height:40px; min-height:40px; border-radius:9px; }
  .scheme-object-card { left:7px; right:7px; bottom:44px; padding:8px; }
  .scheme-object-card button { min-height:38px; padding:8px 10px; font-size:13px; }
}
.lamp-marker.with-text span {
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:10px;
  font-weight:800;
  line-height:1;
  color:#fff;
  text-shadow:0 1px 2px rgba(0,0,0,.45);
  pointer-events:none;
}
