/* ============================================================
   RR Stats — Telegram Mini App
   Естетика: темна, ігрова, з жовтими акцентами
   ============================================================ */

:root,
[data-theme="dark"] {
  /* ТЕМНА ТЕМА (default) */
  --bg: #0f0f12;
  --bg-elevated: #17171c;
  --bg-elevated-2: #1f1f26;
  --border: #2a2a32;
  --text: #ececf0;
  --text-dim: #8a8a96;
  --hint: #6a6a76;
  --accent: #ffd24a;
  --accent-dim: rgba(255, 210, 74, 0.15);
  --green: #7ec97e;
  --red: #e85c47;
  --blue: #5da9ff;
  --shadow-strong: rgba(0, 0, 0, 0.4);
  --map-region-bg: #2a2a32;
  --map-region-stroke: #1a1a20;

  --font-display: 'JetBrains Mono', ui-monospace, monospace;
  --font-body: 'Inter', -apple-system, system-ui, sans-serif;
}

[data-theme="light"] {
  /* СВІТЛА ТЕМА */
  --bg: #f6f6f8;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #ececf0;
  --border: #d8d8de;
  --text: #1a1a20;
  --text-dim: #6a6a76;
  --hint: #9a9aa6;
  --accent: #c89a00;            /* темніший жовтий для контрасту на світлому фоні */
  --accent-dim: rgba(200, 154, 0, 0.12);
  --green: #2e9c4e;
  --red: #d63838;
  --blue: #2070cc;
  --shadow-strong: rgba(0, 0, 0, 0.12);
  --map-region-bg: #d8d8de;
  --map-region-stroke: #b0b0b8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: 50px;
}

.hidden { display: none !important; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0; /* щоб довгі назви могли стискатися/переноситись */
}

.state-switcher {
  cursor: pointer;
  padding: 6px 10px;
  margin: -6px -10px;
  border-radius: 8px;
  transition: background 0.15s;
}
.state-switcher:hover {
  background: var(--bg-elevated);
}
.state-switcher:active {
  background: var(--bg-elevated-2);
}

.title-chevron {
  color: var(--accent);
  font-size: 9px;
  margin-left: -4px;
  opacity: 0.7;
  flex-shrink: 0;
}

.title-mark {
  color: var(--accent);
  font-size: 11px;
  animation: pulse 2.5s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.app-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--text);
  margin: 0;
  min-width: 0;
  flex: 0 1 auto;
  line-height: 1.15;
  /* Довга назва може займати до 2 рядків, далі — обріжемо з трьома крапками */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.icon-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover, .icon-btn:active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.icon-btn.spinning { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   TABS
   ============================================================ */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.2px;
}
.tab:active { transform: scale(0.97); }
.tab.active {
  background: var(--accent);
  color: #1a1a1f;
  border-color: var(--accent);
  font-weight: 600;
}

.range-bar {
  display: flex;
  gap: 4px;
  padding: 0 16px 12px;
}
.range {
  flex: 1;
  padding: 6px 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s;
}
.range.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Суб-вкладки (Доходи / Витрати в Budget) */
.subtab-bar {
  display: flex;
  gap: 4px;
  padding: 0 16px 12px;
}
.subtab {
  flex: 1;
  padding: 8px 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: all 0.15s;
}
.subtab:active { transform: scale(0.97); }
.subtab.active {
  background: var(--accent);
  color: #1a1a1f;
  border-color: var(--accent);
  font-weight: 600;
}

