@font-face {
    font-family: "Vazirmatn";
    src: url("fonts/Vazirmatn-Variable.ttf") format("truetype");
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
}

/* ==========================================================================
   Nova License Console — v4 redesign
   Mobile-first-ish, RTL, light + dark, logical properties
   ========================================================================== */

:root {
    --bg: #f3f4f9;
    --surface: #ffffff;
    --surface-2: #f7f8fc;
    --surface-3: #eef0f7;
    --line: #e3e6ef;
    --line-strong: #d0d5e3;
    --text: #151a2d;
    --muted: #667087;
    --accent: #5a49ee;
    --accent-ink: #ffffff;
    --accent-soft: rgba(90, 73, 238, .10);
    --green: #0e9b72;
    --red: #d9364f;
    --orange: #c47510;
    --shadow-sm: 0 1px 2px rgba(21, 26, 45, .05);
    --shadow: 0 1px 2px rgba(21, 26, 45, .04), 0 10px 30px -12px rgba(21, 26, 45, .12);
    --shadow-lg: 0 20px 60px -20px rgba(21, 26, 45, .35);
    --radius: 16px;
    --radius-sm: 10px;
    --side-w: 270px;
    --rail-w: 78px;
    --ease: cubic-bezier(.2, .7, .2, 1);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0c0f16;
    --surface: #141924;
    --surface-2: #1a2030;
    --surface-3: #212839;
    --line: #262e41;
    --line-strong: #323c54;
    --text: #eceff8;
    --muted: #8e99b1;
    --accent: #8b7fff;
    --accent-ink: #0c0f16;
    --accent-soft: rgba(139, 127, 255, .14);
    --green: #35d3a1;
    --red: #ff6b82;
    --orange: #f2b04c;
    --shadow-sm: none;
    --shadow: 0 1px 0 rgba(255, 255, 255, .02) inset, 0 14px 40px -16px rgba(0, 0, 0, .6);
    --shadow-lg: 0 24px 70px -20px rgba(0, 0, 0, .8);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
    font-size: 14.5px;
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-wrap: break-word;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(60rem 28rem at 100% -10%, var(--accent-soft), transparent 70%),
        radial-gradient(40rem 24rem at 0% 110%, color-mix(in srgb, var(--green) 7%, transparent), transparent 70%);
    pointer-events: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

::selection { background: var(--accent-soft); }

.skip-link {
    position: fixed; top: 8px; inset-inline-start: 8px; z-index: 100;
    padding: 8px 14px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
    transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.ico { flex: none; display: block; }

/* ---------- Sidebar ---------------------------------------------------- */

.side {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 40;
    width: var(--side-w);
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px 14px 14px;
    background: var(--surface);
    border-inline-end: 1px solid var(--line);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: width .22s var(--ease), transform .26s var(--ease), box-shadow .26s;
}

.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px 16px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; color: var(--text); }
.brand:hover { text-decoration: none; }

.brand-mark {
    flex: none;
    display: grid; place-items: center;
    width: 40px; height: 40px;
    border-radius: 13px;
    background: linear-gradient(140deg, var(--accent), #a58bff 130%);
    color: #fff;
    font-size: 20px; font-weight: 800; line-height: 1;
    box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--accent) 65%, transparent);
}

