:root {
  --primary: #126c43;
  --primary-hover: #0d5634;
  --primary-strong: #083d25;
  --primary-soft: #e5f3eb;
  --accent: #25a469;
  --black: #101713;
  --bg: #f3f7f4;
  --surface: #ffffff;
  --surface-soft: #f8fbf9;
  --text: #17201b;
  --muted: #59675f;
  --border: #d7e3db;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #126c43;
  --warning: #8a4b08;
  --shadow-sm: 0 1px 2px rgba(16, 23, 19, .05);
  --shadow: 0 8px 24px rgba(16, 58, 38, .07), 0 1px 3px rgba(16, 23, 19, .06);
  --shadow-lg: 0 24px 60px rgba(8, 61, 37, .13);
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --focus: 0 0 0 3px rgba(18, 108, 67, .23);
  font-family: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); font-size: 16px; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 4%, rgba(37, 164, 105, .06), transparent 24rem),
    var(--bg);
  color: var(--text);
  font-family: inherit;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; }
button, a, summary, select, input[type="checkbox"], input[type="color"] { cursor: pointer; }
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }

.skip-link {
  position: fixed;
  top: -64px;
  right: 16px;
  z-index: 1000;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--black);
  color: #fff;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 1px solid rgba(18, 108, 67, .12);
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 3px 12px rgba(18, 108, 67, .12);
}
.brand-logo-large { width: 64px; height: 64px; flex-basis: 64px; }
.brand strong, .brand small { display: block; }
.brand strong { color: var(--black); font-size: 16px; font-weight: 800; }
.brand small { color: var(--muted); font-size: 12px; font-weight: 500; }

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}
.sidebar {
  position: sticky;
  top: 76px;
  height: calc(100vh - 76px);
  padding: 18px 12px;
  overflow-y: auto;
  background: var(--black);
  border-left: 1px solid rgba(255, 255, 255, .06);
}
.sidebar::before {
  content: "مدیریت تحریریه";
  display: block;
  padding: 4px 14px 12px;
  color: #95a69c;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}
.nav-item {
  position: relative;
  display: block;
  min-height: 46px;
  margin: 4px 0;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: #e7eee9;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: color .2s ease, background-color .2s ease, border-color .2s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active {
  background: var(--primary);
  border-color: rgba(255, 255, 255, .08);
  color: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
}
.nav-item.active::after {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  right: 6px;
  width: 3px;
  border-radius: 99px;
  background: #fff;
}

.content { width: 100%; max-width: 1600px; margin: 0 auto; padding: 28px; }
.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.page-heading h1 {
  margin: 0 0 4px;
  color: var(--black);
  font-size: clamp(24px, 2vw, 30px);
  font-weight: 800;
  line-height: 1.45;
}
.page-heading p, .muted { margin: 0; color: var(--muted); }
h2 { margin: 26px 0 12px; color: var(--black); font-size: 18px; font-weight: 800; }
h3 { margin: 0 0 12px; color: var(--black); font-size: 16px; font-weight: 800; }

.live-pill, .badge, .status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.live-pill { gap: 7px; background: var(--primary-soft); color: var(--primary-strong); }
.live-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(37, 164, 105, .12); }
.badge { background: var(--primary-soft); color: var(--primary-strong); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.comparison-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.kpi-card, .panel, .news-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 142px;
  padding: 18px;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
}
.kpi-card span { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi-card strong { margin-top: auto; color: var(--black); font-size: 29px; font-weight: 800; line-height: 1.25; }
.kpi-card small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.panel { padding: 18px; margin-bottom: 16px; }
.metric-list { margin: 0; }
.metric-list div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid #e8efeb; }
.metric-list div:first-child { border-top: 0; }
.metric-list dt { color: var(--muted); }
.metric-list dd { margin: 0; color: var(--black); font-weight: 800; }

.btn {
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 750;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, opacity .2s ease;
}
.btn:hover { box-shadow: 0 5px 16px rgba(16, 58, 38, .11); }
.btn:active { opacity: .88; }
.btn:focus-visible, .nav-item:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, .icon-button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--primary-strong); border-color: #7bb499; }
.btn-secondary:hover { background: var(--primary-soft); border-color: var(--primary); }
.btn-ghost { background: #fff; color: var(--black); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-soft); border-color: #b9c9bf; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #f4c7c2; }
.btn-danger:hover { background: #ffe4e1; border-color: #e8a8a1; }
.btn-small { min-height: 38px; padding: 6px 11px; font-size: 13px; }

.stack-form { display: grid; gap: 12px; }
.inline-form, .filter-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.stack-form label, .inline-form label, .filter-bar label, .editor-label {
  display: grid;
  gap: 6px;
  color: #253229;
  font-size: 13px;
  font-weight: 700;
}
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid #b9c9bf;
  border-radius: 9px;
  background: #fff;
  color: var(--black);
  caret-color: var(--primary);
  transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
input:hover, select:hover, textarea:hover { border-color: #84aa94; }
input::placeholder, textarea::placeholder { color: #7b8981; opacity: 1; }
textarea { resize: vertical; line-height: 1.9; }
input[type="color"] { width: 64px; padding: 4px; }

.filter-bar { margin-bottom: 14px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-sm); }
.filter-bar label:first-child { flex: 1 1 280px; }
.result-count { margin: 8px 2px 12px; color: var(--muted); font-size: 13px; }
.archive-list { display: grid; gap: 14px; }
.news-card { padding: 18px; border-right: 4px solid var(--primary); }
.news-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.news-card header > div { display: flex; align-items: center; gap: 8px; }
.news-text { max-width: 980px; white-space: pre-wrap; }
.news-card details { padding-top: 10px; border-top: 1px solid #e5ede8; }
.news-card summary { min-height: 40px; color: var(--primary); font-weight: 750; }
.inline-details { display: flex; gap: 24px; flex-wrap: wrap; }
.inline-details div { display: flex; gap: 7px; }
.inline-details dt { color: var(--muted); }
.inline-details dd { margin: 0; }

.status-pending, .status-new { background: #fff3d6; color: #704107; }
.status-approved, .status-edited_published { background: var(--primary-soft); color: var(--primary-strong); }
.status-rejected { background: #fee7e5; color: #861c13; }
.status-publishing { background: #e4f3ec; color: #0b5b37; }
.status-send_failed { background: #ffead8; color: #7a3109; }

.table-panel { padding: 0; overflow: hidden; }
.table-panel h2 { margin: 0; padding: 17px 18px; border-bottom: 1px solid var(--border); background: var(--surface-soft); }
.table-scroll { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 13px; border-bottom: 1px solid #e5ede8; text-align: right; white-space: nowrap; }
thead th { position: sticky; top: 0; z-index: 1; background: #eaf4ee; color: var(--primary-strong); font-weight: 800; }
tbody tr { transition: background-color .18s ease; }
tbody tr:hover { background: #f5faf7; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }

.config-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.config-grid > .panel { border-top: 3px solid var(--primary); }
.narrow-panel { max-width: 920px; }
.chip-list { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); font-size: 12px; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--chip-color); }
.chip form { display: inline; }
.icon-button { min-width: 34px; min-height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--danger); font-size: 21px; line-height: 1; }
.icon-button:hover { background: var(--danger-soft); }

.alert { margin: 12px 0; padding: 11px 13px; border: 1px solid #9dceb5; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-strong); }
.alert-danger { border-color: #f0b7b1; background: var(--danger-soft); color: #891d14; }
.alert-warning { border-color: #f0d29b; background: #fff8e8; color: #714207; }
.empty-state { padding: 44px 20px; border: 1px dashed #8cab99; border-radius: var(--radius); background: #fff; color: var(--muted); text-align: center; }

.login-page, .miniapp-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 22px;
  background: linear-gradient(135deg, rgba(18, 108, 67, .98), rgba(8, 61, 37, .98)), var(--primary);
}
.login-card, .miniapp-card {
  width: min(100%, 480px);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-lg);
}
.login-card::before { content: ""; display: block; width: 54px; height: 4px; margin: -8px auto 20px; border-radius: 99px; background: var(--primary); }
.login-card h1, .miniapp-card h1 { margin: 22px 0 4px; color: var(--black); font-size: 25px; }
.login-brand { justify-content: center; flex-direction: column; text-align: center; }
.login-brand strong { font-size: 18px; }
.miniapp-card { width: min(100%, 760px); }
.editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }

.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }
.result-count, .muted { font-size: 13px; }
.row-edit-form { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(140px, .8fr) auto auto; align-items: center; gap: 8px; min-width: 520px; }
.row-edit-form input, .row-edit-form select { min-height: 38px; padding: 6px 8px; }
.check-label { display: flex; align-items: center; gap: 6px; }
.check-label input { width: 19px; min-height: 19px; accent-color: var(--primary); }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .config-grid { grid-template-columns: 1fr 1fr; }
  .config-grid .panel:last-child { grid-column: 1 / -1; }
}

@media (max-width: 780px) {
  .topbar { height: 68px; padding: 0 12px; }
  .brand small { display: none; }
  .brand-logo { width: 40px; height: 40px; flex-basis: 40px; }
  .app-shell { display: block; min-height: calc(100vh - 68px); }
  .sidebar { position: sticky; top: 68px; z-index: 20; display: flex; gap: 4px; height: auto; padding: 7px; overflow-x: auto; border-left: 0; border-bottom: 1px solid rgba(255, 255, 255, .08); }
  .sidebar::before { display: none; }
  .nav-item { min-height: 42px; flex: 0 0 auto; margin: 0; padding: 8px 12px; white-space: nowrap; }
  .nav-item.active::after { top: auto; right: 12px; bottom: 3px; left: 12px; width: auto; height: 2px; }
  .content { padding: 18px 12px; }
  .kpi-grid, .comparison-grid, .config-grid { grid-template-columns: 1fr; }
  .config-grid .panel:last-child { grid-column: auto; }
  .page-heading { align-items: center; }
  .page-heading h1 { font-size: 23px; }
  .inline-form > * { flex: 1 1 180px; }
  .filter-bar .btn { width: 100%; }
  .news-card header { align-items: flex-start; flex-direction: column; }
  .topbar form .btn { min-height: 40px; padding: 7px 10px; }
}

@media (max-width: 420px) {
  .brand strong { font-size: 14px; }
  .content { padding: 14px 8px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .panel, .news-card, .kpi-card { border-radius: 11px; }
  .kpi-card { min-height: 126px; }
  .editor-footer { align-items: stretch; flex-direction: column; }
  .editor-footer .btn { width: 100%; }
  .login-card, .miniapp-card { padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
