/* ==========================================================================
   دستیار خسرو — شیوه‌نامهٔ پنل مدیریت (RTL، بدون وابستگی خارجی)
   ========================================================================== */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #dfe3ea;
  --text: #1c2230;
  --muted: #6b7688;
  --primary: #1a6b4f;
  --primary-ink: #ffffff;
  --danger: #b3261e;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --ok: #12603f;
  --ok-bg: #e2f5ec;
  --info: #17436e;
  --info-bg: #e6effa;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 26, 38, .06), 0 6px 18px rgba(20, 26, 38, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a1f28;
    --surface-2: #212834;
    --border: #2e3746;
    --text: #e8ecf3;
    --muted: #9aa6b8;
    --primary: #37a37c;
    --primary-ink: #06231a;
    --danger: #ff8a80;
    --warn: #ffd479;
    --warn-bg: #3a2f12;
    --ok: #7fd8b0;
    --ok-bg: #10301f;
    --info: #9dc4ef;
    --info-bg: #14243a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, "IRANSans", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.85;
}

h1, h2, h3, h4 { line-height: 1.5; margin: 0 0 .6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; margin-top: 1.6rem; }
h4 { font-size: .95rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .82rem; }
.error { color: var(--danger); }
.skip { position: absolute; right: -9999px; }

/* ------------------------------------------------------------------ login */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.login-card { width: min(420px, 100%); display: grid; gap: .7rem; }
.login-card h1 { font-size: 1.4rem; margin: 0; }

/* ----------------------------------------------------------------- layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.logo {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
  font-size: 1.1rem;
}
.brand small { display: block; font-size: .76rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: .35rem;
  padding: .5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 57px;
  z-index: 15;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: .35rem .8rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--border); }

main { padding: 1rem; max-width: 1240px; margin: 0 auto; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ inputs */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .45rem .6rem;
  width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
label { display: grid; gap: .25rem; font-size: .88rem; color: var(--muted); }

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  padding: .45rem .85rem;
  cursor: pointer;
  transition: .15s;
}
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.tiny { padding: .15rem .45rem; font-size: .78rem; border-radius: 7px; }
button[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .5rem 0; }
form.inline input, form.inline select { width: auto; flex: 1 1 180px; }

.grid2 { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.two-col { display: grid; gap: 1.2rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.switch { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text); }
.switch input { width: auto; }

.filters { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin: .8rem 0; }
.filters input { max-width: 280px; }
.chip {
  border-radius: 999px;
  padding: .25rem .75rem;
  font-size: .85rem;
  background: var(--surface);
}
.chip.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 620px; }
th, td { padding: .55rem .7rem; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.actions-cell { white-space: nowrap; display: flex; gap: .25rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .76rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.badge.danger { background: #fde7e5; color: var(--danger); border-color: transparent; }
@media (prefers-color-scheme: dark) { .badge.danger { background: #3a1a18; } }

/* ------------------------------------------------------------------- stats */
.stats { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
}
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert b { color: var(--danger); }

.warnings { display: grid; gap: .5rem; }
.notice {
  background: var(--info-bg);
  color: var(--info);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin: .8rem 0;
  white-space: pre-wrap;
}
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem;
  overflow-x: auto;
  font-size: .82rem;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
}
ul.plain { list-style: none; padding: 0; margin: .4rem 0; display: grid; gap: .25rem; }
ul.plain li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .3rem .6rem; font-size: .88rem; }

.allowlist { display: grid; gap: .3rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.allowlist label { display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: .3rem .55rem; color: var(--text); }
.allowlist input { width: auto; }

/* ------------------------------------------------------------------- modal */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(620px, 94vw);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 12, 20, .55); }
.modal-body { padding: 1.2rem; display: grid; gap: .8rem; }
.modal-body menu { display: flex; gap: .5rem; justify-content: flex-start; margin: 0; padding: 0; }
.modal-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.modal-grid .full { grid-column: 1 / -1; }

.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}
.timeline { list-style: none; padding: 0; margin: .5rem 0; display: grid; gap: .35rem; }
.timeline li { border-inline-start: 3px solid var(--border); padding-inline-start: .6rem; font-size: .85rem; }
.timeline li b { font-weight: 600; }

.toast {
  position: fixed;
  inset-inline-start: 1rem;
  bottom: 1rem;
  background: var(--text);
  color: var(--bg);
  padding: .6rem 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 90vw;
}
.toast.bad { background: var(--danger); color: #fff; }

.row-actions { display: flex; gap: .3rem; flex-wrap: wrap; }
code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 6px; font-size: .85rem; direction: ltr; display: inline-block; }
