:root {
    --bg: #0f1117;
    --panel: #171a23;
    --panel-2: #1e222d;
    --line: #2a2f3d;
    --text: #e8eaf0;
    --muted: #939aab;
    --accent: #6c8cff;
    --green: #2ea36a;
    --red: #d9534f;
    --radius: 12px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f5f8;
        --panel: #ffffff;
        --panel-2: #f0f2f6;
        --line: #e2e5ec;
        --text: #1b1e26;
        --muted: #6d7488;
    }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-family: ui-monospace, Consolas, monospace; }
small { color: var(--muted); font-size: 12px; display: block; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---------- چیدمان ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a {
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--muted);
}
.topbar nav a:hover { background: var(--panel-2); text-decoration: none; }
.topbar nav a.on { background: var(--accent); color: #fff; }
.topbar .side { display: flex; align-items: center; gap: 12px; }

main { max-width: 1100px; margin: 0 auto; padding: 20px; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.stats { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) {
    .grid.two, .grid.stats { grid-template-columns: 1fr 1fr; }
}

.stat { text-align: center; }
.stat span { display: block; font-size: 30px; font-weight: 700; color: var(--accent); }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }

/* ---------- فرم ---------- */

label { display: block; margin-bottom: 14px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; margin: 0; }

input[type=text], input[type=password], input[type=number], input[type=file], textarea, select {
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; line-height: 1.9; }

.btn {
    display: inline-block;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }

form.inline { display: inline; }
.link-danger { background: none; border: 0; color: var(--red); cursor: pointer; font: inherit; padding: 0; }

/* ---------- جدول ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
table.kv th { width: 260px; }
.actions { display: flex; gap: 12px; align-items: center; }
.nowrap { white-space: nowrap; }

/* ---------- متفرقه ---------- */

.pill {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 12px;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    background: var(--panel-2);
    color: var(--muted);
}
.pill.green { background: var(--green); color: #fff; }
.pill.red   { background: var(--red);   color: #fff; }
.pill.gray  { background: var(--panel-2); color: var(--muted); }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert.ok  { background: rgba(46, 163, 106, .15); border: 1px solid var(--green); }
.alert.err { background: rgba(217, 83, 79, .15);  border: 1px solid var(--red); }

.ok    { color: var(--green); }
.err   { color: var(--red); }
.muted { color: var(--muted); }

.preview {
    background: var(--panel-2);
    padding: 16px;
    border-radius: 8px;
    white-space: pre-wrap;
    font-family: inherit;
    line-height: 2;
}

details pre { white-space: pre-wrap; word-break: break-all; font-size: 12px; color: var(--muted); }
tr.lvl-error td { background: rgba(217, 83, 79, .08); }

/* ---------- صفحه ورود ---------- */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; margin: 0; }
.auth-card h1 { font-size: 20px; margin: 0 0 18px; }
.auth-card .btn { width: 100%; }