.brand-copy { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-copy b { font-size: 17px; letter-spacing: -.2px; }
.brand-copy small { font-size: 10.5px; color: var(--muted); direction: ltr; text-align: start; letter-spacing: .4px; }

.icon-btn {
    flex: none;
    display: inline-grid; place-items: center;
    width: 38px; height: 38px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.side-close { display: none; }

.nav-caption { color: var(--muted); font-size: 11px; font-weight: 600; padding: 12px 12px 6px; letter-spacing: .3px; }

.nav { display: flex; flex-direction: column; gap: 3px; }

.nav a, .nav-btn {
    position: relative;
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 14px;
    text-align: start;
    cursor: pointer;
    transition: background .15s, color .15s;
    -webkit-tap-highlight-color: transparent;
}
.nav a:hover, .nav-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav a.active::before {
    content: ""; position: absolute; inset-inline-start: -14px; top: 10px; bottom: 10px; width: 4px;
    border-radius: 0 4px 4px 0; background: var(--accent);
}
[dir="rtl"] .nav a.active::before { border-radius: 4px 0 0 4px; }

.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 14px; }

.user { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.user-avatar { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.4; }
.user-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-meta small { color: var(--muted); font-size: 11px; }
.logout { margin-inline-start: auto; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--red); }
.logout:hover { background: color-mix(in srgb, var(--red) 12%, transparent); text-decoration: none; }
[dir="rtl"] .logout .ico { transform: scaleX(-1); }

.i-sun { display: inline-grid; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: inline-grid; }

.scrim { position: fixed; inset: 0; z-index: 35; background: rgba(8, 10, 18, .5); backdrop-filter: blur(2px); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }

/* ---------- Mobile top bar --------------------------------------------- */

.mobilebar {
    display: none;
    position: sticky; top: 0; z-index: 30;
    align-items: center; justify-content: space-between; gap: 8px;
    height: 56px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
}
.mobilebar .icon-btn { color: var(--text); }
.mobilebar-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Shell / content ------------------------------------------- */

.shell { margin-inline-start: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin .22s var(--ease); }

.wrap { flex: 1; width: 100%; max-width: 1400px; margin-inline: auto; padding: 40px clamp(16px, 3.4vw, 48px) 48px; }

.foot { padding: 18px 24px calc(18px + env(safe-area-inset-bottom)); text-align: center; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }

h1 { font-size: clamp(22px, 2.4vw, 29px); font-weight: 800; letter-spacing: -.5px; line-height: 1.4; margin: 0 0 22px; }
h2 { font-size: 16px; font-weight: 700; margin: 26px 0 12px; line-height: 1.5; }
.box h2:first-child { margin-top: 0; }
p { margin: 0 0 12px; }

/* ---------- Stat cards ------------------------------------------------- */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }

.card {
    position: relative;
    display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
    min-height: 116px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform .2s var(--ease), border-color .2s;
}
.card::before { content: ""; position: absolute; inset-inline-start: 0; top: 18px; width: 3px; height: 26px; border-radius: 0 3px 3px 0; background: var(--accent); opacity: .85; }
[dir="rtl"] .card::before { border-radius: 3px 0 0 3px; }
.card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.card .num { font-size: clamp(24px, 2.6vw, 30px); font-weight: 800; line-height: 1.2; letter-spacing: -.5px; font-variant-numeric: tabular-nums; order: 2; }
.card .lbl { color: var(--muted); font-size: 13px; order: 1; }

/* ---------- Boxes ------------------------------------------------------ */

.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(16px, 2.2vw, 24px); margin-bottom: 18px; box-shadow: var(--shadow); min-width: 0; }
.box > p.muted:first-child { margin-top: 0; }

/* ---------- Tables ----------------------------------------------------- */

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-block: 0; }
.table-wrap:focus-visible { outline-offset: -2px; }

table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: var(--surface-2); white-space: nowrap; }
tr:first-child > th:first-child { border-start-start-radius: 10px; }
tr:first-child > th:last-child { border-start-end-radius: 10px; }
tr:last-child > td { border-bottom: 0; }
tbody tr:hover > td, table > tr:not(:first-child):hover > td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
td .muted + .muted { margin-inline-start: 4px; }

/* key/value tables (dashboard, settings) */
table.kv th { background: transparent; width: 1%; font-family: Consolas, ui-monospace, monospace; direction: ltr; text-align: start; font-size: 12.5px; padding-inline-end: 24px; }
table.kv tr:first-child > th:first-child,
table.kv tr:first-child > th:last-child { border-radius: 0; }

