/* ═══════════════════════════════════════════════════════════
   خبرخوان زنده — Dark Editorial Theme
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:          #0a0a0f;
  --bg-2:        #0f0f16;
  --surface:     #13131c;
  --surface-2:   #1a1a25;
  --surface-hi:  #20202d;
  --border:      #24242f;
  --border-hi:   #333340;

  --text:        #e8e8ee;
  --text-dim:    #a0a0ad;
  --text-muted:  #6c6c7a;

  --accent:      #ef4444;
  --accent-2:    #f59e0b;
  --accent-live: #22c55e;

  --radius:      10px;
  --radius-sm:   6px;
  --gap:         12px;

  --font-main:   'Vazirmatn', 'Tahoma', sans-serif;
  --font-num:    'Vazirmatn', monospace;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-glow: 0 0 24px -6px var(--c, var(--accent));
}

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

html, body { min-height: 100%; }

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(239,68,68,.05), transparent 60%),
    radial-gradient(ellipse 60% 50% at 90% 110%, rgba(59,130,246,.04), transparent 60%),
    linear-gradient(var(--bg), var(--bg));
}

/* Persian numbers convert helper */
.fa-num { font-feature-settings: "ss01" on; }

/* ─── Scrollbars ─────────────────────────────────────────── */
.list { scrollbar-width: thin; scrollbar-color: var(--border-hi) transparent; }
.list::-webkit-scrollbar          { width: 6px; }
.list::-webkit-scrollbar-track    { background: transparent; }
.list::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 6px; }
.list::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ═══════════════════════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════════════════════ */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}
@media (min-width: 901px) {
  /* فقط روی دسکتاپ صفحه‌های ۱۰۰vh ثابت */
  html, body { height: 100%; overflow: hidden; }
  .app { height: 100vh; max-height: 100vh; }
}

/* ─── HEADER ─────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  z-index: 10;
  position: relative;
}
.header::after {
  content: '';
  position: absolute;
  inset: auto 0 -1px 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent) 50%, transparent);
  opacity: .4;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: inline-flex;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ef4444, #991b1b);
  box-shadow: 0 0 18px -4px rgba(239,68,68,.8), inset 0 0 6px rgba(0,0,0,.3);
  align-items: center; justify-content: center;
}
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #fff;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .4; transform: scale(.8); }
  50%      { opacity: 1;  transform: scale(1.2); }
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.5px;
  background: linear-gradient(180deg, #fff, #b5b5c0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sep { color: var(--text-muted); font-weight: 300; }
.brand-tag {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.header-meta {
  display: flex; align-items: center; gap: 14px;
}

.stat {
  display: flex; align-items: baseline; gap: 4px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
}
.stat-val { font-weight: 700; color: var(--text); font-family: var(--font-num); }
.stat-label { color: var(--text-muted); font-size: 10.5px; }

.datetime {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-num);
  padding: 4px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.clock-date {
  color: var(--text-dim);
  font-weight: 500;
}
.clock-time {
  color: var(--text);
  font-weight: 700;
  letter-spacing: .5px;
  padding-inline-start: 8px;
  border-inline-start: 1px solid var(--border-hi);
}

.clock {
  font-family: var(--font-num);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .5px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.status {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: all .3s;
}
.status-pip {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  box-shadow: 0 0 0 0 transparent;
}
.status[data-state="connecting"] .status-pip { background: #f59e0b; animation: blink 1s infinite; }
.status[data-state="live"]       .status-pip { background: var(--accent-live); box-shadow: 0 0 10px var(--accent-live); animation: live 2s ease-in-out infinite; }
.status[data-state="error"]      .status-pip { background: var(--accent); }
.status[data-state="live"] { color: #86efac; }
.status[data-state="error"] { color: #fca5a5; }

@keyframes blink { 50% { opacity: .3; } }
@keyframes live  {
  0%,100% { box-shadow: 0 0 0 0 var(--accent-live); }
  50%     { box-shadow: 0 0 14px 2px var(--accent-live); }
}

/* ─── GRID ──────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-areas:
    "lastread  latest   popular   economic  ads"
    "lastread  latest   popular   political ads"
    "multi     sports   cultural  intl      ads";
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
}
@media (min-width: 901px) {
  .grid { overflow: hidden; }
}

/* ─── BOX ───────────────────────────────────────────────── */
.box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
  transition: border-color .25s ease;
}
.box::before {
  /* top accent line */
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--c, var(--accent)) 50%, transparent);
  opacity: .5;
}
.box:hover { border-color: var(--border-hi); }
.box--hero {
  background:
    radial-gradient(ellipse at top, rgba(239,68,68,.06), transparent 60%),
    var(--surface);
}

.box-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  flex-shrink: 0;
}
.box-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px -1px var(--c);
  flex-shrink: 0;
  --c: var(--accent);
}
.box-dot[style*="--c"] { background: var(--c, currentColor); }

.box-title {
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -.2px;
  flex: 1;
}
.box-sub {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 500;
  padding: 2px 7px;
  background: var(--surface-hi);
  border-radius: 20px;
}

