:root {
  --bg: #0b1020;
  --card: #121a33;
  --text: #e9ecf5;
  --muted: #aab3d6;
  --border: #233057;
  --accent: #4ea1ff;
  --accent2: #7ee787;
  --sidebar-bg: #0a0f1c;
  --sidebar-border: #1c2746;
  --sidebar-text: #f5f7ff;
  --sidebar-muted: #7f8ab3;
  --shadow: 0 10px 25px rgba(0,0,0,0.25);
}
body[data-theme="light"] {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2433;
  --muted: #667196;
  --border: #dbe2f2;
  --accent: #2b6bff;
  --accent2: #2aa56a;
  --sidebar-bg: #0f1116;
  --sidebar-border: #202533;
  --sidebar-text: #f5f7ff;
  --sidebar-muted: #9aa3c4;
  --shadow: 0 12px 30px rgba(10,20,40,0.12);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}
.app {
  display: grid;
  grid-template-columns: auto 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 78px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 10px;
  transition: width 200ms ease;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 2;
}
.sidebar.expanded { width: 78px; }
.sidebar:not([data-pinned="1"]):hover { width: 78px; }
.sidebarHeader {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.sidebarHeader { flex-direction: row; align-items: center; }
.sidebarLogo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: contain;
  background: #0c1326;
}
.sidebarLogo { width: 38px; height: 38px; border-radius: 10px; }
.sidebarTitle {
  color: var(--sidebar-text);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 200ms ease;
}
.sidebarTitle { opacity: 0; }
.sidebarControls {
  display: flex;
  gap: 8px;
  margin-left: auto;
  position: absolute;
  right: 8px;
  top: 6px;
}
.sidebarControls { display: none; }
.sidebarBtn {
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  background: rgba(255,255,255,0.06);
}
.sidebarBtn:hover { border-color: var(--sidebar-border); color: var(--sidebar-text); }
.sidebarBtn.active { border-color: rgba(78,161,255,0.5); color: var(--sidebar-text); }
.sidebarNav {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}
.sidebarLink {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.sidebarIcon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  flex-shrink: 0;
}
.sidebarNav form { margin: 0; }
.sidebarLink .label {
  font-weight: 600;
  opacity: 0;
  transition: opacity 200ms ease;
}
.sidebarLink .label { display: none; }
.sidebar:not(.expanded) .sidebarLink {
  justify-content: center;
  padding: 10px 0;
}
.sidebar:not(.expanded) .sidebarLink .label { display: none; }
.sidebarLink:hover { border-color: var(--sidebar-border); background: rgba(255,255,255,0.04); }
.sidebarLink.active { background: rgba(78,161,255,0.18); border-color: rgba(78,161,255,0.35); }
.sidebarFooter {
  margin-top: auto;
  display: grid;
  gap: 8px;
}
.sidebarToggleRow {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--sidebar-muted);
}
.sidebarToggleRow span { display: none; }
.toggle {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  position: relative;
  cursor: pointer;
}
.toggle::after {
  content: "";
  width: 16px;
  height: 16px;
  position: absolute;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: var(--sidebar-text);
  transition: transform 160ms ease;
}
.toggle.on { background: rgba(78,161,255,0.45); }
.toggle.on::after { transform: translateX(16px); }
.content {
  padding: 24px 24px 40px 24px;
}
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}
.header h1 { margin: 0 0 6px 0; font-size: 28px; }
.sub { margin: 0; color: var(--muted); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.userbox {
  display: grid;
  gap: 8px;
  justify-items: end;
}
.usertext { color: var(--muted); font-size: 13px; }
.useractions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}
.form { display: grid; gap: 12px; }
.label { display: grid; gap: 6px; font-weight: 600; }
.label.inline {
  display: flex;
  align-items: center;
  gap: 10px;
}
.label.inline .input { width: auto; }
.modal .label.inline { justify-content: flex-start; }
.label.small { max-width: 180px; }
.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--accent); }
.row {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 12px;
  align-items: start;
}
.counties {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  min-height: 44px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  font-weight: 500;
}
.chip input { transform: translateY(0.5px); }
.actions { display: flex; gap: 10px; align-items: center; }
.btn {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #071024;
  font-weight: 800;
  cursor: pointer;
}
.btn.secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.btn.small {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.status { min-height: 18px; color: var(--muted); }
.status.err { color: #ff7b7b; }
.status.ok { color: #7ee787; }
.tableWrap { overflow: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tbody tr { cursor: move; }
.table tbody tr.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.table tbody tr.dragging { opacity: 0.6; }
.table th { text-align: left; color: var(--muted); font-weight: 700; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.sortBtn {
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sortBtn .sortIndicator {
  min-width: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.sortBtn.active .sortIndicator { color: var(--accent); }
.muted { color: var(--muted); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  margin-right: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.badge.ok { border-color: rgba(126,231,135,0.35); }
.footer { margin-top: 16px; color: var(--muted); }
.adminHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.adminForm { margin-bottom: 12px; }
.auth-card { max-width: 520px; }
.login-page {
  min-height: 100vh;
  background: #efefef;
  color: #1c2433;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 96px 24px 40px;
}
.login-card {
  width: 300px;
}
.login-logo-wrap {
  background: #fff;
  display: grid;
  place-items: center;
  padding: 22px 18px 28px;
  border: 1px solid #ececec;
  border-bottom: 0;
}
.login-logo {
  display: block;
  width: 100%;
  max-width: 260px;
  height: auto;
}
.login-form {
  display: grid;
  gap: 10px;
}
.login-input {
  width: 100%;
  height: 46px;
  padding: 0 10px;
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  background: #fff;
  color: #434343;
  font: inherit;
  outline: none;
}
.login-input::placeholder {
  color: #8f8f8f;
}
.login-input:focus {
  border-color: #9db9d8;
  box-shadow: 0 0 0 2px rgba(60, 126, 190, 0.08);
}
.login-btn {
  width: 100%;
  height: 46px;
  border: 1px solid #3c7ebe;
  border-radius: 4px;
  background: #3f7fba;
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.login-btn:hover {
  background: #3974ab;
}
.login-status {
  color: #b42318;
  font-size: 14px;
  line-height: 1.4;
}
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modalCard {
  width: min(760px, 92vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.savedLayout {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
}
.savedListBody {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}
.savedItem {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: rgba(255,255,255,0.03);
}
.savedItem.active {
  border-color: var(--accent);
  background: rgba(78,161,255,0.12);
}
.savedMeta {
  display: flex;
  gap: 8px;
  align-items: center;
}
.savedShare, .savedSearch { margin-top: 8px; }
.shareList { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.shareChip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.04);
}
.shareChip button { margin-left: 6px; }
.special {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
.specialRow {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.specialToggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  white-space: nowrap;
}
.specialFields {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.specialItem {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.specialLabel { font-weight: 600; }
.specialInput { width: 70px; padding: 8px 10px; }
.settingsNav {
  display: flex;
  gap: 10px;
  align-items: center;
}
.settingsLink {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  background: rgba(255,255,255,0.03);
  font-weight: 600;
}
.settingsLink.active {
  background: var(--accent);
  color: #071024;
  border-color: var(--accent);
}
.home-grid {
  display: grid;
  gap: 18px;
}
.home-card {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(220, 225, 235, 0.95);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 14px 34px rgba(31, 44, 74, 0.08);
}
.home-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.home-card-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  color: #162033;
}
.home-card-header p {
  margin: 6px 0 0;
  color: #6d7994;
}
.home-link {
  color: #2b6bff;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.module-tile {
  display: grid;
  gap: 8px;
  min-height: 116px;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid #d9e0ed;
  background: linear-gradient(135deg, #ffffff 0%, #f4f8ff 100%);
  color: #162033;
  text-decoration: none;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.module-tile:hover {
  transform: translateY(-1px);
  border-color: #b9caea;
  box-shadow: 0 12px 24px rgba(31, 69, 128, 0.08);
}
.module-tile strong {
  font-size: 18px;
}
.module-tile span {
  color: #66748d;
  line-height: 1.45;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.stat-tile {
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fcfdff 0%, #edf4ff 100%);
  border: 1px solid #d9e4f4;
}
.stat-value {
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
  color: #162033;
  margin-bottom: 8px;
}
.stat-label {
  color: #697690;
  font-weight: 600;
}
.home-list {
  display: grid;
  gap: 12px;
}
.home-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #dde3ef;
  border-radius: 16px;
  background: #fff;
  color: #162033;
  text-decoration: none;
}
.home-list-item:hover {
  border-color: #bdd0ee;
  background: #f9fbff;
}
.home-list-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.home-list-main strong,
.home-list-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.home-list-main span {
  color: #697690;
}
.home-list-meta {
  display: grid;
  gap: 4px;
  text-align: right;
  color: #697690;
  white-space: nowrap;
  font-size: 14px;
}
.home-empty {
  padding: 18px;
  border: 1px dashed #d5dbe7;
  border-radius: 16px;
  color: #7b869e;
  background: #fafcff;
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; transform: translateX(0); }
  .content { padding-left: 20px; padding-right: 20px; }
  .row { grid-template-columns: 1fr; }
  .label.small { max-width: none; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .settingsNav { flex-wrap: wrap; }
  .specialFields { width: 100%; }
  .savedLayout { grid-template-columns: 1fr; }
  .home-card-header { display: grid; }
  .home-list-item { display: grid; justify-content: stretch; }
  .home-list-meta { text-align: left; }
}