/* Блок витрат — компактний список з кольоровими числами як у грі */
.expense-block {
  grid-column: 1 / -1; /* на всю ширину */
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.expense-block::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent);
  opacity: 0.6;
}
.expense-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.expense-until {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.expense-value {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Бейдж кордонів у шапці */
.borders-badge {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 5px;
  margin-left: auto; /* притискає бейдж до правого краю всередині title-wrap */
  border: 1px solid;
  white-space: nowrap;
  flex-shrink: 0;
}
.borders-badge.open {
  color: var(--green);
  border-color: var(--green);
  background: rgba(126, 201, 126, 0.1);
}
.borders-badge.closed {
  color: var(--red);
  border-color: var(--red);
  background: rgba(232, 92, 71, 0.1);
}
.borders-badge.mid {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* ============================================================
   DEPARTMENT SELECTOR (custom dropdown)
   ============================================================ */
.dept-selector-wrap {
  padding: 0 16px 12px;
}

.dept-dropdown {
  position: relative;
  width: 100%;
}

.dept-trigger {
  width: 100%;
  height: 38px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 0 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  transition: border-color 0.15s;
}
.dept-trigger:hover, .dept-dropdown.open .dept-trigger {
  border-color: var(--accent);
}
.dept-trigger-arrow {
  color: var(--accent);
  font-size: 10px;
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: 8px;
}
.dept-dropdown.open .dept-trigger-arrow {
  transform: rotate(180deg);
}

.dept-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}
.dept-dropdown.open .dept-menu {
  display: block;
}

.dept-menu::-webkit-scrollbar { width: 6px; }
.dept-menu::-webkit-scrollbar-thumb { background: #3a3a44; border-radius: 3px; }

.dept-option {
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dept-option:hover {
  background: rgba(255, 255, 255, 0.06);
}
.dept-option.selected {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.dept-option.all-option {
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  padding-bottom: 11px;
}
.dept-option.all-option::before {
  content: '∑ ';
  color: var(--accent);
  font-weight: 700;
}

/* ============================================================
   STATES
   ============================================================ */
.loading, .error, .empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}
.loading { 
  font-family: var(--font-display); 
  letter-spacing: 1.5px; 
  font-size: 12px;
  animation: pulse-loading 1.5s ease-in-out infinite;
}
@keyframes pulse-loading {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}
.error { color: var(--red); font-family: var(--font-display); font-size: 12px; }
.empty-mark {
  font-size: 48px;
  color: var(--border);
  margin-bottom: 12px;
}
.empty .hint { font-size: 12px; color: var(--hint); margin-top: 6px; }

/* ============================================================
   KPI GRID
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 0 16px 16px;
}

.kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  animation: slideUpFade 0.4s ease-out both;
}
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
/* Stagger the animation for children if possible via inline styles, or just keep it simple */
.kpi:nth-child(1) { animation-delay: 0.05s; }
.kpi:nth-child(2) { animation-delay: 0.10s; }
.kpi:nth-child(3) { animation-delay: 0.15s; }
.kpi:nth-child(4) { animation-delay: 0.20s; }
.kpi:nth-child(5) { animation-delay: 0.25s; }
.kpi:nth-child(6) { animation-delay: 0.30s; }
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent);
  opacity: 0.6;
}
.kpi-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  font-family: var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}
.kpi-delta {
  font-family: var(--font-display);
  font-size: 11px;
  margin-top: 4px;
  letter-spacing: 0.3px;
}
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.flat { color: var(--text-dim); }

/* Картка-перемикач режиму для "Всі разом" */
.kpi.kpi-toggle {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi-toggle-buttons {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.mode-btn {
  flex: 1;
  height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0 4px;
  white-space: nowrap;
}
.mode-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}
.mode-btn.active {
  background: var(--accent);
  color: #1a1a1f;
  border-color: var(--accent);
  font-weight: 700;
}

/* ============================================================
   CHARTS
   ============================================================ */
.charts {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 8px;
  animation: slideUpFade 0.4s ease-out both;
  animation-delay: 0.1s;
}

.chart-card h3 {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  padding-left: 4px;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 10px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--hint);
  letter-spacing: 1px;
  text-align: center;
}

/* ============================================================
   STATE PICKER MODAL
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-panel {
  position: relative;
  width: calc(100% - 32px);
  max-width: 480px;
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px; /* slightly more rounded */
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes scaleUpFade {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text);
  text-transform: uppercase;
}
.modal-body {
  padding: 12px 16px 16px;
  overflow-y: auto;
}

