/* =====================================================================
   FreeNet Admin — Design System v2
   Rewritten UI layer (Presentation only — no backend/business logic
   here). Design language: calm, minimal, box/panel-based "application"
   feel rather than a classic admin-template look. Brand accent (green)
   is preserved per project requirement; everything around it — spacing,
   radius, borders vs. shadow, typography scale, component set — has
   been rebuilt.

   Fonts are loaded via <link rel="preconnect"> + <link rel="stylesheet">
   in the HTML <head> (see partials/layout_top.php and login.php), not
   @import here — @import blocks CSS parsing until it resolves, which
   delays first paint on this project's slow host.
   ===================================================================== */

/* ---- Tokens --------------------------------------------------------- */
:root {
    --bg:            #0B1416;
    --surface:       #101B1E;
    --surface-2:     #162326;   /* one step up — panel-on-panel, inputs */
    --surface-3:     #1C2B2F;   /* hover / pressed state */
    --border:        #223035;
    --border-soft:   #1A2529;  /* quieter divider, e.g. inside a panel */
    --text:          #E9F1F1;
    --text-dim:      #8AA0A3;
    --text-faint:    #5C7075;

    --accent:          #34D399;  /* kept identical across both themes */
    --accent-contrast: #06251B;
    --accent-dim:      #163227;  /* active-nav / soft badge background */
    --accent-border:   #2B5C48;

    --info:      #5B9CF6;
    --info-dim:  #16233A;
    --warn:      #F0B429;
    --warn-dim:  #332708;
    --danger:    #F0554A;
    --danger-dim:#301715;
    --neutral-dim: #1C2B2F;

    --radius-sm: 6px;
    --radius:    9px;
    --radius-lg: 13px;
    --radius-xl: 18px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.18);
    --shadow-md: 0 8px 24px rgba(0,0,0,.30);
    --shadow-lg: 0 16px 48px rgba(0,0,0,.38);

    --sidebar-w:      258px;
    --sidebar-w-collapsed: 72px;
    --topbar-h:       58px;

    --font-ui:   'Vazirmatn', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;

    --ease: cubic-bezier(.4,0,.2,1);
}

:root[data-theme="light"] {
    --bg:            #F6F8F8;
    --surface:       #FFFFFF;
    --surface-2:     #F1F5F4;
    --surface-3:     #E7EEEC;
    --border:        #E1E8E6;
    --border-soft:   #EBF0EF;
    --text:          #0F1E1C;
    --text-dim:      #5E7370;
    --text-faint:    #93A5A2;

    --accent:          #1FA57A;   /* slightly deepened for AA contrast on white */
    --accent-contrast: #FFFFFF;
    --accent-dim:      #E3F6EE;
    --accent-border:   #B8E6D3;

    --info:      #2F6FE0;
    --info-dim:  #E8F0FE;
    --warn:      #9A6B0A;
    --warn-dim:  #FBF0D6;
    --danger:    #C4342A;
    --danger-dim:#FBE4E2;
    --neutral-dim: #EEF2F1;

    --shadow-sm: 0 1px 2px rgba(20,40,35,.06);
    --shadow-md: 0 10px 28px rgba(20,40,35,.10);
    --shadow-lg: 0 20px 48px rgba(20,40,35,.14);
}

/* ---- Reset / base ----------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14.5px;
    line-height: 1.7;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
ul { margin: 0; padding: 0; list-style: none; }
hr, .divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

code, .mono { font-family: var(--font-mono); direction: ltr; unicode-bidi: plaintext; }

.icon { flex-shrink: 0; }

::selection { background: var(--accent-dim); color: var(--text); }

button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible,
.nav-link:focus-visible, .menu-list-item:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* =====================================================================
   App shell — sidebar fixed on the RIGHT (native to RTL) and taken
   completely out of normal flow; topbar + content are pushed clear of
   it with a matching margin. Deliberately NOT a CSS Grid: a grid track
   has to size itself around a 100vh sidebar spanning both rows, which
   is a well-known source of stray extra space — a fixed sidebar with
   an offset margin has no such ambiguity. Sidebar collapses to an icon
   rail on desktop (persisted choice) and becomes an off-canvas drawer
   on mobile.
   ===================================================================== */
.app-shell {
    min-height: 100vh;
}

