:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef2f4;
  --border: #d9e0e4;
  --text: #17272e;
  --muted: #5d7179;
  --accent: #0f766e;
  --accent-soft: #d7f0ec;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn: #b54708;
  --warn-soft: #fdf0dd;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --shadow: 0 8px 24px rgba(18, 38, 46, 0.08);
  --radius: 14px;
  --font: Vazirmatn, "Segoe UI", Tahoma, "Iranian Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f171b;
    --surface: #152026;
    --surface-2: #1b262c;
    --border: #26343b;
    --text: #e8eef1;
    --muted: #9aacb4;
    --accent: #35c2b3;
    --accent-soft: #10312e;
    --danger: #ff8a80;
    --danger-soft: #3a1614;
    --warn: #f5b264;
    --warn-soft: #33220f;
    --ok: #7bdc9c;
    --ok-soft: #122b1c;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.4; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

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

.brand h1 { font-size: 17px; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

.logo {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.icon-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  height: calc(100dvh - 61px);
}

.sidebar {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
  border-inline-start: 1px solid var(--border);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.panel-muted { box-shadow: none; background: transparent; }

/* ---------------------------------------------------------- layer list */

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

.layer-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.layer-item:hover { border-color: var(--accent); }

.layer-item input { margin-top: 5px; accent-color: var(--accent); }

.layer-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.layer-item .name { font-weight: 600; font-size: 14px; }
.layer-item .desc { font-size: 12px; color: var(--muted); }

.layer-thumb {
  flex: 0 0 44px;
  width: 44px; height: 44px;
  border-radius: 8px;
  background: var(--surface-2) center/cover no-repeat;
  border: 1px solid var(--border);
}

/* -------------------------------------------------------------- fields */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 8px; }

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, Consolas, monospace; direction: ltr; text-align: left; }

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}

.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.coords {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  direction: ltr;
  text-align: center;
}

.hint { margin: 0 0 8px; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ map */

.map-wrap { position: relative; min-height: 0; }

.map {
  width: 100%;
  height: 100%;
  background: var(--surface-2);
  z-index: 1;
}

.leaflet-container { font-family: var(--font); }

/* ---------------------------------------------------------------- toast */

.toast {
  position: absolute;
  inset-inline-start: 50%;
  transform: translateX(50%);
  bottom: 22px;
  z-index: 800;
  max-width: min(560px, calc(100% - 40px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* ----------------------------------------------------------- admin page */

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { font-size: 20px; }
.page-header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card h2 { font-size: 16px; margin-bottom: 4px; }
.card .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.notice {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
  background: var(--surface-2);
  color: var(--muted);
}
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

.config-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.config-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.config-item.active { border-color: var(--accent); background: var(--accent-soft); }
.config-item input[type="radio"] { accent-color: var(--accent); }
.config-item .meta { flex: 1; min-width: 0; }
.config-item .title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: left; }
.config-item .tag { font-size: 11px; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

.log {
  margin-top: 12px;
  max-height: 240px;
  overflow: auto;
  background: #0b1418;
  color: #cfe6ea;
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
}

.kv { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.kv b { color: var(--text); font-weight: 600; }

.hidden { display: none !important; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .icon-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 850;
    max-height: 62dvh;
    border-inline-start: 0;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% + 10px));
    transition: transform 0.25s ease;
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.18);
  }
  .sidebar.open { transform: translateY(0); }
  .map { height: 100%; }
}
