/* ══════════════════════════════════════════
   مِداد v4 — Main Layout & Core Styles
══════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 16px; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font-body); cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }
input, textarea, select { font-family: var(--font-body); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 100px; }

/* ── Reading progress bar ── */
.read-progress {
  position: fixed; top: 0; right: 0; left: 0; z-index: 1000;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transform-origin: right;
  transform: scaleX(0);
  transition: transform .1s linear;
  pointer-events: none;
}
.read-progress.active { transform: scaleX(var(--progress, 0)); }

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; right: 0; left: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--sh1);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  padding: 0 var(--sp4);
  display: flex;
  align-items: center;
  gap: var(--sp3);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  transition: opacity var(--tr);
}
.brand:hover { opacity: .8; }
.brand svg { color: var(--accent); }

/* Nav search */
.nav-search {
  flex: 1;
  max-width: 440px;
  position: relative;
  margin: 0 var(--sp3);
}
.nav-search > svg {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}
.nav-search input {
  width: 100%;
  height: 36px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r5);
  padding: 0 34px 0 var(--sp4);
  font-size: .85rem;
  color: var(--text);
  transition: all var(--tr);
}
.nav-search input:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-f);
  outline: none;
}
.nav-search input::placeholder { color: var(--text4); }

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0; left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  box-shadow: var(--sh3);
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}
.search-results.show { display: block; }
.sr-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--tr);
  border-bottom: 1px solid var(--border);
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--bg2); }
.sr-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-l);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 600; color: var(--accent);
  flex-shrink: 0;
  overflow: hidden;
}
.sr-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sr-label { font-size: .82rem; }
.sr-sub { font-size: .74rem; color: var(--text3); }
.sr-section { padding: 6px 14px; font-size: .72rem; font-weight: 600; letter-spacing: 1px; color: var(--text4); text-transform: uppercase; background: var(--bg2); }

/* Nav actions */
.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--sp2);
  margin-right: auto;
  flex-shrink: 0;
}
.nav-btn {
  width: 34px; height: 34px;
  border-radius: var(--r2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: all var(--tr);
  position: relative;
}
.nav-btn:hover { background: var(--bg2); color: var(--text); }
.notif-badge {
  position: absolute;
  top: 3px; left: 3px;
  min-width: 16px; height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  border-radius: 100px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  display: none;
}
.notif-badge.show { display: flex; }

/* User avatar in nav */
.nav-avatar-wrap { position: relative; }
.nav-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-l);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 600; color: var(--accent);
  overflow: hidden;
  transition: border-color var(--tr);
}
.nav-avatar:hover { border-color: var(--accent); }
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Hamburger */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  border-radius: var(--r2);
}
.hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: var(--text2);
  border-radius: 2px;
  transition: all var(--tr2);
}
.hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* User dropdown */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  box-shadow: var(--sh3);
  z-index: 200;
  overflow: hidden;
  animation: dropIn 150ms ease;
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dd-header { padding: 14px 16px; background: var(--bg2); }
.dd-name { font-size: .88rem; font-weight: 600; color: var(--text); }
.dd-handle { font-size: .78rem; color: var(--text3); margin-top: 2px; direction: ltr; }
.dd-divider { height: 1px; background: var(--border); }
.dd-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  font-size: .84rem; color: var(--text2);
  cursor: pointer;
  transition: all var(--tr);
  width: 100%;
  text-align: right;
}
.dd-item:hover { background: var(--bg2); color: var(--text); }
.dd-signout { color: var(--danger); }
.dd-signout:hover { background: var(--danger-l); }

/* ── App Shell ── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--raside-w);
  grid-template-areas: "sidebar main raside";
  min-height: calc(100vh - var(--topbar-h));
  margin-top: var(--topbar-h);
  max-width: 1400px;
  margin-inline: auto;
  gap: 0;
}

/* ── Sidebar ── */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-inner { padding: var(--sp5) var(--sp3); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--sp5); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  font-size: .85rem; font-weight: 400;
  color: var(--text2);
  border-radius: var(--r2);
  transition: all var(--tr);
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active { background: var(--accent-l); color: var(--accent); font-weight: 500; }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