.watched-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.watched-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.15s;
}
.watched-row:hover {
  border-color: var(--text-dim);
}
.watched-row.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.watched-row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  min-width: 0;
}
.watched-row-name {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watched-row.active .watched-row-name {
  color: var(--accent);
}
.watched-row-meta {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}
.watched-row-remove {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
}
.watched-row-remove:hover {
  color: var(--red);
  border-color: var(--red);
}

.watched-list-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 24px 12px;
  font-style: italic;
}

.add-state-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.add-state-input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  outline: none;
  -moz-appearance: textfield;
}
.add-state-input::-webkit-outer-spin-button,
.add-state-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.add-state-input:focus {
  border-color: var(--accent);
}
.add-state-btn {
  height: 38px;
  padding: 0 16px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #1a1a1f;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.add-state-btn:active { transform: scale(0.97); }
.add-state-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.add-state-hint {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  min-height: 14px;
}
.add-state-hint.error { color: var(--red); }
.add-state-hint.success { color: var(--green); }


/* ============================================================
   REGIONS MAP — повна карта світу з підсвіткою регіонів держави
   ============================================================ */
.regions-map {
  margin-top: 0;
  padding: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 200px;
}
.regions-map svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 450px;
}
.regions-map .map-loading {
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1px;
  padding: 80px 0;
}
.regions-map .map-note {
  margin-top: 8px;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.5px;
  line-height: 1.4;
}
.regions-map path[id^="jqvmap1_m"] {
  transition: fill 0.3s ease, stroke 0.15s, stroke-width 0.15s;
}
.regions-map path[data-value] {
  cursor: pointer;
}
.regions-map path[data-value]:hover,
.regions-map path[data-value]:active {
  stroke: #000000 !important;
  stroke-width: 1.8 !important;
}

/* ============================================================
   REGIONS LEGEND — горизонтальний градієнт red→yellow→green
   ============================================================ */
.regions-legend {
  margin-top: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--text);
}
.regions-legend .legend-label {
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 30px;
}
.regions-legend .legend-min { text-align: right; color: rgb(232, 60, 70); }
.regions-legend .legend-max { text-align: left; color: rgb(60, 220, 80); }
.regions-legend .legend-bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right,
    rgb(232, 60, 70) 0%,
    rgb(232, 200, 60) 50%,
    rgb(60, 220, 80) 100%);
}

/* ============================================================
   REGION DETAIL — панель з інфо про регіон при кліку на карту
   ============================================================ */
.region-detail {
  margin-top: 10px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: var(--font-body, 'Inter', sans-serif);
  color: var(--text);
}
.region-detail-loading,
.region-detail-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 0;
}
.region-detail-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.region-detail-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
  text-align: center;
  flex: 1;
}
.region-detail-close {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
}
.region-detail-close:hover { color: var(--text); background: var(--border); }
.region-detail-row {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  text-align: center;
}
.region-detail .rd-value { color: var(--text); font-weight: 600; }
.region-detail .rd-muted { color: var(--text-dim); font-style: italic; }
.region-detail-meta {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-align: center;
}

/* ============================================================
   REGION CONTROLS — рядок з dropdown метрики + квадратною кнопкою
   ============================================================ */
.region-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
}
.region-metric-dropdown {
  position: relative;
  flex: 1;
  min-width: 0;
}
.region-metric-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.region-metric-trigger:hover { border-color: var(--accent); }
.region-metric-dropdown.open .region-metric-trigger {
  border-color: var(--accent);
}
.region-metric-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.region-metric-caret {
  color: var(--text-dim);
  font-size: 10px;
  transition: transform 0.2s;
}
.region-metric-dropdown.open .region-metric-caret {
  transform: rotate(180deg);
}
.region-metric-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.region-metric-option {
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}
.region-metric-option:hover,
.region-metric-option:active {
  background: rgba(255, 210, 74, 0.1);
  color: var(--accent);
}
.region-view-toggle {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  transition: all 0.15s;
}
.region-view-toggle:active { transform: scale(0.95); }
.region-view-toggle:hover { background: var(--border); }