/* ---------- Forms ------------------------------------------------------ */

label { display: block; color: var(--muted); font-size: 13px; font-weight: 500; margin: 0 0 6px; }

input, select, textarea {
    display: block;
    width: 100%;
    min-height: 42px;
    padding: 9px 13px;
    margin-bottom: 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 11px;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
input:disabled { opacity: .6; cursor: not-allowed; }
select { appearance: none; -webkit-appearance: none; padding-inline-end: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238e99b1' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 13px center; }
select[multiple] { min-height: 160px; background-image: none; padding-inline-end: 13px; }
input[type=file] { padding: 7px 10px; }
input[type=file]::file-selector-button { margin-inline-end: 10px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 12.5px; cursor: pointer; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 18px; height: 18px; min-height: 0; padding: 0; margin: 0; vertical-align: middle; accent-color: var(--accent); cursor: pointer; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 0 18px; margin-bottom: 4px; }

/* ---------- Buttons ---------------------------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px;
    padding: 0 18px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 11px;
    color: var(--text);
    font: inherit;
    font-size: 13.5px; font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s, transform .12s, box-shadow .15s;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); color: var(--accent-ink); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, var(--line)); }
.btn.danger:hover { background: color-mix(in srgb, var(--red) 10%, transparent); border-color: var(--red); color: var(--red); }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn.lg { min-height: 48px; font-size: 15px; width: 100%; }

.inline { display: inline-block; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar > * { margin-bottom: 0; }
.toolbar input, .toolbar select { width: auto; min-width: 170px; flex: 1 1 170px; max-width: 360px; margin-bottom: 0; }
.toolbar input[type=checkbox] { flex: none; min-width: 0; }
.toolbar input[type=number] { flex: 0 0 auto; min-width: 0; }
.toolbar label { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--text); }
.toolbar > form.toolbar { margin-bottom: 0; }
.filter-bar { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.filter-bar input[type=text] { flex: 2 1 240px; max-width: 420px; }

/* ---------- Badges / chips / alerts ----------------------------------- */

.badge { display: inline-block; max-width: 100%; padding: 1px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.9; text-align: start; overflow-wrap: anywhere; background: var(--surface-3); color: var(--muted); }
.badge.on { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.badge.off { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.badge.exp { background: color-mix(in srgb, var(--orange) 15%, transparent); color: var(--orange); }
.badge.on, .badge.core, .badge.soft { white-space: nowrap; }
.badge.core { background: var(--accent-soft); color: var(--accent); }
.badge.soft { background: var(--surface-3); color: var(--muted); }

.alert { display: flex; gap: 10px; padding: 12px 16px; margin-bottom: 16px; border-radius: 12px; border: 1px solid transparent; border-inline-start-width: 4px; font-size: 13.5px; line-height: 1.8; }
.alert.success { background: color-mix(in srgb, var(--green) 11%, var(--surface)); color: var(--green); border-color: color-mix(in srgb, var(--green) 28%, transparent); }
.alert.error { background: color-mix(in srgb, var(--red) 9%, var(--surface)); color: var(--red); border-color: color-mix(in srgb, var(--red) 28%, transparent); }
.alert.info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }

.key { display: inline-block; max-width: 100%; direction: ltr; unicode-bidi: embed; padding: 2px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-family: Consolas, "SF Mono", ui-monospace, monospace; font-size: 12.5px; line-height: 1.7; overflow-wrap: anywhere; word-break: break-all; vertical-align: middle; }

.muted { color: var(--muted); }
.empty-row { padding: 32px 0; text-align: center; }

/* ---------- Category tabs ---------------------------------------------- */

.cat-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.cat-tabs .cat { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; white-space: nowrap; transition: .15s; }
.cat-tabs .cat:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.cat-tabs .cat.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.cat-tabs .cat i { font-style: normal; font-size: 11px; min-width: 22px; padding: 0 7px; border-radius: 999px; background: color-mix(in srgb, currentColor 14%, transparent); text-align: center; line-height: 1.7; }

/* ---------- License groups, issue box, bulk bar ----------------------- */

.lic-group { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; background: var(--surface); }
.lic-group > summary { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 16px; background: var(--surface-2); cursor: pointer; list-style: none; user-select: none; }
.lic-group > summary::-webkit-details-marker { display: none; }
.lic-group > summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translate(-2px,-2px); transition: transform .18s; margin-inline-end: 4px; flex: none; }
.lic-group:not([open]) > summary::before { transform: rotate(135deg) translate(-2px,-2px); }
.lic-group > summary:hover { background: var(--surface-3); }
.lic-group .g-title { font-weight: 700; }
.lic-group .g-sub { color: var(--muted); font-size: 12px; font-family: Consolas, ui-monospace, monospace; overflow-wrap: anywhere; }
.lic-group .g-badges { margin-inline-start: auto; display: flex; flex-wrap: wrap; gap: 6px; }
.lic-group table th:first-child, .lic-group table td:first-child { padding-inline-end: 6px; width: 1%; }
.lic-group th { border-radius: 0 !important; }

.issue-box { padding: 0; }
.issue-box > summary { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding: 16px 20px; cursor: pointer; list-style: none; user-select: none; }
.issue-box > summary::-webkit-details-marker { display: none; }
.issue-box > summary::before { content: "+"; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 18px; font-weight: 700; line-height: 1; }
.issue-box[open] > summary::before { content: "−"; }
.issue-box > summary b { font-size: 16px; }
.issue-box .issue-body { padding: 4px 20px 20px; }

.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 16px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; }
.bulk-bar input { width: 100px; min-width: 0; margin-bottom: 0; }

/* ---------- Login ------------------------------------------------------ */

.auth-body::before { display: none; }
.auth-body { background: var(--bg); }
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-aside { position: relative; display: flex; align-items: center; padding: clamp(32px, 6vw, 80px); color: #fff; background: radial-gradient(40rem 30rem at 0% 0%, rgba(255,255,255,.18), transparent 60%), linear-gradient(150deg, #4636d6 0%, #6a4df0 55%, #9a76ff 120%); overflow: hidden; }
.auth-aside::after { content: ""; position: absolute; width: 36rem; height: 36rem; inset-inline-end: -14rem; bottom: -16rem; border-radius: 50%; border: 1px solid rgba(255,255,255,.22); box-shadow: 0 0 0 4rem rgba(255,255,255,.05), 0 0 0 9rem rgba(255,255,255,.04); }
.auth-aside-inner { position: relative; z-index: 1; max-width: 440px; }
.auth-aside .brand-mark { width: 52px; height: 52px; font-size: 26px; background: rgba(255,255,255,.2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }
.auth-aside h2 { font-size: clamp(24px, 2.8vw, 34px); line-height: 1.5; margin: 24px 0 10px; font-weight: 800; }
.auth-aside p { color: rgba(255,255,255,.82); font-size: 15px; }
.auth-aside ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }
.auth-aside li { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.92); }
.auth-aside li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; opacity: .85; }
.auth-main { display: grid; place-items: center; padding: 28px 16px; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.auth-card { width: min(420px, 100%); padding: clamp(24px, 4vw, 38px); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-lg); }
.auth-logo { display: none; margin-bottom: 14px; }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-sub { color: var(--muted); margin-bottom: 22px; }
.auth-card .btn { margin-top: 6px; }
.auth-card input { font-size: 16px; min-height: 46px; }

