@import url('https://fonts.googleapis.com/css2?family=David+Libre:wght@400;700&family=Rubik:wght@400;500;600;700&display=swap');

/* ══════════════════════════════════════════════════════════
   NEWS MODE OVERLAY — full-screen overlay, RTL
   ══════════════════════════════════════════════════════════ */

#news-mode-overlay {
  position: fixed;
  inset: var(--hud-height, 52px) 0 0 0;
  background: var(--bg);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  direction: rtl;
  font-family: var(--font-ui, 'Rubik', 'Assistant', sans-serif);
  transition: opacity 250ms ease;
}

#news-mode-overlay.nm-visible {
  opacity: 1;
  pointer-events: all;
  animation: nmOverlayEnter 240ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes nmOverlayEnter {
  from { opacity: 0; transform: scale(0.994); }
  to   { opacity: 1; transform: scale(1); }
}

/* ══════════════════════════════════════════════════════════
   SHELL — outer CSS Grid
   ══════════════════════════════════════════════════════════ */

.nm-shell {
  display: grid;
  grid-template-columns: var(--nm-alerts-w, 310px) 14px 1fr;
  grid-template-rows: 1fr;
  height: 100%;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════
   ALERTS COLUMN (right side)
   ══════════════════════════════════════════════════════════ */

.nm-alerts-col {
  grid-column: 1;
  overflow-y: auto;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  min-width: 160px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nm-alerts-section {
  padding: 0;
}

.nm-alerts-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
}

.nm-alerts-section-body {
  display: flex;
  flex-direction: column;
  padding: 4px 8px;
  gap: 0;
}

.nm-alerts-empty,
.nm-alerts-calm {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 20px 12px;
}

.nm-alerts-calm {
  color: #22c55e;
}

/* Alert rows */
.nm-alert-row {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}

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

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

.nm-alert-type {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--alert);
  line-height: 1.2;
}

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

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