/* ---- Sidebar ----------------------------------------------------------- */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 30;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: width .18s var(--ease);
}
html[data-sidebar-collapsed="1"] .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    height: var(--topbar-h);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; color: var(--text); overflow: hidden; white-space: nowrap; }
.brand-mark {
    width: 26px; height: 26px; border-radius: 8px;
    background: var(--accent); color: var(--accent-contrast);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; flex-shrink: 0;
}

.sidebar-nav { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 16px; overflow-x: hidden; }
.nav-group-label {
    font-size: 11px; font-weight: 600; color: var(--text-faint);
    padding: 0 10px; margin-bottom: 6px; white-space: nowrap;
    text-transform: uppercase; letter-spacing: .04em;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 38px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 13.5px;
    font-weight: 500;
    transition: background .12s, color .12s;
    white-space: nowrap;
    overflow: hidden;
}
.nav-link .icon { color: var(--text-faint); transition: color .12s; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link:hover .icon { color: var(--text-dim); }
.nav-link.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-link.active .icon { color: var(--accent); }
.nav-link-danger { color: var(--danger); }
.nav-link-danger .icon { color: var(--danger); }
.nav-link-danger:hover { background: var(--danger-dim); color: var(--danger); }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border-soft); flex-shrink: 0; }
.collapse-toggle {
    width: 100%; justify-content: flex-start; gap: 11px;
    background: transparent; border: none; color: var(--text-faint);
    padding: 0 10px; min-height: 36px; font-size: 13px; font-weight: 500;
}
.collapse-toggle:hover { background: var(--surface-2); color: var(--text-dim); }
.collapse-toggle .icon { transition: transform .18s var(--ease); }

/* Collapsed (desktop icon-rail) state */
html[data-sidebar-collapsed="1"] .brand span:not(.brand-mark),
html[data-sidebar-collapsed="1"] .nav-group-label,
html[data-sidebar-collapsed="1"] .nav-link span,
html[data-sidebar-collapsed="1"] .collapse-toggle span { display: none; }
html[data-sidebar-collapsed="1"] .nav-link { justify-content: center; }
html[data-sidebar-collapsed="1"] .collapse-toggle { justify-content: center; }
html[data-sidebar-collapsed="1"] .collapse-toggle .icon { transform: rotate(180deg); }
html[data-sidebar-collapsed="1"] .sidebar-head { justify-content: center; padding: 0; }

/* ---- Topbar (slim global toolbar — no page title here) ---------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin-right: var(--sidebar-w);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 22px;
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-soft);
    transition: margin-right .18s var(--ease);
}
html[data-sidebar-collapsed="1"] .topbar { margin-right: var(--sidebar-w-collapsed); }

#hamburgerBtn { display: none; } /* shown only on mobile — see media query below */

.topbar-start { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-end { display: flex; align-items: center; gap: 8px; }

.search-box {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 0 12px; height: 36px;
    color: var(--text-faint); max-width: 320px; width: 100%;
}
.search-box .icon { flex-shrink: 0; }
.search-box input {
    background: transparent; border: none; margin: 0; padding: 0;
    height: auto; font-size: 13.5px; color: var(--text);
}
.search-box input::placeholder { color: var(--text-faint); }
.search-box input:focus { outline: none; }

.icon-btn {
    width: 36px; height: 36px; min-height: 0; padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent;
    color: var(--text-dim); border-radius: var(--radius-sm);
    position: relative;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.icon-btn.xs { width: 27px; height: 27px; }
#themeToggle .icon-sun { display: none; }
#themeToggle .icon-moon { display: flex; }
:root[data-theme="light"] #themeToggle .icon-sun { display: flex; }
:root[data-theme="light"] #themeToggle .icon-moon { display: none; }
.notif-dot { position: absolute; top: 7px; left: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); border: 2px solid var(--bg); }

/* Avatar + account dropdown */
.avatar {
    width: 34px; height: 34px; border-radius: 999px;
    background: var(--accent-dim); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.account-btn { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 9px; height: 40px; width: auto; }
.account-btn .chev { color: var(--text-faint); }

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: calc(100% + 8px); right: 0;
    min-width: 190px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    padding: 6px; z-index: 40; display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 9px; border-radius: var(--radius-sm);
    color: var(--text-dim); font-size: 13.5px; cursor: pointer;
    min-height: 0;
}
.dropdown-item:hover { background: var(--surface-2); color: var(--text); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-dim); }
.dropdown-sep { height: 1px; background: var(--border-soft); margin: 5px 3px; }
.dropdown-label { padding: 8px 9px 4px; font-size: 12px; color: var(--text-faint); }

