* { box-sizing: border-box; }

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #172033;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-h: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.82rem; }
.api-hint { margin: 2px 0 12px; font-size: 0.75rem; word-break: break-all; }
.https-warning { margin-bottom: 12px; line-height: 1.4; }

/* Inputs / buttons */
input, select, button, textarea {
  font: inherit;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 8px 10px;
  margin: 4px 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
label {
  font-size: 0.8rem;
  color: var(--muted);
}
button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--primary-h); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.ghost:hover { background: var(--panel); }

.status { font-size: 0.82rem; margin-top: 6px; min-height: 1em; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

/* Login */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #1e293b, #0f172a);
  z-index: 1000;
}
.login-card {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.3rem; }
.login-card button { width: 100%; margin-top: 6px; }

/* App layout */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.topbar-right { display: flex; gap: 12px; align-items: center; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 360px;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
}
.main { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.row button { flex: 1; }
.checkbox { display: flex; align-items: center; gap: 6px; color: var(--text); }
.checkbox input { width: auto; margin: 0; }

/* Zones list */
.list { display: flex; flex-direction: column; gap: 8px; }
.zone-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}
.zone-item .zi-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.zone-item .zi-name { font-weight: 600; }
.zone-item .zi-meta { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
.zone-item .zi-actions { display: flex; gap: 6px; margin-top: 8px; }
.zone-item .zi-actions button { flex: 1; padding: 6px 8px; font-size: 0.78rem; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
}
.badge.active { background: #064e3b; color: #6ee7b7; }
.badge.inactive { background: #4c0519; color: #fda4af; }

/* Rates */
.rates-block, .geom-block { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; }
.rates-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.rate-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.rate-row input { margin: 0; }
.rate-row .rr-label { flex: 1; font-size: 0.82rem; }
.rate-row input[type="number"] { width: 90px; flex: none; }
.rate-row .checkbox { font-size: 0.75rem; }
.rate-row button { padding: 4px 8px; }

/* Segmented control */
.seg { display: flex; margin-bottom: 10px; }
.seg-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 0;
}
.seg-btn:first-child { border-radius: 6px 0 0 6px; }
.seg-btn:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.seg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

details { margin: 10px 0; }
summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; margin-bottom: 6px; }

/* Detail panel */
.detail {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 320px;
  max-height: calc(100% - 24px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 500;
  display: flex;
  flex-direction: column;
}
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.detail-head button { padding: 2px 10px; }
.detail pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Leaflet popup readability */
.leaflet-popup-content { color: #1e293b; }
.leaflet-popup-content h3 { margin: 0 0 6px; font-size: 14px; }
.leaflet-popup-content p { margin: 3px 0; font-size: 12px; }