.badge-live {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700;
  color: #fecaca;
  padding: 3px 8px;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 20px;
  letter-spacing: .5px;
}
.badge-live-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: #ef4444;
  animation: pulse 1.4s ease-in-out infinite;
}

/* Box heading — hero variant slightly bolder */
.box--hero .box-title { font-size: 15px; }

/* Per-box accent — adjust top line color from dot */
.box[data-cat="latest"]        { --c: #ef4444; }
.box[data-cat="economic"]      { --c: #10b981; }
.box[data-cat="political"]     { --c: #3b82f6; }
.box[data-cat="cultural"]      { --c: #a855f7; }
.box[data-cat="international"] { --c: #06b6d4; }
.box[data-cat="multimedia"]    { --c: #ec4899; }
.box[data-cat="popular"]       { --c: #f59e0b; }
.box[data-cat="lastread"]      { --c: #94a3b8; }
.box[data-cat="ads"]           { --c: #64748b; }
.box[data-cat="sports"]        { --c: #f97316; }

/* ─── Search form in header ────────────────────────── */
.search-form {
  display: flex;
  flex: 1;
  max-width: 460px;
  margin: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color .15s;
}
.search-form:focus-within { border-color: var(--accent); }
.search-cat {
  background: var(--surface);
  border: none;
  border-inline-end: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0 10px;
  font-family: var(--font-main);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  max-width: 130px;
}
.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 8px 12px;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 13px;
  min-width: 0;
}
.search-input::placeholder { color: var(--text-muted); }
.search-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0 14px;
  cursor: pointer;
  border-inline-start: 1px solid var(--border);
  transition: background .15s, color .15s;
}
.search-btn:hover { color: var(--text); background: var(--surface-hi); }

.contact-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  color: var(--text-dim);
  text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  transition: all .15s;
}
.contact-link:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(239,68,68,.08);
}
.pause-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.pause-btn:hover { color: var(--text); border-color: var(--border-hi); }
.pause-btn.is-paused {
  color: #fbbf24;
  border-color: rgba(251,191,36,.4);
  background: rgba(251,191,36,.08);
}
.pause-badge {
  display: inline-block;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-num);
  border-radius: 8px;
  text-align: center;
  line-height: 16px;
  margin-inline-start: 2px;
}

.box-all {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  transition: all .15s;
  flex-shrink: 0;
}
.box-all:hover {
  color: var(--text);
  border-color: var(--c, var(--accent));
  background: var(--surface-hi);
  transform: rotate(-15deg);
}

/* ─── ADS column ────────────────────────────────────────── */
.box--ads { background: var(--bg-2); }
.ads-stack {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}
.ads-stack::-webkit-scrollbar          { width: 6px; }
.ads-stack::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 6px; }
.ads-stack:empty::before {
  content: 'فضای تبلیغات';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 80px;
  color: var(--text-muted);
  font-size: 11.5px;
  border: 1px dashed var(--border-hi);
  border-radius: var(--radius-sm);
}

.ad {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform .15s, border-color .15s, box-shadow .2s;
  position: relative;
}
.ad:hover {
  border-color: var(--border-hi);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(0,0,0,.5);
}
.ad-img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--surface);
}
.ad-text {
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
}
.ad-text-title {
  font-weight: 700;
  margin-bottom: 4px;
  color: #fff;
}
.ad-text-body {
  color: var(--text-dim);
  font-size: 11.5px;
}
.ad-cta {
  display: block;
  padding: 6px 12px;
  background: var(--surface-hi);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  border-top: 1px solid var(--border);
  text-align: center;
}
.ad-label {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-start: 4px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 9.5px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  letter-spacing: .3px;
  pointer-events: none;
  z-index: 1;
}

/* ─── LIST ──────────────────────────────────────────────── */
.list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 4px 0;
}

/* empty state */
.list:empty::before {
  content: attr(data-empty);
  display: block;
  text-align: center;
  color: var(--text-muted);
  padding: 24px 12px;
  font-size: 12px;
  font-style: normal;
}

.item {
  display: block;
  padding: 9px 12px;
  color: var(--text);
  text-decoration: none;
  position: relative;
  transition: background .15s ease;
  cursor: pointer;
}
/* لینک داخل آیتم — رفع خط آبی پیش‌فرض مرورگر */
.item-link,
.item-link:visited,
.item-link:hover,
.item-link:active {
  color: inherit;
  text-decoration: none;
  display: block;
  outline: none;
}
.item:hover {
  background: var(--surface-2);
}
.item:hover .item-title {
  color: #fff;
}
.item:active { background: var(--surface-hi); }

.item-title {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color .15s;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--text-muted);
}
.item-source {
  color: var(--text-dim);
  font-weight: 600;
  padding: 1px 6px;
  background: var(--surface-hi);
  border-radius: 4px;
  font-size: 10px;
}
.item-time { opacity: .75; }
.item-clicks {
  margin-inline-start: auto;
  color: var(--accent-2);
  font-weight: 700;
  font-size: 10px;
}
.item-clicks::before { content: '👁 '; filter: grayscale(.5); }