.nm-alert-time {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

/* Live badge */
.alert-live-badge {
  font-size: 0.62rem;
  font-weight: 700;
  background: var(--alert);
  color: #fff;
  padding: 1px 5px;
  border-radius: 99px;
  animation: livePulse 1.4s ease-in-out infinite;
  letter-spacing: 0.04em;
}

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

/* City chips */
.nm-alert-cities {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 4px;
  align-items: center;
}

.nm-alert-city {
  font-size: 0.74rem;
  background: var(--alert-city-bg, rgba(40,51,64,0.9));
  color: var(--news-desc);
  padding: 1px 7px;
  border-radius: 99px;
  white-space: nowrap;
}

.theme-light .nm-alert-city {
  background: var(--alert-city-bg, rgba(219,234,254,0.85));
  color: var(--text);
}

.nm-alert-city-sep {
  color: var(--border);
  font-size: 0.7rem;
  user-select: none;
}

.nm-alert-city-extra {
  font-size: 0.7rem;
  color: var(--muted);
  font-style: italic;
}

/* ══════════════════════════════════════════════════════════
   RESIZE HANDLE
   ══════════════════════════════════════════════════════════ */

.nm-resize-handle {
  grid-column: 2;
  width: 14px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex: 0 0 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nm-resize-handle::after {
  content: '';
  width: 3px;
  height: 40px;
  border-radius: 3px;
  background: var(--border);
  transition: background 150ms ease, height 150ms ease;
}

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

/* ══════════════════════════════════════════════════════════
   CONTENT AREA (masthead + stage)
   ══════════════════════════════════════════════════════════ */

.nm-content {
  grid-column: 3;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  min-width: 0;
}

/* ══════════════════════════════════════════════════════════
   MASTHEAD
   ══════════════════════════════════════════════════════════ */

.nm-masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  box-shadow: 0 1px 8px rgba(0,0,0,0.10);
  position: relative;
  z-index: 5;
  flex-wrap: wrap;
}

.theme-light .nm-masthead {
  box-shadow: 0 1px 8px rgba(30,80,180,0.07);
}

.nm-masthead-title {
  font-family: 'David Libre', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.nm-masthead-sources {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.nm-masthead-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
  border-radius: 99px;
  padding: 2px 10px;
  white-space: nowrap;
  letter-spacing: 0.03em;
}

/* ══════════════════════════════════════════════════════════
   STAGE (feed + sidebar in RTL: sidebar=right, feed=left)
   ══════════════════════════════════════════════════════════ */

.nm-stage {
  display: grid;
  grid-template-columns: 1fr clamp(260px, 18vw, 360px);
  overflow: hidden;
  min-width: 0;
}

/* ══════════════════════════════════════════════════════════
   FEED (main content area: grid of cards)
   ══════════════════════════════════════════════════════════ */

.nm-feed {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.nm-feed-body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(12px, 1.5vw, 24px);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  min-height: 0;
}

/* ══════════════════════════════════════════════════════════
   CARD GRID
   ══════════════════════════════════════════════════════════ */

.nm-grid {
  display: grid;
  /* --nm-card-scale set by JS (default 1); drives both column width and font size */
  grid-template-columns: repeat(auto-fill, minmax(max(140px, calc(190px * var(--nm-card-scale, 1))), 1fr));
  gap: clamp(10px, 1.2vw, 20px);
  align-content: start;
  font-size: calc(1rem * var(--nm-card-scale, 1));
}

/* ══════════════════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════════════════ */

.nm-card {
  background: color-mix(in srgb, var(--bg-panel) 85%, transparent);
  border: 1px solid color-mix(in srgb, var(--muted) 18%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.32), inset 0 1px 0 rgba(255,255,255,0.035);
  border-radius: var(--radius-lg, 14px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 160ms ease-out, box-shadow 160ms ease-out, border-color 160ms ease-out;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.theme-light .nm-card {
  background: #ffffff;
  border: 1px solid rgba(148, 186, 230, 0.5);
  box-shadow: 0 2px 12px rgba(30,80,180,0.07);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.nm-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.42);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.theme-light .nm-card:hover {
  box-shadow: 0 8px 24px rgba(30,80,180,0.13);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

/* Hero card — spans 2 columns */
.nm-card--hero {
  grid-column: span 2;
  flex-direction: row;
}

.nm-card--hero .nm-card-image {
  width: 45%;
  height: auto;
  min-height: 220px;
  flex-shrink: 0;
}

.nm-card--hero .nm-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nm-card--hero .nm-card-headline {
  font-size: 1.35em;
  -webkit-line-clamp: 4;
  line-clamp: 4;
}

/* Fresh card — subtle glow border */
.nm-card--fresh {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent) !important;
  animation: nmFreshGlow 2.8s ease-in-out infinite;
}

.theme-light .nm-card--fresh {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent) !important;
}

@keyframes nmFreshGlow {
  0%, 100% { box-shadow: 0 2px 12px rgba(0,0,0,0.32), 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
  50%       { box-shadow: 0 2px 12px rgba(0,0,0,0.32), 0 0 0 7px color-mix(in srgb, var(--accent) 18%, transparent); }
}

.theme-light .nm-card--fresh {
  animation: nmFreshGlowLight 2.8s ease-in-out infinite;
}

@keyframes nmFreshGlowLight {
  0%, 100% { box-shadow: 0 2px 12px rgba(30,80,180,0.07), 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
  50%       { box-shadow: 0 2px 12px rgba(30,80,180,0.07), 0 0 0 6px color-mix(in srgb, var(--accent) 20%, transparent); }
}

/* Entry animation */
.nm-card--entering {
  animation: nmFadeSlideUp 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: var(--enter-delay, 0ms);
}

@keyframes nmFadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Card image */
.nm-card-image {
  width: 100%;
  height: 150px;
  overflow: hidden;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--muted) 10%, transparent);
}

.nm-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 300ms ease;
}

.nm-card:hover .nm-card-image img {
  transform: scale(1.03);
}

/* Card body */
.nm-card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

/* Source row: chip + fresh dot + time */
.nm-card-source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.nm-card-source-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Source chip */
.nm-source-chip {
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 99px;
  padding: 2px 9px;
  white-space: nowrap;
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip-color, var(--accent)) 38%, transparent);
  color: var(--chip-color, var(--accent));
}

