:root {
  --bg: #0b0f14;
  --bg-panel: #141a22;
  --text: #ffb347;
  --accent: #ff8c42;
  --alert: #ff4d4f;
  --muted: #5b6b7d;
  --news-desc: #c2cdd8; /* description text — light grey, readable on dark bg */
  --border: #1f2630;
  --alert-city-bg: rgba(40, 51, 64, 0.9);
  --radius-lg: 14px;
  --radius-md: 10px;
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.55);
  --transition-fast: 150ms ease-out;
  --hud-height: 52px;
  --font-ui: "Rubik", "Assistant", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

.theme-light {
  --bg: #eef2f7;
  --bg-panel: #ffffff;
  --text: #1a2d45;
  --accent: #2563eb;
  --alert: #dc2626;
  --muted: #64748b;
  --news-desc: #1e3050; /* description text — dark navy, readable on light bg */
  --border: rgba(148, 186, 230, 0.45);
  --alert-city-bg: rgba(219, 234, 254, 0.85);
  --shadow-soft: 0 4px 20px rgba(30, 80, 180, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  direction: rtl;
}

.app-root {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hud {
  height: var(--hud-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  position: relative;
  z-index: 300;
}

body.theme-dark .hud {
  background: radial-gradient(circle at top right, #1a2533 0, #05070b 60%);
  border-bottom: 1px solid rgba(255, 140, 66, 0.6);
}

body.theme-light .hud {
  background: linear-gradient(90deg, #dbeafe, #eff6ff);
  border-bottom: 1px solid rgba(147, 197, 253, 0.7);
  box-shadow: 0 4px 12px rgba(30, 80, 180, 0.12);
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-clock {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.hud-status {
  color: var(--text);
}

.hud-last-alert {
  color: var(--muted);
}

.hud-separator {
  color: var(--border);
}

.hud-btn {
  background: transparent;
  border-radius: 999px;
  border: 1px solid rgba(90, 121, 149, 0.9);
  color: var(--text);
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition:
    background-color var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
}

.hud-btn:hover {
  background-color: rgba(58, 166, 255, 0.12);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.hud-btn:active {
  transform: translateY(0);
}

.hud-btn--danger {
  border-color: rgba(255, 77, 79, 0.5);
  color: rgba(255, 77, 79, 0.85);
}

.hud-btn--danger:hover {
  background-color: rgba(255, 77, 79, 0.12);
  border-color: var(--alert);
  color: var(--alert);
}

/* ── Sound toggle button ────────────────────────────────── */
.hud-sound-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 3px 6px;
  opacity: 0.45;
  transition:
    opacity var(--transition-fast),
    background-color var(--transition-fast),
    border-color var(--transition-fast);
  line-height: 1;
}

.hud-sound-btn:hover {
  opacity: 1;
  background-color: rgba(58, 166, 255, 0.12);
  border-color: rgba(90, 121, 149, 0.5);
}

.hud-sound-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.hud-sound-btn--muted {
  opacity: 0.3;
}

/* ── Hamburger menu ─────────────────────────────────────── */
.hud-menu-wrap {
  position: relative;
}

.hud-menu-btn {
  background: transparent;
  border: 1px solid rgba(90, 121, 149, 0.9);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 32px;
  height: 28px;
  padding: 0;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast);
}

.hud-menu-btn:hover {
  background-color: rgba(58, 166, 255, 0.12);
  border-color: var(--accent);
}

.hud-menu-bar {
  display: block;
  width: 14px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  transform-origin: center;
}

/* X state */
.hud-menu-btn--open .hud-menu-bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.hud-menu-btn--open .hud-menu-bar:nth-child(2) {
  opacity: 0;
}
.hud-menu-btn--open .hud-menu-bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.hud-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow-soft);
  z-index: 500;
  min-width: 180px;
}

.hud-menu--open {
  display: flex;
}

.hud-menu .hud-btn {
  width: 100%;
  justify-content: flex-start;
  border-radius: 6px;
  text-align: right;
}

.app-main {
  flex: 1;
  min-height: 0;
  padding: 12px 16px 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panels-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 0; /* gap handled by resize-handle width */
}

.panel-alerts {
  flex: 0 0 auto; /* width set dynamically by JS */
  width: 54%;
  min-width: 220px;
  min-height: 0;
}

.panel-news {
  flex: 1 1 0;
  min-width: 180px;
  min-height: 0;
}

/* ── Resize handle between the two panels ────────────────── */
.panels-resize-handle {
  flex: 0 0 14px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 10;
  user-select: none;
}

/* Visible divider line inside the handle */
.panels-resize-handle::after {
  content: "";
  display: block;
  width: 3px;
  height: 40px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.15s, height 0.15s;
}

.panels-resize-handle:hover::after,
.panels-resize-handle.dragging::after {
  background: var(--accent);
  height: 60px;
}

.panel {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

body.theme-dark .panel {
  background: linear-gradient(135deg, rgba(20, 26, 34, 0.96), rgba(9, 14, 21, 0.96));
  border: 1px solid rgba(31, 38, 48, 0.94);
}

body.theme-light .panel {
  background: #ffffff;
  border: 1px solid var(--border);
}

.panel-title {
  margin: 0;
  padding: 10px 14px 8px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.panel-title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  margin-left: 8px;
  background: radial-gradient(circle at 30% 30%, #7cf3ff 0, #3aa6ff 70%);
  box-shadow: 0 0 12px rgba(58, 166, 255, 0.8);
}

.panel-body {
  padding: 10px 14px 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── News split mode ─────────────────────────────────────── */
.panel-body.news-split {
  display: flex;
  flex-direction: row;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.news-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px 10px;
}

.news-col--rss {
  border-left: 1px solid var(--border);
}

.news-col-header {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  text-align: center;
}

.panel-placeholder {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.alert-calm-banner {
  margin: 0 0 6px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  background: rgba(58, 166, 255, 0.08);
  color: var(--muted);
  font-size: 0.8rem;
  border: 1px solid rgba(58, 166, 255, 0.15);
}

.alert-row {
  padding: 6px 4px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 4px;
  transition: background var(--transition-fast);
}

.alert-row:last-child {
  border-bottom: none;
}

.alert-row:hover {
  background: rgba(58, 166, 255, 0.06);
}

.alert-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.alert-row-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.78rem;
}

.alert-row-type {
  font-size: 0.85rem;
  color: var(--alert);
}

.alert-row-type--ended {
  color: #22c55e;
}

.alert-row--latest .alert-row-type {
  font-weight: 500;
}

.alert-row-time-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.alert-live-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 999px;
  background: #ff4d4f;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  animation: livePulse 1.4s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.alert-row-cities {
  font-size: 0.84rem;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.alert-city {
  padding: 2px 6px;
  border-radius: 999px;
  background-color: var(--alert-city-bg);
}

.alert-city-separator {
  color: var(--muted);
}

.alert-city-extra {
  color: var(--accent);
}

.news-item {
  padding: 6px 4px 8px;
  border-bottom: 1px solid var(--border);
}

.news-item:last-child {
  border-bottom: none;
}

.news-item-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.news-item-title {
  font-size: 0.88rem;
  color: var(--text);
  text-decoration: none;
}

.news-item-title:hover {
  text-decoration: underline;
}

.news-item-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.news-item-source {
  color: var(--accent);
}

.news-item-summary {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--news-desc);
  line-height: 1.5;
  /* Prevent injected HTML from breaking layout */
  overflow: hidden;
}

/* Contain images that arrive from RSS */
.news-item-summary img {
  max-width: 100%;
  max-height: 160px;
  width: auto;
  height: auto;
  display: block;
  margin: 4px 0;
  border-radius: var(--radius-md);
  object-fit: cover;
}

/* Telegram media (telesco.pe CDN) — small inline thumbnails/videos, multiple side-by-side */
.news-item-summary img.news-desc-tg-media,
.news-item-summary video.news-desc-tg-media {
  display: inline-block;
  width: 80px;
  height: 80px;
  max-width: 80px;
  max-height: 80px;
  object-fit: cover;
  border-radius: 6px;
  margin: 2px 2px 0 0;
  vertical-align: top;
  cursor: pointer;
}
.news-item-summary img.news-desc-tg-media:hover,
.news-item-summary video.news-desc-tg-media:hover {
  opacity: 0.85;
}

/* Links inside description */
.news-item-summary a {
  color: var(--accent);
  text-decoration: none;
}
.news-item-summary a:hover {
  text-decoration: underline;
}

/* Telegram channel attribution div */
.news-item-summary .tgme_widget_message_text {
  font-size: 0.78rem;
}

/* Trim extra whitespace from wrapping paragraphs */
.news-item-summary p:first-child,
.news-item-summary p:last-child {
  margin: 0;
}

/* Layout-thumbnail images (e.g. Walla brand image with align/hspace attrs) —
   these are decorative / corporate identity, not editorial photos, so hide them */
.news-item-summary img.news-desc-layout-thumb {
  display: none;
}

.alerts-timeline {
  flex-shrink: 0;
  padding: 6px 14px 8px;
  border-top: 1px solid var(--border);
}

.timeline-track {
  display: flex;
  align-items: stretch;
  gap: 3px;
  height: 52px;
  direction: ltr; /* oldest=left, newest=right regardless of page RTL */
}

.timeline-slot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.timeline-point {
  flex: 1;
  width: 100%;
  min-height: 0;
  border-radius: 999px;
  background: linear-gradient(to top, rgba(58, 166, 255, 0.4), transparent);
  opacity: 0.4;
  transform-origin: bottom;
  transition:
    transform var(--transition-fast),
    opacity var(--transition-fast),
    background-color var(--transition-fast);
}

.timeline-point--active {
  opacity: 1;
  background: linear-gradient(to top, rgba(255, 77, 79, 0.7), transparent);
}

.timeline-point--calm {
  opacity: 0.25;
}

.timeline-label {
  flex-shrink: 0;
  height: 10px;        /* fixed height — all slots identical, bars stay equal */
  font-size: 0.5rem;
  line-height: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  white-space: nowrap;
}

/* Map drawer */
.map-drawer {
  position: fixed;
  top: var(--hud-height);
  right: 0;
  bottom: 0;
  width: 380px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

body.theme-dark .map-drawer {
  background: linear-gradient(135deg, rgba(20, 26, 34, 0.98), rgba(9, 14, 21, 0.98));
}

body.theme-light .map-drawer {
  background: #ffffff;
}

.map-drawer--open {
  transform: translateX(0);
}

.map-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.map-drawer-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.map-drawer-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-md);
  line-height: 1;
}

.map-drawer-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* Alert info banner shown below the drawer header */
.map-drawer-alert-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 0.75rem;
  background: rgba(255, 77, 79, 0.12);
  border-bottom: 1px solid rgba(255, 77, 79, 0.25);
  min-height: 0;
}

.map-drawer-alert-info:empty {
  display: none;
}

.map-drawer-alert-info--ended {
  background: rgba(34, 197, 94, 0.1);
  border-bottom-color: rgba(34, 197, 94, 0.25);
}

.map-alert-info-type {
  font-weight: 600;
  color: var(--alert);
  flex: 1;
}

.map-drawer-alert-info--ended .map-alert-info-type {
  color: #22c55e;
}

.map-alert-info-count {
  color: var(--muted);
}

.map-alert-info-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* City chips list in the map drawer */
.map-drawer-cities {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 12px;
  max-height: 130px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}

.map-drawer-cities:empty {
  display: none;
}

.map-drawer-city-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  background: var(--alert-city-bg);
  color: var(--text);
  white-space: nowrap;
}

.map-root {
  flex: 1;
  width: 100%;
  min-height: 0;
}

.app-main,
.panel,
.hud {
  backdrop-filter: blur(22px);
}

.api-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.api-modal {
  background: var(--bg-panel);
  color: var(--text);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 16px 18px 14px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-soft);
}

.api-modal-title {
  margin: 0 0 6px;
  font-size: 1rem;
}

.api-modal-text {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.api-modal-text code {
  font-family: "Consolas", "Fira Code", monospace;
  direction: ltr;
}

.api-modal-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.api-modal-input {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-family: "Consolas", "Fira Code", monospace;
  font-size: 0.85rem;
}

.theme-light .api-modal-input {
  background: #fff;
}

.api-modal-error {
  min-height: 16px;
  font-size: 0.8rem;
  color: var(--alert);
  margin-bottom: 6px;
}

.api-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.text-filter-phrase-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  max-height: 220px;
  overflow-y: auto;
}

.text-filter-phrase-empty {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 4px 0;
}

.text-filter-phrase-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 0.82rem;
}

.theme-light .text-filter-phrase-item {
  background: rgba(0, 0, 0, 0.06);
}

.text-filter-phrase-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
}