/* New item animation */
.item--new {
  animation: slideIn .45s cubic-bezier(.22, 1, .36, 1);
  background: linear-gradient(90deg, rgba(239,68,68,.06), transparent);
  transition: background 2s;
}
@keyframes slideIn {
  from { transform: translateY(-6px); opacity: 0; max-height: 0; }
  to   { transform: translateY(0);    opacity: 1; max-height: 100px; }
}

/* Ranked list (popular) */
.list--ranked .item {
  counter-increment: rank;
  padding-inline-start: 34px;
}
.list--ranked { counter-reset: rank; }
.list--ranked .item::before {
  content: counter(rank);
  position: absolute;
  inset-inline-start: 10px;
  top: 11px;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 50%;
  font-family: var(--font-num);
}
.list--ranked .item:nth-child(1)::before { color: #fff; background: linear-gradient(135deg, #f59e0b, #b45309); box-shadow: 0 0 10px -2px #f59e0b; }
.list--ranked .item:nth-child(2)::before { color: #fff; background: linear-gradient(135deg, #94a3b8, #475569); }
.list--ranked .item:nth-child(3)::before { color: #fff; background: linear-gradient(135deg, #b45309, #78350f); }

/* ─── FOOTER ─────────────────────────────────────────────── */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  gap: 12px;
}
.foot-left, .foot-right { display: flex; align-items: center; gap: 8px; }
.foot-sep { opacity: .4; }
.foot-pip {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent-live);
  animation: live 2s ease-in-out infinite;
  --accent-live: #22c55e;
  box-shadow: 0 0 6px var(--accent-live);
}

.dev-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  margin-inline-start: 3px;
  border-bottom: 1px dashed transparent;
  transition: border-color .15s, color .15s;
}
.dev-link:hover {
  color: #fff;
  border-bottom-color: var(--accent);
}

/* ─── TOASTS ─────────────────────────────────────────────── */
.toast-wrap {
  position: fixed;
  inset-block-end: 16px;
  inset-inline-start: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-inline-start: 3px solid var(--c, var(--accent));
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow-md);
  animation: toastIn .3s ease-out, toastOut .3s ease-in forwards 4s;
  max-width: 360px;
  pointer-events: auto;
}
.toast-cat { font-weight: 700; color: var(--c); margin-inline-end: 6px; }
@keyframes toastIn  { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { to   { transform: translateX(100%); opacity: 0; } }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */

/* Medium screens — 4 columns + ads at bottom */
@media (max-width: 1400px) {
  .grid {
    grid-template-columns: 1fr 1.3fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr auto;
    grid-template-areas:
      "lastread  latest   popular   economic"
      "lastread  latest   popular   political"
      "multi     sports   cultural  intl"
      "ads       ads      ads       ads";
  }
  .box--ads { display: flex; min-height: 140px; max-height: 200px; }
  .box--ads .ads-stack { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .box--ads .ad { min-width: 220px; flex-shrink: 0; }
}

/* Smaller — 3 columns */
@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr 1.5fr 1fr;
    grid-template-rows: repeat(4, 1fr);
    grid-template-areas:
      "lastread  latest    popular"
      "lastread  latest    popular"
      "economic  sports    political"
      "cultural  intl      multi";
  }
}

/* Small desktop — 2 columns */
@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "latest    latest"
      "lastread  popular"
      "sports    economic"
      "political cultural"
      "intl      multi"
      "ads       ads";
  }
  .box { min-height: 260px; max-height: 400px; }
  .box--hero { min-height: 380px; }
  .box--ads { display: flex; min-height: 200px; }
}

/* Mobile */
@media (max-width: 600px) {
  /* هدر و فوتر ثابت در موبایل */
  .header {
    position: sticky;
    top: 0;
    z-index: 100;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
  }
  .footer {
    position: sticky;
    bottom: 0;
    z-index: 100;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    text-align: center;
    font-size: 10.5px;
    padding: 8px 12px;
    background: var(--bg);
    border-top: 1px solid var(--border);
  }
  .header-meta { width: 100%; flex-wrap: wrap; gap: 6px; }
  .search-form { width: 100%; max-width: 100%; margin: 0; }
  .search-cat { max-width: 100px; font-size: 11px; }
  .search-input { font-size: 12px; padding: 7px 10px; }
  .stat, .clock, .datetime, .status, .contact-link { font-size: 11px; padding: 3px 8px; }
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "latest"
      "lastread"
      "popular"
      "sports"
      "economic"
      "political"
      "cultural"
      "intl"
      "multi"
      "ads";
    padding: 8px;
    gap: 8px;
  }
  .box { min-height: 240px; max-height: 360px; }
  .box--ads { min-height: 160px; }
  .brand-tag { display: none; }
  .toast-wrap { inset-inline: 12px; inset-block-end: 80px; }
  .toast { max-width: 100%; }
}