/* ---------- Rail (collapsed) sidebar ---------------------------------- */
/* generated: desktop-collapsed + tablet-closed share these rules */
@media (min-width: 1200px) {
    html[data-nav="collapsed"] .side { width: var(--rail-w); padding-inline: 12px; overflow-x: hidden; }
    html[data-nav="collapsed"] .t { display: none; }
    html[data-nav="collapsed"] .side-head { flex-direction: column; justify-content: center; padding-inline: 0; gap: 10px; }
    html[data-nav="collapsed"] .nav a, html[data-nav="collapsed"] .nav-btn { justify-content: center; padding: 0; }
    html[data-nav="collapsed"] .nav a.active::before { inset-inline-start: -12px; }
    html[data-nav="collapsed"] .user { flex-direction: column; padding: 8px 4px; gap: 4px; }
    html[data-nav="collapsed"] .logout { margin: 0; }
    html[data-nav="collapsed"] .side-collapse .ico { transform: scaleX(-1); }
}
@media (min-width: 861px) and (max-width: 1199px) {
    html:not([data-open]) .side { width: var(--rail-w); padding-inline: 12px; overflow-x: hidden; }
    html:not([data-open]) .t { display: none; }
    html:not([data-open]) .side-head { flex-direction: column; justify-content: center; padding-inline: 0; gap: 10px; }
    html:not([data-open]) .nav a, html:not([data-open]) .nav-btn { justify-content: center; padding: 0; }
    html:not([data-open]) .nav a.active::before { inset-inline-start: -12px; }
    html:not([data-open]) .user { flex-direction: column; padding: 8px 4px; gap: 4px; }
    html:not([data-open]) .logout { margin: 0; }
    html:not([data-open]) .side-collapse .ico { transform: scaleX(-1); }
}