/* ---- Content column ----------------------------------------------------- */
.main {
    margin-right: var(--sidebar-w);
    padding: 26px 30px 60px;
    max-width: 1180px;
    min-width: 0;
    transition: margin-right .18s var(--ease);
}
html[data-sidebar-collapsed="1"] .main { margin-right: var(--sidebar-w-collapsed); }

/* Page header — title/subtitle/actions block lives IN the content, not
   the topbar. Auto-emitted by partials/layout_top.php from $pageTitle /
   $pageSubtitle / $pageActions. */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-header h1 { font-size: 21px; font-weight: 700; }
.page-header p { color: var(--text-dim); font-size: 13.5px; margin-top: 4px; }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ---- Panels / Cards ----------------------------------------------------- */
.card, .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}
.card h2, .panel h2, .section-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 14px;
    color: var(--text);
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px; gap: 10px; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
.panel-desc { color: var(--text-dim); font-size: 12.5px; margin-top: -10px; margin-bottom: 14px; }

/* Toolbar — a thin control strip inside a panel (search + filter + action) */
.toolbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 160px; }

.grid-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }

.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 16px; display: flex; align-items: flex-start; gap: 12px;
}
.stat-icon {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: var(--accent-dim); color: var(--accent);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-body { min-width: 0; }
.stat .value { font-size: 21px; font-weight: 700; font-family: var(--font-mono); word-break: break-word; line-height: 1.3; }
.stat .label { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; }

/* ---- Forms --------------------------------------------------------------- */
label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }
input, select, textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    font-family: var(--font-ui);
    font-size: 13.5px;
    margin-bottom: 14px;
    transition: border-color .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; }
.field-hint { font-size: 12px; color: var(--text-faint); margin-top: -10px; margin-bottom: 14px; }

/* Checkbox / Radio / Switch — new to the system (base styles for use as
   the project grows into them) */
.check-row { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.check-row label { margin: 0; color: var(--text); font-weight: 400; font-size: 13.5px; }
input[type="checkbox"], input[type="radio"] { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); flex-shrink: 0; }

.switch { position: relative; display: inline-block; width: 40px; height: 23px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; margin: 0; }
.switch .track {
    position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border);
    border-radius: 999px; transition: background .15s;
}
.switch .track::before {
    content: ''; position: absolute; width: 17px; height: 17px; border-radius: 50%;
    background: #fff; top: 2px; right: 3px; transition: transform .15s var(--ease);
    box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::before { transform: translateX(-17px); }

/* ---- Buttons --------------------------------------------------------------- */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: var(--accent);
    color: var(--accent-contrast);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0 16px;
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    transition: filter .12s, background .12s, border-color .12s;
    min-height: 40px;
}
button:hover, .btn:hover { filter: brightness(1.07); }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-3); }
button.ghost, .btn.ghost { background: transparent; color: var(--text-dim); border-color: transparent; }
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); color: var(--text); }
button.danger, .btn.danger { background: var(--danger); color: #fff; }
button.sm, .btn.sm { min-height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: var(--radius-sm); }
button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

.icon-btn.action { width: 30px; height: 30px; border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-sm); }
.icon-btn.action:hover { background: var(--surface-3); border-color: var(--border); color: var(--text); }
.actions-cell { display: flex; gap: 6px; }

/* ---- Table ----------------------------------------------------------------- */
.card table, .panel table { display: block; overflow-x: auto; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: right; padding: 11px 10px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--text-faint); font-weight: 600; font-size: 11.5px; white-space: nowrap; text-transform: uppercase; letter-spacing: .02em; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ---- Badge ------------------------------------------------------------------ */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge.on   { background: var(--accent-dim); color: var(--accent); }
.badge.off  { background: var(--danger-dim); color: var(--danger); }
.badge.wait { background: var(--warn-dim); color: var(--warn); }
.badge.info { background: var(--info-dim); color: var(--info); }
.badge.neutral { background: var(--neutral-dim); color: var(--text-dim); }

/* ---- Alert (banner) ---------------------------------------------------------- */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 13px 14px; border-radius: var(--radius); border: 1px solid;
    font-size: 13.5px; margin-bottom: 16px;
}
.alert.warn { background: var(--warn-dim); border-color: var(--warn-dim); color: var(--warn); }
.alert.danger { background: var(--danger-dim); border-color: var(--danger-dim); color: var(--danger); }
.alert.info { background: var(--info-dim); border-color: var(--info-dim); color: var(--info); }
.alert .icon { flex-shrink: 0; margin-top: 1px; }
.alert-body { color: var(--text); }
.alert-body strong { display: block; margin-bottom: 2px; }