/* Герб регіону у панелі деталей */
.region-detail-emblem {
  text-align: center;
  margin-bottom: 12px;
}
.region-detail-emblem img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px;
}

/* Місячна врізка у правому верхньому куті основної карти.
   Квадратна — Місяць обрізається до квадрата з центру. */
.regions-map { position: relative; }
.regions-map .moon-inset {
  position: absolute;
  top: 0;
  right: 0;
  width: 18%;
  max-width: 95px;
  aspect-ratio: 1 / 1;
  background: rgba(15, 15, 18, 0.9);
  border: 1px solid var(--border);
  border-top: none;
  border-right: none;
  border-radius: 0 12px 0 8px;
  padding: 2px;
  box-sizing: border-box;
  pointer-events: auto;
  backdrop-filter: blur(2px);
  overflow: hidden;
}
.regions-map .moon-inset svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.regions-map .moon-inset path[data-value] {
  cursor: pointer;
}
.regions-map .moon-inset path[data-value]:hover,
.regions-map .moon-inset path[data-value]:active {
  stroke: #000000 !important;
  stroke-width: 1.8 !important;
}

/* ============================================================
   REGIONS LIST — таблиця регіонів топ-від-більшого-до-меншого
   ============================================================ */
.regions-list {
  margin: 0 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.regions-list-header {
  display: grid;
  grid-template-columns: 36px 1fr 100px;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.regions-list-header .rl-value { text-align: right; }
.regions-list-row {
  display: grid;
  grid-template-columns: 36px 1fr 100px;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.15s;
  align-items: center;
}
.regions-list-row:last-child { border-bottom: none; }
.regions-list-row:hover,
.regions-list-row:active {
  background: rgba(255, 210, 74, 0.06);
}
.regions-list .rl-rank {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.regions-list .rl-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.regions-list .rl-region-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.regions-list .rl-region-id {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}
.regions-list .rl-gov {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.regions-list .rl-muted { font-style: italic; }
.regions-list .rl-value {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-align: right;
}

/* Заглушка карти для не-українських держав */
.map-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 8px;
}
.map-placeholder-icon {
  font-size: 48px;
  opacity: 0.5;
  margin-bottom: 4px;
}
.map-placeholder-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 1px;
}
.map-placeholder-sub {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ============================================================
   ADMIN — іконка-шестерня в header (видима тільки адмінам)
   ============================================================ */
.admin-btn {
  margin-right: 4px;
}

/* ============================================================
   ADMIN MODAL — повноекранна модалка адмін-панелі
   ============================================================ */
.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.admin-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.admin-modal-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  background: var(--bg, #1a1a1f);
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  overflow: hidden;
}
.admin-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.admin-modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
}
.admin-modal-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
}
.admin-modal-close:hover { background: var(--border); }

.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.admin-tab {
  flex: 1;
  padding: 12px 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.admin-tab:hover { color: var(--text); }

.admin-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.admin-tab-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.admin-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-section-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 700;
}

.admin-add-row,
.admin-cleanup-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.admin-input {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
}
.admin-input:focus { outline: none; border-color: var(--accent); }

.admin-btn-primary,
.admin-btn-secondary,
.admin-btn-danger {
  padding: 8px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.admin-btn-primary {
  background: var(--accent);
  color: #1a1a1f;
}
.admin-btn-primary:hover { filter: brightness(1.1); }
.admin-btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
}
.admin-btn-secondary:hover { background: var(--border); }
.admin-btn-danger {
  background: rgba(232, 60, 70, 0.15);
  border-color: rgba(232, 60, 70, 0.5);
  color: rgb(232, 60, 70);
}
.admin-btn-danger:hover { background: rgba(232, 60, 70, 0.25); }
.admin-btn-small { padding: 4px 10px; font-size: 12px; }

.admin-hint {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-display);
  letter-spacing: 0.5px;
  min-height: 14px;
}

