/* ==========================================================================
   پاسخ‌یار — پنل مدیریت (راست‌به‌چپ)
   پالت: مه (زمینه)، بندر (متن/منو)، تالاب (اصلی)، هلوی تند (هشدار/خطا)
   عنصر شاخص: «نوار گفتگو» که هر قانون را مثل یک مکالمه‌ی کامنت ← دایرکت نشان می‌دهد.
   ========================================================================== */

:root {
    --fog: #edf1f4;
    --paper: #ffffff;
    --harbor: #17324d;
    --harbor-soft: #4b6178;
    --line: #d3dce3;
    --lagoon: #0e7c86;
    --lagoon-dark: #0a5f67;
    --lagoon-tint: #dcf1f2;
    --persimmon: #c2410c;
    --persimmon-tint: #fde8dc;
    --font: "Vazirmatn", Tahoma, system-ui, sans-serif;
    --rail: 232px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; min-height: 100vh; background: var(--fog); color: var(--harbor);
    font: 400 15px/1.8 var(--font); font-variant-numeric: tabular-nums;
}
h1, h2 { margin: 0; line-height: 1.4; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--lagoon-dark); }
code { font-family: ui-monospace, Menlo, monospace; font-size: .85em; background: var(--fog); padding: 1px 6px; border-radius: 6px; }
:focus-visible { outline: 3px solid var(--lagoon); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; }