/* ---- Empty / Loading / Error state -------------------------------------------- */
.empty-state, .loading-state, .error-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 46px 20px; color: var(--text-dim); gap: 8px;
}
.empty-state .icon, .error-state .icon { color: var(--text-faint); margin-bottom: 6px; }
.empty-state h3, .error-state h3 { font-size: 14px; color: var(--text); font-weight: 600; }
.empty-state p, .error-state p { font-size: 13px; max-width: 320px; }
.spinner {
    width: 22px; height: 22px; border-radius: 50%;
    border: 2.5px solid var(--border); border-top-color: var(--accent);
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Tabs ------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
    padding: 10px 4px; margin-inline-end: 18px;
    color: var(--text-dim); font-size: 13.5px; font-weight: 500;
    border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---- Modal / Drawer (base — available for future use) ----------------------- */
.overlay {
    position: fixed; inset: 0; background: rgba(4,10,10,.55);
    z-index: 49; display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.overlay.open { display: flex; }
.modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
    padding: 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 15.5px; font-weight: 700; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.overlay.drawer-overlay { justify-content: flex-start; padding: 0; align-items: stretch; }
.drawer {
    background: var(--surface); border-inline-start: 1px solid var(--border);
    width: min(400px, 92vw); height: 100%; padding: 20px; overflow-y: auto;
    box-shadow: var(--shadow-lg); margin-inline-start: auto;
}

/* ---- List / Avatar reused in content (not just topbar) ----------------------- */
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.list-row:last-child { border-bottom: none; }

/* ---- Toast -------------------------------------------------------------------- */
.toast {
    position: fixed;
    bottom: 20px;
    inset-inline-start: 20px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .2s, transform .2s;
    pointer-events: none;
    z-index: 999;
    max-width: calc(100vw - 40px);
    display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---- Login shell ---------------------------------------------------------------- */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(560px 320px at 85% -8%, var(--accent-dim), transparent 65%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 32px 28px;
    box-shadow: var(--shadow-md);
}
.login-mark {
    width: 44px; height: 44px; border-radius: var(--radius);
    background: var(--accent); color: var(--accent-contrast);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
}
.login-card h1 { font-size: 17px; text-align: center; font-weight: 700; }
.login-card .sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-top: 4px; margin-bottom: 22px; }
.login-error {
    display: flex; align-items: center; gap: 8px;
    color: var(--danger); background: var(--danger-dim); border: 1px solid transparent;
    border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 14px;
}

/* ---- Color swatch picker (button style) ------------------------------------ */
.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.swatch {
    display: flex; align-items: center; gap: 7px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 999px; padding: 7px 13px 7px 9px;
    font-family: var(--font-ui); font-size: 12.5px; color: var(--text-dim);
    cursor: pointer; min-height: 0;
}
.swatch:hover { background: var(--surface-3); }
.swatch.selected { border-color: var(--accent); color: var(--text); background: var(--accent-dim); }
.swatch-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--border); display: inline-block; }
.swatch-default { background: var(--surface); }
.swatch-primary { background: #3B82F6; border-color: #3B82F6; }
.swatch-success { background: #22C55E; border-color: #22C55E; }
.swatch-danger  { background: #EF4444; border-color: #EF4444; }

/* ---- Nested button builder ("دکمه‌ساز") -------------------------------------- */
.kb-builder-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }

.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; font-size: 12.5px; }
.breadcrumb-item { color: var(--accent); cursor: pointer; padding: 3px 5px; border-radius: var(--radius-sm); }
.breadcrumb-item:hover { background: var(--surface-2); }
.breadcrumb-item.current { color: var(--text); font-weight: 600; cursor: default; }
.breadcrumb-item.current:hover { background: none; }
.breadcrumb-sep { color: var(--text-faint); font-size: 11px; }

.builder-row-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.row-toolbar-label { font-size: 11.5px; font-weight: 600; color: var(--text-faint); }
.row-toolbar-icons, .btn-toolbar-icons { display: flex; gap: 4px; }

.row-buttons { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.builder-btn-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.btn-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.btn-toolbar-label { font-size: 11px; color: var(--text-faint); }

.add-row-btn, .add-btn-btn {
    width: 100%; background: transparent; border: 1.5px dashed var(--border);
    color: var(--text-dim); font-weight: 500;
}
.add-row-btn:hover, .add-btn-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.add-btn-btn { margin-top: 2px; padding: 8px; font-size: 12.5px; }

/* ---- Live phone-style preview -------------------------------------------------- */
.preview-col { min-width: 0; }
.preview-sticky { position: sticky; top: calc(var(--topbar-h) + 20px); }
.phone-preview {
    background: #0E1621;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
.phone-header { background: #17212B; color: #fff; padding: 12px 14px; display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,.06); }
.phone-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-dim); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.phone-body { padding: 16px 12px; min-height: 280px; }
.phone-bubble { background: #182533; color: #E6EDF3; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; line-height: 1.7; white-space: pre-wrap; max-width: 92%; margin-inline-start: auto; }
.phone-kb-row { display: flex; gap: 6px; margin-top: 6px; }
.phone-inline-kb { margin-top: 4px; }
.preview-inline-btn { flex: 1; background: rgba(90,150,255,.12); color: #6EA8FF; border: 1px solid rgba(110,168,255,.25); border-radius: var(--radius-sm); padding: 7px 6px; font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-reply-dock { padding: 8px 10px 12px; }
.phone-reply-kb { margin-bottom: 8px; }
.preview-reply-btn { flex: 1; background: #202B36; color: #E6EDF3; border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius-sm); padding: 9px 6px; font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-input-bar { background: #17212B; color: rgba(255,255,255,.35); border-radius: 999px; padding: 9px 16px; font-size: 12px; }

/* ---- Menu builder list (settings-style nested list) ---------------------------- */
.builder-layout { display: grid; grid-template-columns: 230px 1fr; gap: 18px; align-items: start; }
.menu-list-item { display: flex; justify-content: space-between; align-items: center; min-height: 36px; padding: 0 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-dim); font-size: 13.5px; margin-bottom: 2px; }
.menu-list-item:hover { background: var(--surface-2); }
.menu-list-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.menu-list-item.root::after { content: '★'; font-size: 10.5px; color: var(--warn); margin-inline-start: 6px; }

.button-cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.button-cell .pos { color: var(--text-faint); font-family: var(--font-mono); font-size: 11.5px; }

@media (max-width: 980px) {
    .kb-builder-layout, .builder-layout { grid-template-columns: 1fr; }
    .preview-sticky { position: static; }
}

/* =====================================================================
   Mobile — RTL off-canvas drawer from the right, single-column content,
   full-width panels, touch-friendly targets. This is a distinct
   navigation mode, not a shrunk desktop layout.
   ===================================================================== */
@media (max-width: 860px) {
    .topbar { margin-right: 0; padding: 0 12px; }
    .main { margin-right: 0; padding: 16px 14px 40px; }
    .search-box { display: none; } /* reachable via a dedicated icon on small screens, kept out of the way here */
    #hamburgerBtn { display: flex; }

    .sidebar, html[data-sidebar-collapsed="1"] .sidebar {
        position: fixed; right: 0; top: 0; bottom: 0;
        width: min(82vw, 300px);
        transform: translateX(100%);
        z-index: 50;
        box-shadow: var(--shadow-lg);
        transition: transform .2s var(--ease);
    }
    .sidebar.open { transform: translateX(0); }
    html[data-sidebar-collapsed="1"] .brand span:not(.brand-mark),
    html[data-sidebar-collapsed="1"] .nav-group-label,
    html[data-sidebar-collapsed="1"] .nav-link span { display: inline; }
    html[data-sidebar-collapsed="1"] .nav-link { justify-content: flex-start; }
    .sidebar-foot { display: none; } /* collapse toggle is meaningless on mobile */

    .drawer-backdrop { display: none; position: fixed; inset: 0; top: var(--topbar-h); background: rgba(4,10,10,.5); z-index: 45; }
    .drawer-backdrop.open { display: block; }

    .nav-link { min-height: 46px; font-size: 14.5px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header-actions { width: 100%; }
    .page-header-actions .btn, .page-header-actions button { flex: 1; }
    .field-row { grid-template-columns: 1fr; }
    .page-header h1 { font-size: 18px; }

    input, select, textarea, button, .btn { font-size: 16px; } /* prevents iOS auto-zoom on focus */
    .modal, .drawer { max-width: 100%; }
    .overlay { padding: 0; align-items: flex-end; }
    .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; width: 100%; max-width: 100%; }
}