/* Список адмінів */
.admins-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 10px;
}
.admin-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.admin-row-meta {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-role {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.admin-role-owner {
  background: rgba(255, 210, 74, 0.15);
  color: var(--accent);
}
.admin-role-admin {
  background: rgba(110, 210, 110, 0.12);
  color: rgb(110, 210, 110);
}

/* Статистика */
.admin-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.admin-stat {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  gap: 3px;
}
.admin-stat span {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.admin-stat b {
  font-size: 14px;
  color: var(--text);
}

/* Заглушка для не-власників у адмін-панелі */
.admin-stub {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 10px;
}
.admin-stub-icon {
  font-size: 48px;
  opacity: 0.6;
}
.admin-stub-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.admin-stub-sub {
  font-size: 12px;
  color: var(--text-dim);
  max-width: 320px;
  line-height: 1.5;
}

/* Header модалки: actions справа (кнопка-перемикач + закрити) */
.admin-modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-view-toggle {
  background: rgba(255, 210, 74, 0.1);
  border: 1px solid rgba(255, 210, 74, 0.4);
  border-radius: 6px;
  color: var(--accent);
  padding: 6px 12px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.admin-view-toggle:hover { background: rgba(255, 210, 74, 0.2); }

/* Список відвідувачів */
.visitors-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 60vh;
  overflow-y: auto;
}
.visitor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 10px;
}
.visitor-row-info { flex: 1; min-width: 0; }
.visitor-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.visitor-row-meta {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  margin-top: 3px;
  display: flex;
  gap: 8px;
}
.visitor-row-id { color: var(--text-dim); }
.visitor-row-time {
  text-align: right;
  flex-shrink: 0;
}
.visitor-row-last {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.visitor-row-visits {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.5px;
}

/* ============================================================
   ADMIN MODAL BACKDROP AND PANEL
   ============================================================ */
.admin-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease-out;
}
.admin-modal-panel {
  position: relative;
  width: calc(100% - 32px);
  max-width: 600px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ============================================================
   SETTINGS — перемикач теми
   ============================================================ */
html, body {
  transition: background-color 0.2s, color 0.2s;
}
.theme-options {
  display: flex;
  gap: 6px;
}
.theme-option {
  flex: 1;
  padding: 10px 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.theme-option:active { transform: scale(0.97); }
.theme-option.active {
  background: var(--accent);
  color: #1a1a1f;
  border-color: var(--accent);
  font-weight: 600;
}

/* ============================================================
   LIGHT THEME — спеціальні правки для світлої теми де hard-coded
   ============================================================ */
[data-theme="light"] .icon-btn {
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .icon-btn:hover {
  background: var(--bg-elevated-2);
}
[data-theme="light"] .admin-modal-backdrop {
  background: rgba(255, 255, 255, 0.7);
}
[data-theme="light"] .regions-map .moon-inset {
  background: rgba(255, 255, 255, 0.92);
}
[data-theme="light"] .regions-list-row:hover,
[data-theme="light"] .regions-list-row:active {
  background: rgba(200, 154, 0, 0.08);
}
[data-theme="light"] .region-metric-option:hover,
[data-theme="light"] .region-metric-option:active {
  background: rgba(200, 154, 0, 0.12);
}
[data-theme="light"] .visitor-row-last {
  color: var(--accent);
}

/* ============================================================
   LIGHT THEME — додаткова поліровка
   ============================================================ */
[data-theme="light"] {
  /* Тіні і прозорості м'якіші у світлій темі */
}
[data-theme="light"] body {
  background: var(--bg);
  color: var(--text);
}
[data-theme="light"] .borders-badge {
  background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .borders-badge.open {
  background: rgba(46, 156, 78, 0.12);
  color: var(--green);
}
[data-theme="light"] .borders-badge.closed {
  background: rgba(214, 56, 56, 0.12);
  color: var(--red);
}
[data-theme="light"] .kpi-card {
  background: var(--bg-elevated);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .chart-card {
  background: var(--bg-elevated);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .icon-btn:hover,
[data-theme="light"] .add-state-btn:hover {
  background: var(--bg-elevated-2);
}
[data-theme="light"] .modal-backdrop,
[data-theme="light"] .admin-modal-backdrop {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
}
[data-theme="light"] .modal-panel,
[data-theme="light"] .admin-modal-panel {
  background: var(--bg);
}
[data-theme="light"] .admin-modal-header,
[data-theme="light"] .modal-header {
  background: var(--bg-elevated);
}
/* ============================================================
   WARS TAB — Tactical Intel Display
   ============================================================ */
@keyframes war-pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(232,92,71,0.55); }
  50%       { opacity: 0.75; box-shadow: 0 0 0 5px rgba(232,92,71,0); }
}
@keyframes war-card-breathe {
  0%, 100% { box-shadow: 0 0 0 1px rgba(232,92,71,0.18), 0 4px 22px rgba(232,92,71,0.06); }
  50%       { box-shadow: 0 0 0 1px rgba(232,92,71,0.38), 0 4px 26px rgba(232,92,71,0.15); }
}

.wars-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 4px 0 16px;
}
.wars-section-header {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--hint);
  padding: 12px 0 4px;
}
.wars-section-header:first-child { padding-top: 0; }

/* === Card === */
.war-card {
  background: var(--bg-elevated);
  background-image: radial-gradient(circle, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 18px 18px;
  border-radius: 10px;
  padding: 10px 12px 11px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}
.war-card-active {
  border-color: rgba(232, 92, 71, 0.38);
  animation: war-card-breathe 3s ease-in-out infinite;
}
.war-card-active::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: linear-gradient(180deg, #ff7060 0%, #e85c47 60%, #c94332 100%);
  border-radius: 10px 0 0 10px;
}
.war-card-active::after {
  content: '';
  position: absolute;
  bottom: -1px; left: -1px;
  width: 55%; height: 45%;
  background: radial-gradient(ellipse at 0% 100%, rgba(232,92,71,0.09) 0%, transparent 70%);
  pointer-events: none;
}
.war-card-past { opacity: 0.52; }

/* === Header: dot + badge · timer === */
.war-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 9px;
  margin-bottom: 9px;
  border-bottom: 1px solid var(--border);
}
.war-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}
.war-badge::before {
  content: '';
  display: block;
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.war-badge-active { color: #e85c47; }
.war-badge-active::before {
  background: #e85c47;
  animation: war-pulse-dot 1.6s ease-in-out infinite;
}
.war-badge-past { color: var(--hint); }
.war-badge-past::before { background: var(--hint); opacity: 0.4; }

.war-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.war-time-active { color: var(--yellow, #ffd24a); }
.war-time-past   { color: var(--hint); font-weight: 400; }

/* === Battle row: left | center | right === */
.war-battle {
  display: flex;
  align-items: center;
  gap: 5px;
}
.war-side-left,
.war-side-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.war-side-left  { text-align: right; }
.war-side-right { text-align: left; }
.war-side-main {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  line-height: 1.25;
}
.war-side-sub {
  font-size: 10px;
  font-weight: 400;
  color: var(--hint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  line-height: 1.2;
}
.war-side-dmg {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--hint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  line-height: 1.2;
  margin-top: 2px;
  opacity: 0.8;
}

/* === Center: framed score box === */
.war-center {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
}
.war-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--yellow, #ffd24a);
  white-space: nowrap;
  line-height: 1;
}
.war-card-past .war-score { color: var(--hint); }
.war-score-icon {
  font-size: 12px;
  color: #e85c47;
  line-height: 1;
}
.war-score-dur {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--hint);
  letter-spacing: 0.3px;
  line-height: 1;
  margin-top: 1px;
}

/* === Empty === */
.wars-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 40px 16px;
  text-align: center;
}
.wars-empty-icon {
  font-size: 32px;
  opacity: 0.25;
  line-height: 1;
  margin-bottom: 4px;
}
.wars-empty-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.wars-empty-hint {
  font-size: 12px;
  color: var(--hint);
  max-width: 220px;
  line-height: 1.4;
}

[data-theme="light"] .region-detail {
  background: var(--bg-elevated);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