/* ---------- Layout breakpoints ---------------------------------------- */

/* tablet: persistent rail, full menu as overlay */
@media (min-width: 861px) and (max-width: 1199px) {
    :root { --side-w: var(--rail-w); }
    html[data-open] .side { width: 270px; box-shadow: var(--shadow-lg); }
    html[data-open] .scrim { opacity: 1; visibility: visible; }
    html[data-open] .nav a.active::before { inset-inline-start: -14px; }
}
@media (min-width: 1200px) {
    html[data-nav="collapsed"] { --side-w: var(--rail-w); }
}

/* phone + small tablet: off-canvas drawer */
@media (max-width: 860px) {
    :root { --side-w: 0px; }
    body { font-size: 14px; }
    .mobilebar { display: flex; }
    .shell { margin-inline-start: 0; }
    .side { width: min(300px, 86vw); transform: translateX(100%); visibility: hidden; padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
    [dir="ltr"] .side { transform: translateX(-100%); }
    html[data-open] .side { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
    html[data-open] .scrim { opacity: 1; visibility: visible; }
    html[data-open] body { overflow: hidden; }
    .side-collapse { display: none; }
    .side-close { display: inline-grid; }
    .wrap { padding-top: 22px; padding-bottom: 32px; }
    h1 { margin-bottom: 16px; }
}

/* ---------- Responsive tables → cards ---------------------------------- */

@media (max-width: 860px) {
    .table-wrap { overflow: visible; }
    table.rt, table.rt tbody { display: block; }
    table.rt { min-width: 0; }
    table.rt tr { display: block; }
    table.rt tr.th-row { display: none; }
    table.rt tr.th-row.has-check { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); background: transparent; }
    table.rt tr.th-row.has-check th { display: none; padding: 0; background: none; border: 0; }
    table.rt tr.th-row.has-check th:first-child { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
    table.rt tr.th-row.has-check th:first-child::after { content: "انتخاب همه"; }
    table.rt tr:not(.th-row) {
        position: relative;
        margin: 0 0 12px;
        padding: 6px 14px;
        background: var(--surface-2);
        border: 1px solid var(--line);
        border-radius: 14px;
    }
    table.rt tr:not(.th-row):hover > td { background: none; }
    table.rt td { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 6px 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); text-align: end; min-width: 0; }
    table.rt tr:not(.th-row) > td:last-child { border-bottom: 0; }
    table.rt td[data-label]::before { content: attr(data-label); flex: 1 0 auto; margin-inline-end: auto; max-width: 40%; color: var(--muted); font-size: 12.5px; font-weight: 600; text-align: start; padding-top: 2px; }
    table.rt td > * { min-width: 0; }
    table.rt td[colspan] { display: block; text-align: center; border: 0; padding: 18px 0; }
    table.rt td:not([data-label]) { justify-content: flex-start; }
    /* checkbox cell sits in the card corner */
    table.rt td:first-child:has(> input[type=checkbox]:only-child) { justify-content: flex-start; padding: 8px 0 6px; }
    table.rt td:first-child:has(> input[type=checkbox]:only-child)::before { display: none; }
    /* cells holding actions / forms: full-width, left aligned */
    table.rt td:empty { display: none; }
    table.rt td:last-child:not([data-label]) { padding-top: 12px; }
    table.rt td .row-actions { justify-content: flex-end; }
    table.rt td .key { text-align: start; }
    .lic-group table.rt tr:not(.th-row) { background: var(--surface); }
    .lic-group > table.rt, .lic-group .table-wrap { padding: 12px 12px 2px; }

    /* kv tables stack */
    table.kv, table.kv tbody, table.kv tr { display: block; }
    table.kv tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
    table.kv tr:last-child { border-bottom: 0; }
    table.kv th, table.kv td { display: block; width: auto; padding: 2px 0; border: 0; }
    table.kv th { font-size: 12px; padding-bottom: 4px; }
}

/* phones */
@media (max-width: 640px) {
    .wrap { padding-inline: 14px; }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .card { min-height: 100px; padding: 14px 15px; }
    .card .lbl { font-size: 12.5px; }
    .box { border-radius: 14px; padding: 16px 14px; }
    .issue-box > summary { padding: 14px 16px; }
    .issue-box .issue-body { padding: 2px 16px 16px; }
    .grid2 { grid-template-columns: 1fr; }
    input, select, textarea { font-size: 16px; }   /* stop iOS zoom */
    .btn { min-height: 44px; }
    .btn.sm { min-height: 36px; padding: 0 13px; }

    .toolbar { gap: 8px; }
    .toolbar input, .toolbar select { flex: 1 1 100%; max-width: none; width: 100%; }
    .toolbar input[type=number] { flex: 1 1 90px; width: auto; }
    .toolbar > .btn { flex: 1 1 auto; }
    .toolbar > .muted { flex: 1 1 100%; }
    form.toolbar { width: 100%; }
    .filter-bar input[type=text] { flex-basis: 100%; }

    .cards > .card:last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 88px; }
    .bulk-bar > .muted { flex: 1 1 100%; }
    .bulk-bar .btn { flex: 1 1 calc(50% - 8px); padding: 0 10px; }
    .bulk-bar input { flex: 1 1 80px; width: auto; }

    .cat-tabs { flex-wrap: nowrap; overflow-x: auto; margin-inline: -14px; padding: 2px 14px 8px; scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .cat-tabs::-webkit-scrollbar { display: none; }
    .cat-tabs .cat { scroll-snap-align: start; }

    .lic-group > summary { padding: 12px 14px; }
    .lic-group .g-badges { margin-inline-start: 0; width: 100%; }

    .alert { padding: 11px 13px; }
    .auth { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .auth-logo { display: block; }
    .auth-card { box-shadow: var(--shadow); }
}

@media (max-width: 900px) {
    .auth { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .auth-logo { display: block; }
}

@media (max-width: 360px) {
    .cards { grid-template-columns: 1fr; }
}

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

@media print {
    .side, .mobilebar, .scrim, .foot, .btn, .toolbar { display: none !important; }
    .shell { margin: 0; }
    body { background: #fff; color: #000; }
    body::before { display: none; }
    .box, .card { box-shadow: none; }
}