.text-filter-phrase-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}

.text-filter-phrase-remove:hover {
  color: var(--alert);
}

.text-filter-add-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.text-filter-add-row .api-modal-input {
  flex: 1;
  font-family: inherit;
}

.panel--alert-pulse {
  animation: alertPulse 450ms ease-out;
}

@keyframes alertPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.7);
    border-color: rgba(255, 77, 79, 0.9);
  }
  60% {
    box-shadow: 0 0 0 14px rgba(255, 77, 79, 0);
    border-color: rgba(255, 77, 79, 0.4);
  }
  100% {
    box-shadow: var(--shadow-soft);
    border-color: rgba(31, 38, 48, 0.94);
  }
}

.alert-row-enter {
  animation: alertEnter 160ms ease-out;
}

@keyframes alertEnter {
  0% {
    opacity: 0;
    transform: translateY(-4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 920px) {
  html,
  body {
    overflow: auto;
  }

  .app-root {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .app-main {
    overflow: visible;
  }

  .panels-grid {
    flex-direction: column;
    height: auto;
  }

  .panel-alerts {
    min-height: 300px;
  }

  .panel-news {
    min-height: 300px;
  }

  .map-drawer {
    width: 100%;
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    height: 60vh;
    transform: translateY(100%);
  }

  .map-drawer--open {
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .hud {
    flex-direction: column;
    align-items: flex-start;
    padding: 6px 12px;
    gap: 4px;
    height: auto;
  }

  .hud-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .app-main {
    padding: 10px;
  }
}