.sidebar-section-title {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text4);
  padding: 0 12px;
  margin-bottom: 8px;
}
.cat-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-stats {
  display: flex;
  gap: var(--sp3);
  padding: var(--sp4) var(--sp3);
  margin-top: var(--sp4);
  border-top: 1px solid var(--border);
}
.sidebar-stat {
  display: flex; flex-direction: column; align-items: center;
  flex: 1;
}
.sidebar-stat span { font-size: 1.1rem; font-weight: 600; color: var(--text); }
.sidebar-stat small { font-size: .72rem; color: var(--text4); }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 90;
  backdrop-filter: blur(2px);
}

/* ── Main Content ── */
.main-content {
  grid-area: main;
  min-width: 0;
  padding: var(--sp6) var(--sp5);
  border-left: 1px solid var(--border);
}
.page { animation: fadeIn 200ms ease; }
.page.hidden { display: none !important; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Right Aside ── */
.r-aside {
  grid-area: raside;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: var(--sp5) var(--sp4);
}
.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  overflow: hidden;
  margin-bottom: var(--sp4);
}
.widget-hdr {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.widget-body { padding: 12px 14px; }

/* ── Article Cards ── */
.feed-bar {
  display: flex; align-items: center; gap: var(--sp3);
  margin-bottom: var(--sp4);
  flex-wrap: wrap;
}
.feed-tabs {
  display: flex; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r5);
  padding: 3px;
  gap: 2px;
}
.feed-tab {
  padding: 5px 14px;
  border-radius: var(--r5);
  font-size: .78rem;
  font-weight: 500;
  color: var(--text3);
  transition: all var(--tr);
}
.feed-tab:hover { color: var(--text); }
.feed-tab.active { background: var(--accent); color: #fff; }
.feed-info { font-size: .78rem; color: var(--text4); margin-right: auto; }

/* Category filter chips */
.cat-filter-bar {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: var(--sp4);
}
.cft {
  padding: 4px 14px;
  border-radius: var(--r5);
  font-size: .77rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  transition: all var(--tr);
  white-space: nowrap;
}
.cft:hover { border-color: var(--border2); color: var(--text); }
.cft.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Search bar */
.search-bar-wrap { margin-bottom: var(--sp4); }
.search-box { position: relative; }
.search-box .s-icon {
  position: absolute; right: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text3); pointer-events: none; display: flex;
}
.search-box input {
  width: 100%; height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 0 36px 0 var(--sp4);
  font-size: .88rem; color: var(--text);
  transition: all var(--tr);
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-f); outline: none; }
.search-box input::placeholder { color: var(--text4); }
.s-clear {
  position: absolute; left: 8px; top: 50%;
  transform: translateY(-50%);
  color: var(--text3); font-size: .8rem;
  padding: 2px 5px; border-radius: var(--r1);
  display: none; transition: all var(--tr);
}
.s-clear:hover { color: var(--text); background: var(--bg2); }
.s-clear.show { display: block; }

/* Article card */
.a-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  overflow: hidden;
  margin-bottom: var(--sp4);
  transition: all var(--tr2);
  animation: cardIn 300ms ease both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.a-card:hover {
  border-color: var(--border2);
  box-shadow: var(--sh2);
  transform: translateY(-1px);
}
.a-card-img {
  width: 100%; height: 180px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--border);
}
.a-card-body { padding: var(--sp4); }