/* ---------- قالب اصلی ---------- */
.main { padding: 20px 16px 96px; max-width: 980px; margin-inline: auto; }
.rail { display: none; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--harbor); color: #fff; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; }
.brand-mark { color: #7fd6dc; }
.account { font-size: .85rem; opacity: .8; direction: ltr; }

.tabbar {
    position: fixed; inset-inline: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: grid; justify-items: center; gap: 2px; padding: 8px 0; font-size: .75rem; color: var(--harbor-soft); text-decoration: none; }
.tabbar a[aria-current] { color: var(--lagoon-dark); font-weight: 700; }

@media (min-width: 900px) {
    body.has-shell { display: grid; grid-template-columns: var(--rail) 1fr; align-items: start; }
    .topbar, .tabbar { display: none; }
    .rail {
        display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh;
        padding: 24px 16px; background: var(--harbor); color: #fff;
    }
    .main { width: 100%; padding: 32px 40px 48px; }
}

.nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nav-link {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 10px;
    color: #cfdbe6; text-decoration: none; font: inherit; background: none; border: 0; cursor: pointer; text-align: start;
}
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-link[aria-current] { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 700; box-shadow: inset -3px 0 0 #7fd6dc; }
.rail-foot { margin-top: auto; display: grid; gap: 8px; }
.rail-foot .account { padding-inline: 12px; }

/* ---------- ورود/نصب ---------- */
.is-bare .main { max-width: 420px; padding-top: 12vh; }
.gate { display: grid; gap: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }

/* ---------- سرصفحه و بلوک‌ها ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.block { margin-top: 28px; padding: 20px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 14px; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; }
.block-head a { font-size: .9rem; }
.row { padding-block: 10px; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.empty { padding: 20px; color: var(--harbor-soft); background: var(--paper); border: 1px dashed var(--line); border-radius: 12px; }
.block .empty { border: 0; padding: 0; background: none; }
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 24px; }

/* ---------- نوار آمار (یک نوار، نه چهار کارت) ---------- */
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); background: var(--harbor); color: #fff; border-radius: 12px; overflow: hidden; }
.metrics > div { padding: 16px 20px; display: grid; gap: 2px; border-inline-start: 1px solid rgba(255, 255, 255, .14); border-block-end: 1px solid rgba(255, 255, 255, .14); }
.metrics b { font-size: 1.9rem; font-weight: 800; line-height: 1.2; }
.metrics span { font-size: .82rem; color: #b9c9d8; }
@media (min-width: 700px) {
    .metrics { grid-template-columns: repeat(4, 1fr); }
    .metrics > div { border-block-end: 0; }
}

/* ---------- نوار گفتگو ---------- */
.convo { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bubble { padding: 10px 16px; font-size: .95rem; min-width: 0; }
.bubble--in {
    flex: none; display: inline-flex; align-items: center; gap: 8px; max-width: 45%;
    background: var(--paper); border: 1.5px solid var(--harbor); border-radius: 18px; border-end-end-radius: 4px;
}
.bubble--in strong { font-size: 1.15rem; font-weight: 800; overflow-wrap: anywhere; }
.bubble--out {
    flex: 1; background: var(--lagoon); color: #fff; border-radius: 18px; border-end-start-radius: 4px;
    white-space: pre-line; overflow-wrap: anywhere;
}
.bubble--out p { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.convo-arrow { color: var(--harbor-soft); }
.chip { font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--lagoon-tint); color: var(--lagoon-dark); }
.chip--button { border: 0; cursor: pointer; font-family: inherit; padding: 3px 10px; }
.chip--button:hover { background: #c4e8ea; }

/* ---------- لیست قانون‌ها ---------- */
.rule { display: grid; gap: 12px; padding: 16px; margin-bottom: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.rule.is-off { opacity: .6; }
.rule-post { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--harbor-soft); }
.rule-actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.rule-count { margin-inline-end: auto; font-size: .85rem; color: var(--harbor-soft); }
@media (min-width: 900px) {
    .rule { grid-template-columns: 170px 1fr auto; align-items: center; gap: 20px; }
    .rule-post { flex-direction: column; align-items: flex-start; }
    .rule-actions { flex-direction: column; align-items: stretch; justify-content: center; }
}
.thumb { flex: none; width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: var(--line); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb--all { background: var(--lagoon-tint); color: var(--lagoon-dark); }
.thumb--lg { width: 88px; height: 88px; border-radius: 10px; }

/* ---------- دکمه‌ها ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px;
    border-radius: 10px; border: 1.5px solid transparent; font: 700 .92rem var(--font); cursor: pointer; text-decoration: none;
    transition: background-color .15s;
}
.btn--primary { background: var(--lagoon); color: #fff; }
.btn--primary:hover { background: var(--lagoon-dark); }
.btn--ghost { background: transparent; color: var(--harbor); border-color: var(--line); }
.btn--ghost:hover { background: var(--fog); }
.btn--sm { padding: 5px 12px; font-size: .82rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: none; color: var(--harbor); cursor: pointer; }
.icon-btn:hover { background: var(--fog); }
.icon-btn--danger:hover { background: var(--persimmon-tint); color: var(--persimmon); border-color: var(--persimmon); }

/* ---------- فرم‌ها ---------- */
.field { display: grid; gap: 6px; }
.field--narrow { max-width: 220px; }
.field-label { font-weight: 700; font-size: .9rem; }
.field-foot { display: flex; justify-content: space-between; align-items: center; }
.field-error { color: var(--persimmon); font-size: .85rem; font-weight: 500; }
.hint { font-size: .82rem; color: var(--harbor-soft); }
.counter { font-size: .8rem; color: var(--harbor-soft); }
input[type="text"], input[type="password"], input[type="number"], textarea {
    width: 100%; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper);
    color: var(--harbor); font: inherit;
}
input:focus, textarea:focus { border-color: var(--lagoon); outline: 0; box-shadow: 0 0 0 3px var(--lagoon-tint); }
textarea { resize: vertical; line-height: 1.8; }
input[readonly] { background: var(--fog); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; }

.group { border: 1px solid var(--line); border-radius: 12px; background: var(--paper); padding: 18px 20px 20px; display: grid; gap: 14px; margin: 0; min-width: 0; }
.group legend { padding-inline: 8px; font-weight: 800; }

/* انتخاب نوع تطبیق */
.seg { display: grid; gap: 8px; }
@media (min-width: 700px) { .seg { grid-template-columns: 1fr 1fr; } }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: grid; gap: 2px; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 10px; }
.seg small { color: var(--harbor-soft); font-size: .8rem; }
.seg input:checked + span { border-color: var(--lagoon); background: var(--lagoon-tint); }
.seg input:focus-visible + span { outline: 3px solid var(--lagoon); outline-offset: 2px; }

/* انتخاب پست */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.post-option { position: relative; cursor: pointer; }
.post-option > input[type="radio"] { position: absolute; opacity: 0; }
.post-card { display: grid; gap: 6px; justify-items: center; padding: 8px; border: 1.5px solid var(--line); border-radius: 10px; height: 100%; text-align: center; }
.post-card .thumb { width: 100%; height: 92px; }
.post-card-label { font-size: .75rem; line-height: 1.5; color: var(--harbor-soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-option > input:checked + .post-card { border-color: var(--lagoon); background: var(--lagoon-tint); box-shadow: 0 0 0 1.5px var(--lagoon); }
.post-option > input:focus-visible + .post-card { outline: 3px solid var(--lagoon); outline-offset: 2px; }

/* سوییچ */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch-track { position: relative; width: 42px; height: 24px; border-radius: 99px; background: #aab8c5; transition: background-color .2s; }
.switch-track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--lagoon); }
.switch input:checked + .switch-track::after { transform: translateX(-18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--lagoon); outline-offset: 2px; }

.save-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 20px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.save-bar .switch { margin-inline-end: auto; }

/* ویرایشگر: فرم + پیش‌نمایش */
.editor { display: grid; gap: 20px; }
.preview { display: grid; gap: 12px; align-content: start; padding: 18px 20px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.preview .convo { flex-direction: column; align-items: stretch; }
.preview .bubble--in { max-width: 100%; align-self: flex-start; }
.preview .convo-arrow { transform: rotate(-90deg); align-self: center; }
@media (min-width: 1100px) {
    .editor { grid-template-columns: 1fr 300px; align-items: start; }
    .preview { position: sticky; top: 24px; }
}

/* ---------- پیام‌ها و هشدارها ---------- */
.flash, .notice { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash--success { background: var(--lagoon-tint); color: var(--lagoon-dark); }
.flash--error { background: var(--persimmon-tint); color: var(--persimmon); }
.notice--warn { background: var(--persimmon-tint); color: #7c2d0a; }
.notice a { color: inherit; font-weight: 700; }

/* ---------- گزارش‌ها ---------- */
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-block: 10px; border-top: 1px solid var(--line); }
.feed li:first-child { border-top: 0; }
.feed-meta { display: inline-flex; align-items: center; gap: 10px; color: var(--harbor-soft); font-size: .85rem; }
.badge { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: var(--fog); color: var(--harbor-soft); }
.badge--sent { background: var(--lagoon-tint); color: var(--lagoon-dark); }
.badge--partial, .badge--failed { background: var(--persimmon-tint); color: var(--persimmon); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters a { padding: 4px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--paper); text-decoration: none; color: var(--harbor); font-size: .88rem; }
.filters a[aria-current] { background: var(--harbor); color: #fff; border-color: var(--harbor); }
.table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table th { text-align: start; padding: 10px 14px; font-size: .85rem; background: var(--fog); }
.table td { padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.log-error { margin-top: 4px; font-size: .8rem; color: var(--persimmon); max-width: 340px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 16px; }
@media (max-width: 699px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; }
    .table tr { padding: 10px 14px; border-top: 1px solid var(--line); }
    .table tr:first-child { border-top: 0; }
    .table td { border: 0; padding: 2px 0; }
    .table td::before { content: attr(data-label) ": "; color: var(--harbor-soft); font-size: .8rem; }
}

/* ---------- پست‌ها ---------- */
.post-list { display: grid; gap: 12px; }
.post-item { display: flex; gap: 14px; padding: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.post-item-body { display: grid; gap: 6px; align-content: start; min-width: 0; }
.post-item-title { font-weight: 700; overflow-wrap: anywhere; }
.post-item-meta { font-size: .82rem; color: var(--harbor-soft); }
.post-item-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.guide { padding: 14px 20px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.guide summary { cursor: pointer; font-weight: 700; }
.guide ol { margin: 10px 0 0; padding-inline-start: 22px; display: grid; gap: 6px; }

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