/* Per-channel colors */
.nm-source-chip[data-source="fekanewss"]      { --chip-color: #e0640a; }
.nm-source-chip[data-source="N12chat"]        { --chip-color: #0088cc; }
.nm-source-chip[data-source="beforeredalert"] { --chip-color: #cc1122; }

/* Fresh dot */
.nm-fresh-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: livePulse 1.4s ease-in-out infinite;
}

/* Card time */
.nm-card-time {
  font-size: 0.68em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  flex-shrink: 0;
}

/* Card headline */
.nm-card-headline {
  font-size: 0.95em;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  word-break: break-word;
}

.nm-card-headline a {
  color: inherit;
  text-decoration: none;
}

.nm-card-headline a:hover {
  color: var(--accent);
}

/* ══════════════════════════════════════════════════════════
   SIDEBAR — RSS Timeline
   ══════════════════════════════════════════════════════════ */

.nm-sidebar {
  background: color-mix(in srgb, var(--bg-panel) 60%, var(--bg) 40%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.theme-light .nm-sidebar {
  background: #f4f8ff;
  border-right: 1px solid rgba(148,186,230,0.45);
}

.nm-sidebar-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
  background: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.nm-sidebar-header-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.nm-sidebar-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  animation: livePulse 1.4s ease-in-out infinite;
}

/* Timeline scroll area */
.nm-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding: 12px 16px 12px 12px;
  position: relative;
}

/* Vertical timeline axis line (on the right in RTL) */
.nm-sidebar-scroll::before {
  content: '';
  position: absolute;
  right: 22px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    to bottom,
    var(--accent),
    color-mix(in srgb, var(--accent) 6%, transparent)
  );
  pointer-events: none;
}

.theme-light .nm-sidebar-scroll::before {
  background: linear-gradient(
    to bottom,
    var(--accent),
    color-mix(in srgb, var(--accent) 4%, transparent)
  );
}

/* Timeline item */
.nm-tl-item {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 0 10px;
  padding: 0 32px 16px 0;
  position: relative;
  text-decoration: none;
  color: inherit;
}

.nm-tl-item:last-child {
  padding-bottom: 4px;
}

/* Timeline dot (on the right in RTL) */
.nm-tl-dot {
  position: absolute;
  right: 17px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  flex-shrink: 0;
  z-index: 1;
  transition: transform 150ms ease;
}

.theme-light .nm-tl-dot {
  border-color: #f4f8ff;
}

.nm-tl-item--fresh .nm-tl-dot {
  background: #22c55e;
  animation: livePulse 1.4s ease-in-out infinite;
}

.nm-tl-item:hover .nm-tl-dot {
  transform: scale(1.3);
}

/* Time label */
.nm-tl-time {
  font-size: 0.65rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  white-space: nowrap;
  line-height: 1.6;
  grid-column: 1;
  grid-row: 1;
}

/* Source label */
.nm-tl-source {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  grid-column: 1;
  grid-row: 2;
}

/* Headline */
.nm-tl-title {
  font-size: 0.83rem;
  line-height: 1.45;
  color: var(--news-desc);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
}

.theme-light .nm-tl-title {
  color: var(--text);
}

.nm-tl-title a {
  color: inherit;
  text-decoration: none;
}

.nm-tl-title a:hover {
  color: var(--accent);
}

/* Entry animation for timeline items */
.nm-tl-item--entering {
  animation: nmFadeSlideRight 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: var(--enter-delay, 0ms);
}

@keyframes nmFadeSlideRight {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ══════════════════════════════════════════════════════════
   ZOOM CONTROL
   ══════════════════════════════════════════════════════════ */

.nm-feed-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 6px 14px 8px;
  gap: 4px;
}

.nm-zoom-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  background: color-mix(in srgb, var(--bg-panel) 75%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 120ms, color 120ms, border-color 120ms, opacity 120ms;
  user-select: none;
}

.nm-zoom-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-panel));
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.nm-zoom-btn:disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

.nm-zoom-label {
  font-size: 0.68rem;
  color: var(--muted);
  min-width: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* ══════════════════════════════════════════════════════════
   ALERT ROW — entry animation (news mode only)
   ══════════════════════════════════════════════════════════ */

@keyframes nmAlertRowEnter {
  from {
    opacity: 0;
    transform: translateY(-6px);
    background: color-mix(in srgb, var(--alert) 10%, transparent);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    background: transparent;
  }
}

.nm-alert-row--entering {
  animation: nmAlertRowEnter 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: var(--enter-delay, 0ms);
}

/* ── Column border-flash when new active alert arrives ── */

@keyframes nmAlertColPulse {
  0%   {
    border-left-color: var(--border);
    box-shadow: none;
  }
  18%  {
    border-left-color: var(--alert);
    box-shadow: inset -4px 0 16px color-mix(in srgb, var(--alert) 18%, transparent);
  }
  100% {
    border-left-color: var(--border);
    box-shadow: none;
  }
}

.nm-alerts-col--pulse {
  animation: nmAlertColPulse 950ms ease-out forwards;
}

/* ══════════════════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .nm-card--entering,
  .nm-tl-item--entering,
  .nm-alert-row--entering,
  .nm-alerts-col--pulse,
  #news-mode-overlay.nm-visible {
    animation: none !important;
  }
  .nm-card--fresh,
  .theme-light .nm-card--fresh {
    animation: none !important;
  }
  .nm-fresh-dot,
  .nm-sidebar-live-dot,
  .alert-live-badge,
  .nm-tl-item--fresh .nm-tl-dot {
    animation: none !important;
  }
}


/* ══════════════════════════════════════════════════════════
   RESPONSIVE — Tablet / Mobile
   ══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .nm-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 14px auto 1fr;
  }

  .nm-alerts-col {
    grid-column: 1;
    grid-row: 1;
    max-height: 38vh;
    border-left: none;
    border-bottom: 1px solid var(--border);
    width: 100% !important;
  }

  .nm-resize-handle {
    display: none;
  }

  .nm-content {
    grid-column: 1;
    grid-row: 3 / span 2;
  }

  .nm-stage {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .nm-sidebar {
    border-right: none;
    border-top: 1px solid var(--border);
    max-height: 40vh;
  }

  .nm-sidebar-scroll::before {
    display: none;
  }

  .nm-tl-item {
    padding-right: 0;
  }

  .nm-tl-dot {
    display: none;
  }

  .nm-card--hero {
    grid-column: span 1;
    flex-direction: column;
  }

  .nm-card--hero .nm-card-image {
    width: 100%;
    min-height: 160px;
  }
}

@media (min-width: 769px) and (max-width: 1100px) {
  .nm-stage {
    grid-template-columns: 1fr clamp(220px, 26vw, 300px);
  }
}