.a-meta {
  display: flex; align-items: center;
  gap: 8px; margin-bottom: 10px;
  flex-wrap: wrap;
}
.a-av {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-l);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600; color: var(--accent);
  overflow: hidden; flex-shrink: 0;
  cursor: pointer; transition: opacity var(--tr);
}
.a-av:hover { opacity: .8; }
.a-av img { width: 100%; height: 100%; object-fit: cover; }
.a-author {
  font-size: .82rem; font-weight: 500; color: var(--text2);
  cursor: pointer; display: flex; align-items: center; gap: 4px;
  transition: color var(--tr);
}
.a-author:hover { color: var(--accent); }
.a-time { font-size: .75rem; color: var(--text4); margin-right: auto; }
.a-cat {
  font-size: .72rem; font-weight: 600;
  color: var(--accent);
  background: var(--accent-l);
  padding: 2px 8px;
  border-radius: var(--r5);
}

/* Verified badge — premium */
.badge-verified {
  display: inline-flex;
  width: 15px; height: 15px;
  background: linear-gradient(135deg, var(--accent), #0a5a51);
  border-radius: 50%;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(13,112,100,.4);
}
.badge-verified svg { color: #fff; }

.a-title {
  display: block;
  font-size: 1rem; font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 6px;
  cursor: pointer;
  transition: color var(--tr);
}
.a-title:hover { color: var(--accent); }

.a-excerpt {
  font-size: .84rem; color: var(--text3);
  line-height: 1.6;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.a-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.tag-pill {
  font-size: .72rem; color: var(--text3);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r5);
  transition: all var(--tr);
}
.tag-pill:hover { background: var(--bg2); color: var(--text); border-color: var(--border2); }

.a-footer {
  display: flex; align-items: center; gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.a-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  border-radius: var(--r5);
  font-size: .78rem; color: var(--text3);
  border: 1px solid transparent;
  transition: all var(--tr);
}
.a-btn:hover { background: var(--bg2); color: var(--text); }
.a-btn.liked { color: #e64d6a; }
.a-btn.saved { color: var(--gold); }
.a-btn.featured { color: var(--gold); }
.a-btn-share { margin-right: auto; }

/* Featured badge */
.a-featured-badge { margin-bottom: 6px; }
.badge-featured {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .72rem; font-weight: 600;
  color: var(--gold);
  background: var(--gold-l);
  padding: 2px 8px;
  border-radius: var(--r5);
  border: 1px solid rgba(184,148,107,.3);
}

/* Search highlight */
mark.hl {
  background: #fef08a; color: #713f12;
  border-radius: 2px; padding: 0 1px; font-style: normal;
}
[data-theme="dark"] mark.hl { background: #713f12; color: #fef9c3; }

/* ── Skeleton loading ── */
.sk-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--sp4);
  margin-bottom: var(--sp4);
}
.sk {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--border) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  border-radius: var(--r1);
  animation: shimmer 1.5s infinite;
  height: 14px;
  margin-bottom: 8px;
}
.sk.lg { height: 18px; width: 70%; }
.sk.sm { height: 12px; width: 45%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: var(--sp8) var(--sp4);
  color: var(--text4);
}
.empty h3 { font-size: 1rem; color: var(--text3); margin-top: var(--sp3); }
.empty p { font-size: .85rem; margin-top: 6px; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: var(--sp5);
  left: var(--sp5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  box-shadow: var(--sh3);
  font-size: .85rem;
  color: var(--text);
  min-width: 220px;
  max-width: 340px;
  animation: toastIn 300ms cubic-bezier(.4,0,.2,1) both;
  pointer-events: all;
}
.toast.hide { animation: toastOut 250ms ease forwards; }
@keyframes toastIn { from { opacity:0; transform: translateX(-16px); } to { opacity:1; transform: translateX(0); } }
@keyframes toastOut { to { opacity:0; transform: translateX(-16px); } }
.toast.success .t-dot { background: var(--success); }
.toast.error   .t-dot { background: var(--danger); }
.toast.warn    .t-dot { background: var(--warn); }
.toast.info    .t-dot { background: var(--info); }
.t-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
