:root {
    --primary: #6C31F5;
    --primary-deep: #2E158C;
    --primary-hover: #5722D4;
    --primary-active: #4616B8;
    --primary-subtle: #F4F0FF;
    --lavender: #C8A7FF;
    --on-primary: #ffffff;
    --background: #FAF8FF;
    --surface: #ffffff;
    --surface-low: #F4F0FF;
    --surface-mid: #ECE5FF;
    --border: #EAE4FC;
    --border-strong: #C8A7FF;
    --text: #1A103C;
    --heading: #2E158C;
    --muted: #4D426D;
    --faint: #7A7488;
    --error: #DC2626;
    --error-bg: #FEF2F2;
    --ok: #059669;
    --ok-bg: #ECFDF5;
    --warn: #D97706;
    --warn-bg: #FEF3C7;
    --info: #6C31F5;
    --info-bg: #F4F0FF;
    --ai: #6C31F5;
    --ai-bg: #F4F0FF;
    --shadow-1: 0 2px 8px -2px rgba(46, 21, 140, 0.05), 0 1px 3px 0 rgba(46, 21, 140, 0.03);
    --shadow-2: 0 8px 24px -4px rgba(46, 21, 140, 0.10), 0 2px 6px -1px rgba(108, 49, 245, 0.06);
    --shadow-btn: 0 4px 14px rgba(108, 49, 245, 0.35);
    --focus-ring: 0 0 0 3px rgba(200, 167, 255, 0.45);
    --sidebar: 260px;
    --header: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--background);
    color: var(--text);
    font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", sans-serif;
    font-size: 14px;
    line-height: 22px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; }
.num { font-family: "JetBrains Mono", "IBM Plex Sans", ui-monospace, monospace; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar);
    background: #fff;
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-1);
    z-index: 40;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--heading);
    font-weight: 700;
    font-size: 16px;
    line-height: 22px;
    text-decoration: none;
}
.brand:hover { color: var(--heading); text-decoration: none; }
.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    object-fit: contain;
    background: transparent;
    flex: 0 0 auto;
    box-shadow: 0 4px 12px rgba(108, 49, 245, 0.28);
}
.brand-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand-name { letter-spacing: 0.04em; }
.brand-name-ar { color: var(--primary); font-size: 12px; font-weight: 600; }
.brand small, .brand-tag {
    display: block;
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
    line-height: 16px;
}
.sidebar-top { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.sidebar-brand { padding: 16px 20px 8px; flex-shrink: 0; }
.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
}
.nav-label {
    margin: 16px 20px 6px;
    color: var(--faint);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.nav { display: flex; flex-direction: column; gap: 4px; overflow: visible; padding: 0 12px; }
.nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    padding: 8px 12px;
    border-radius: 8px;
}
.nav a .material-symbols-outlined { font-size: 20px; color: var(--faint); }
.nav a.active { background: var(--primary); color: var(--on-primary); font-weight: 600; }
.nav a.active .material-symbols-outlined { color: var(--on-primary); }
.nav a:hover { background: var(--surface-low); color: var(--heading); text-decoration: none; }
.nav a:hover .material-symbols-outlined { color: var(--primary); }
.nav a.active:hover { background: var(--primary-hover); color: var(--on-primary); }
.nav a.active:hover .material-symbols-outlined { color: var(--on-primary); }
.sidebar-foot { flex-shrink: 0; margin-top: auto; padding: 12px 16px 16px; display: grid; gap: 10px; }
.sidebar-foot .btn { width: 100%; }
.sidebar-health {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-low);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--muted);
    font-size: 12px;
}
.sidebar-health .material-symbols-outlined { font-size: 16px; color: var(--primary); }
.sidebar-health .pulse-dot { margin-right: auto; }
.menu-toggle, .backdrop { display: none; }

.workspace { margin-right: var(--sidebar); min-height: 100vh; }
.header {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}
.header-search {
    flex: 1;
    max-width: 520px;
    position: relative;
    display: flex;
    align-items: center;
}
.header-search .material-symbols-outlined {
    position: absolute;
    right: 12px;
    color: var(--faint);
    font-size: 18px;
    pointer-events: none;
}
.header-search input {
    margin: 0;
    height: 40px;
    min-height: 40px;
    padding: 8px 40px 8px 14px;
    background: var(--surface-low);
    border-color: transparent;
}
.header-tools { display: flex; align-items: center; gap: 12px; }
.header-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-low);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.header-chip.muted-chip { color: var(--muted); }
.header-notify {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: var(--muted);
}
.header-notify:hover { background: var(--surface-low); color: var(--heading); text-decoration: none; }
.header-notify-dot {
    position: absolute;
    top: 8px;
    right: 9px;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--error);
}
.header-divider { width: 1px; height: 24px; background: var(--border); }
.header-who { display: flex; align-items: center; gap: 10px; }
.who { text-align: left; }
.who strong { display: block; color: var(--heading); }
.who span { color: var(--muted); font-size: 12px; }
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 0 0 0 rgba(108, 49, 245, .45);
    animation: pulse-dot 1.6s ease-out infinite;
}
.pulse-dot.dim { background: var(--faint); animation: none; box-shadow: none; }
@keyframes pulse-dot {
    0% { box-shadow: 0 0 0 0 rgba(108, 49, 245, .4); }
    100% { box-shadow: 0 0 0 8px rgba(108, 49, 245, 0); }
}
.main { padding: 24px; max-width: 1600px; }
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-1);
}
h1 { font-size: 24px; line-height: 32px; margin: 0; color: var(--heading); }
h2 { font-size: 20px; line-height: 28px; margin: 0 0 8px; color: var(--heading); }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 12px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-1);
}
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi strong { display: block; margin-top: 8px; font-size: 28px; color: var(--heading); font-family: "JetBrains Mono", "IBM Plex Sans", ui-monospace, monospace; }
.dash-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 20px;
}
.dash-hero .btn { gap: 6px; }
.dash-live { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--primary-subtle);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
}
.kpi-card {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}
.kpi-card strong { display: block; margin-top: 6px; font-size: 26px; color: var(--heading); font-family: "JetBrains Mono", "IBM Plex Sans", ui-monospace, monospace; }
.kpi-card .faint { display: block; margin-top: 4px; }
.kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--surface-low);
    color: var(--primary);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}
.kpi-icon.secondary { background: #E8EEFF; color: #3A485C; }
.kpi-icon.success { background: var(--ok-bg); color: var(--ok); }
.kpi-icon.ai { background: #EDE7FF; color: #4B1ECB; }
.dash-split {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 16px;
    margin: 16px 0;
}
.dash-panel h3 { margin: 0; font-size: 16px; }
.dash-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}
.dash-panel-title { display: flex; align-items: center; gap: 8px; }
.dash-panel-title .material-symbols-outlined { color: var(--primary); }
.chart-legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.swatch.primary { background: var(--primary); }
.swatch.secondary { background: #7A7488; }
.swatch.tertiary { background: #4B1ECB; }
.line-chart { width: 100%; }
.line-chart svg { width: 100%; height: 200px; overflow: visible; }
.chart-grid { stroke: #EAE4FC; stroke-dasharray: 3 3; stroke-width: 1; }
.chart-area { fill: rgba(108, 49, 245, .16); }
.chart-line { fill: none; stroke: #2E158C; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-axis {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 11px;
    margin-top: 8px;
}
.donut-wrap { position: relative; width: 150px; height: 150px; margin: 12px auto; }
.donut { width: 150px; height: 150px; transform: rotate(-90deg); }
.donut path { fill: none; stroke-width: 4.5; }
.donut-track { stroke: var(--surface-low); }
.donut-data { stroke: var(--primary); stroke-linecap: round; }
.donut-program { stroke: #4B1ECB; stroke-linecap: round; }
.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.donut-center strong { font-size: 20px; color: var(--heading); }
.donut-center span { font-size: 11px; color: var(--muted); }
.donut-list { display: grid; gap: 8px; }
.donut-list > div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    background: var(--surface-low);
    border-radius: 10px;
}
.dash-table { padding: 0; overflow: hidden; }
.dash-table .dash-panel-head { padding: 16px 16px 0; }
.table-wrap.flat { border: 0; border-radius: 0; box-shadow: none; }
.dash-table-foot { padding: 12px 16px 16px; }
.entity { display: flex; align-items: center; gap: 10px; }
.entity-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--primary-subtle);
    color: var(--primary-deep);
    display: grid;
    place-items: center;
    font-weight: 700;
    flex: 0 0 auto;
}
.usage-meter { margin: 0 0 16px; }
.meter {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-low);
    overflow: hidden;
}
.meter > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--primary);
    color: var(--on-primary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow-btn);
    transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
.btn:hover { background: var(--primary-hover); color: var(--on-primary); text-decoration: none; }
.btn:active { background: var(--primary-active); transform: scale(.99); }
.btn.secondary {
    background: var(--surface);
    color: var(--heading);
    border-color: var(--border-strong);
    box-shadow: none;
}
.btn.secondary:hover { background: var(--surface-low); border-color: var(--primary); color: var(--primary); }
.btn.danger { background: var(--error); box-shadow: none; }
.btn.ai { background: var(--ai-bg); color: var(--ai); border-color: var(--lavender); box-shadow: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 6px; color: var(--heading); }
input, select, textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    margin-bottom: 12px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}
textarea { min-height: 88px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.icon-picker { display: grid; gap: 10px; }
.icon-picker-preview {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 12px;
    background: #f7f1ff;
    border: 1px solid #ece4ff;
    width: fit-content;
}
.icon-picker-preview .material-symbols-outlined { color: #6c31f5; font-size: 28px; }
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 8px;
    max-height: 180px;
    overflow: auto;
    padding: 8px;
    border: 1px solid #ece4ff;
    border-radius: 12px;
    background: #fff;
}
.icon-picker-option {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid #ece4ff;
    border-radius: 10px;
    background: #fdf7ff;
    color: #1d1440;
    cursor: pointer;
    display: grid;
    place-items: center;
}
.icon-picker-option:hover { border-color: #c8a7ff; background: #f4f0ff; }
.icon-picker-option.is-active { background: #6c31f5; color: #fff; border-color: #6c31f5; }
.media-preview { margin-bottom: 10px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-1); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: right; padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-low); color: var(--heading); font-size: 12px; font-weight: 600; border-bottom: 2px solid var(--border); }
tr:nth-child(even) td { background: #FAF8FF; }
tr:hover td { background: #F1EBFF; }

.badge {
    display: inline-flex;
    align-items: center;
    height: 24px;
    border-radius: 9999px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-low);
    color: var(--primary);
    border: 1px solid var(--lavender);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: #A7F3D0; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: #FDE68A; }
.badge.bad { background: var(--error-bg); color: var(--error); border-color: #FECACA; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: var(--lavender); }

.alert { background: var(--primary-subtle); border: 1px solid var(--lavender); color: var(--heading); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }
.errors { background: var(--error-bg); color: var(--error); border: 1px solid #FECACA; border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }

.guest-shell {
    min-height: 100vh;
    position: relative;
    overflow: hidden;
    background: var(--background);
}
.guest-shell::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .35;
    background-image: radial-gradient(rgba(108, 49, 245, .55) 0.75px, transparent 0.75px);
    background-size: 32px 32px;
}
.guest-shell::after {
    content: "";
    position: absolute;
    top: -180px;
    left: 50%;
    transform: translateX(-50%);
    width: 720px;
    height: 360px;
    border-radius: 9999px;
    background: rgba(200, 167, 255, .28);
    filter: blur(64px);
    pointer-events: none;
}
.guest-main { position: relative; z-index: 1; max-width: 1120px; margin: 0 auto; padding: 24px 20px 64px; }
.guest-top, .topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.guest-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: rgba(255,255,255,.85);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 6px 12px;
    box-shadow: var(--shadow-1);
}
.guest-chip::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 9999px;
    background: var(--primary);
}
.hero {
    padding: 56px 0 20px;
    max-width: 720px;
}
.hero .brand-hero {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
}
.hero .brand-hero img { width: 72px; height: 72px; border-radius: 20px; box-shadow: var(--shadow-btn); }
.hero .brand-hero .brand-name {
    font-size: 40px;
    line-height: 1;
    letter-spacing: 0.06em;
    color: var(--heading);
}
.hero .brand-hero .brand-name-ar {
    font-size: 16px;
    margin-top: 6px;
}
.hero h1 { font-size: 32px; line-height: 40px; margin-bottom: 12px; }
.hero .lede { font-size: 16px; line-height: 26px; max-width: 34rem; margin: 0 0 24px; }

.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    position: relative;
    overflow: hidden;
    background: var(--background);
}
.auth-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .4;
    background-image: radial-gradient(rgba(108, 49, 245, .55) 0.75px, transparent 0.75px);
    background-size: 32px 32px;
}
.auth-screen::after {
    content: "";
    position: absolute;
    top: -160px;
    left: 50%;
    transform: translateX(-50%);
    width: 700px;
    height: 350px;
    border-radius: 9999px;
    background: rgba(200, 167, 255, .25);
    filter: blur(48px);
    pointer-events: none;
}
.auth-card {
    width: min(440px, 100%);
    position: relative;
    z-index: 1;
    padding: 28px;
    border-radius: 20px;
    box-shadow: var(--shadow-2);
    backdrop-filter: blur(12px);
}
.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
    text-align: right;
}
.auth-brand img { width: 44px; height: 44px; border-radius: 12px; }
.auth-brand strong { display: block; color: var(--heading); letter-spacing: 0.04em; }
.auth-brand span { color: var(--primary); font-size: 12px; font-weight: 600; }
.auth-card h1 { text-align: center; }
.auth-card > .muted { text-align: center; }
.auth-card .btn { width: 100%; margin-top: 4px; }
.auth-foot { text-align: center; margin-top: 16px; }

.data-browser {
    display: grid;
    grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}
.data-tables h2 { margin-bottom: 10px; }
.data-table-link {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    margin-bottom: 4px;
}
.data-table-link:hover { background: var(--surface-low); text-decoration: none; }
.data-table-link.active {
    background: var(--primary-subtle);
    color: var(--primary-deep);
    font-weight: 600;
}
.data-rows { min-width: 0; }
@media (max-width: 900px) {
    .data-browser { grid-template-columns: 1fr; }
}

.chat {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 320px;
}
.bubble { max-width: min(720px, 100%); padding: 12px 14px; border-radius: 14px; white-space: pre-wrap; }
.bubble.user { background: var(--surface-low); margin-right: auto; border-bottom-left-radius: 2px; }
.bubble.ai { background: var(--surface); border: 1px solid var(--border); border-bottom-right-radius: 2px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { margin: 0; flex: 1; }

html:has(.chat-shell),
body:has(.chat-shell) {
    height: 100svh;
    max-height: 100svh;
    overflow: hidden;
    overscroll-behavior: none;
}
.workspace:has(.chat-shell) {
    height: 100svh;
    max-height: 100svh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.workspace:has(.chat-shell) .header {
    flex-shrink: 0;
}
.main:has(.chat-shell) {
    padding: 0;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-width: none;
    overflow: hidden;
}
.main:has(.chat-shell) > .alert,
.main:has(.chat-shell) > .errors {
    flex-shrink: 0;
    margin: 12px 16px 0;
}
.chat-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--background);
}
.chat-rail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-left: 1px solid var(--border);
    background: var(--surface);
    min-height: 0;
    overflow: hidden;
}
.chat-rail-backdrop {
    display: none;
}
.chat-mobile-bar {
    display: none;
}
.chat-new { display: grid; gap: 8px; }
.chat-new label { margin: 0; }
.chat-new select { margin: 0; }
.chat-new .btn { width: 100%; }
.chat-rail-label { color: var(--faint); font-size: 12px; font-weight: 700; margin-top: 4px; }
.chat-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}
.chat-list-item {
    display: grid;
    gap: 2px;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--text);
    border: 1px solid transparent;
}
.chat-list-item strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-list-item span { color: var(--faint); font-size: 11px; }
.chat-list-item:hover { background: var(--surface-low); text-decoration: none; color: var(--text); }
.chat-list-item.active {
    background: var(--primary-subtle);
    border-color: var(--border-strong);
}
.chat-list-empty { margin: 8px 4px; }
.chat-quota { margin-top: auto; }

.chat-stage {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: var(--background);
}
.chat-stage-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
.chat-stage-head h1 { font-size: 18px; line-height: 26px; }
.chat-stage-head .muted { margin: 2px 0 0; }
.chat-thread {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}
.chat-thread .bubble { max-width: min(680px, 92%); }
.chat-thread .bubble.user { align-self: flex-start; background: var(--primary); color: var(--on-primary); }
.chat-thread .bubble.ai { align-self: flex-end; }
.chat-thread .bubble.md {
    white-space: normal;
    line-height: 1.55;
}
.chat-thread .bubble.md strong { font-weight: 700; color: inherit; }
.chat-thread .bubble.md em { font-style: italic; }
.chat-thread .bubble.md code {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.9em;
    background: var(--surface-low);
    padding: 0.1em 0.35em;
    border-radius: 6px;
}
.chat-thread .bubble.typing {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    min-height: 44px;
}
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.typing-dots i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.35;
    animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
.typing-label { font-size: 13px; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40% { transform: translateY(-3px); opacity: 1; }
}
.chat-empty {
    margin: auto;
    text-align: center;
    max-width: 420px;
    padding: 24px;
}
.chat-empty-full { padding: 48px 24px; }
.chat-empty h1, .chat-empty h2 { margin-bottom: 8px; }

.chat-composer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 5;
}
.chat-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-composer textarea {
    margin: 0;
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    border-radius: 14px;
    padding: 12px 14px;
}
.chat-composer .send-btn {
    height: 44px;
    width: 44px;
    min-width: 44px;
    padding: 0;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-composer .send-btn.is-busy,
.chat-composer .send-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.chat-composer .faint { margin: 8px 4px 0; }
.btn-svg { width: 20px; height: 20px; display: block; }
.icon-btn { line-height: 0; }

.mic-btn {
    height: 44px;
    width: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--heading);
    font: inherit;
    cursor: pointer;
    padding: 0;
}
.mic-btn:hover { background: var(--surface-low); }
.mic-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.mic-btn.recording {
    background: var(--error-bg);
    border-color: var(--error);
    color: var(--error);
    animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.25); }
    50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.menu-btn {
    display: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--heading);
    border-radius: 8px;
    height: 38px;
    padding: 0 12px;
    font: inherit;
    cursor: pointer;
}

.site-foot {
    margin-top: 48px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--faint);
    font-size: 12px;
    text-align: center;
}

.material-symbols-outlined {
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
    line-height: 1;
    font-size: 20px;
}
.hidden { display: none !important; }

.blog-admin-head, .blog-editor-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}
.blog-editor-head {
    position: sticky;
    top: calc(var(--header) + 8px);
    z-index: 15;
    background: var(--background);
    padding-bottom: 8px;
}
.blog-admin-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.blog-count {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--surface-mid);
    color: var(--muted);
    font-size: 12px;
}
.blog-admin .btn .material-symbols-outlined { font-size: 18px; margin-inline-start: 0; }
.blog-admin-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-1);
    overflow: hidden;
}
.blog-admin-filters {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    flex-wrap: wrap;
}
.blog-search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.blog-search .material-symbols-outlined {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--faint);
}
.blog-search input { margin: 0; padding-right: 40px; background: var(--surface-low); border-color: transparent; }
.blog-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--surface-low);
    border-radius: 10px;
}
.blog-tabs a {
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 600;
}
.blog-tabs a.is-active { background: var(--primary); color: #fff; }
.blog-table-wrap { border: 0; border-radius: 0; box-shadow: none; }
.blog-title-cell { display: flex; align-items: center; gap: 10px; }
.blog-title-cell a { font-weight: 700; color: var(--heading); }
.blog-title-cell .faint { display: block; }
.blog-thumb {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface-low);
    color: var(--primary);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}
.blog-chip {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--surface-low);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}
.blog-author { display: flex; align-items: center; gap: 8px; }
.blog-avatar {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--primary-subtle);
    color: var(--primary-deep);
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 700;
}
.blog-col-center { text-align: center; }
.blog-col-actions { text-align: left; }
.blog-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.blog-status::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.blog-status-published { background: var(--ok-bg); color: var(--ok); }
.blog-status-draft, .blog-status-scheduled { background: var(--surface-low); color: var(--muted); }
.blog-row-actions { display: inline-flex; gap: 4px; }
.blog-icon-btn {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
}
.blog-icon-btn:hover { background: var(--surface-low); color: var(--primary); }
.blog-icon-btn.danger:hover { background: var(--error-bg); color: var(--error); }
.blog-empty { text-align: center; padding: 36px 16px; }
.blog-empty .material-symbols-outlined { font-size: 28px; color: var(--faint); }
.blog-pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    flex-wrap: wrap;
}
.blog-pager-links { display: flex; gap: 4px; }
.blog-pager-links a, .blog-pager-links span {
    min-width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}
.blog-pager-links .is-active { background: var(--primary); color: #fff; font-weight: 700; }
.blog-pager-links .is-disabled { opacity: .4; }

.blog-crumbs { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.blog-crumbs .material-symbols-outlined { font-size: 14px; }
.blog-editor-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.blog-panel { display: flex; flex-direction: column; gap: 8px; }
.blog-panel h2 { font-size: 16px; }
.blog-title-input { font-size: 20px; font-weight: 700; min-height: 52px; background: var(--surface-low); }
.blog-cover-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; }
.blog-dropzone {
    position: relative;
    display: block;
    border-radius: 12px;
    background: var(--surface-low);
    padding: 24px;
    text-align: center;
    cursor: pointer;
}
.blog-dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.blog-dropzone .material-symbols-outlined { font-size: 28px; color: var(--primary); }
.blog-dropzone img { width: 100%; height: 208px; object-fit: cover; border-radius: 10px; }
.blog-remove-cover { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.blog-remove-cover input { width: auto; min-height: 0; margin: 0; }
.blog-editor-meta { display: flex; justify-content: space-between; gap: 8px; }
.blog-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px;
    background: var(--surface-low);
    border-radius: 10px;
}
.blog-toolbar button {
    min-width: 32px;
    height: 32px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.blog-toolbar button:hover { background: var(--surface); color: var(--heading); }
.blog-toolbar-sep { width: 1px; background: var(--border); margin: 4px 6px; }
.blog-canvas {
    min-height: 360px;
    padding: 12px;
    border-radius: 10px;
    outline: none;
    line-height: 1.8;
}
.blog-canvas:focus { background: var(--surface-low); }
.blog-author-box { display: flex; align-items: center; gap: 10px; padding: 8px; background: var(--surface-low); border-radius: 10px; }
.blog-author-box .blog-avatar { width: 36px; height: 36px; }
.blog-author-box span { display: flex; flex-direction: column; }
.blog-schedule { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.blog-schedule button {
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: var(--surface-low);
    color: var(--heading);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.blog-schedule button.is-active { background: var(--primary); color: #fff; }
.blog-share-preview > div { background: var(--surface-low); border-radius: 10px; padding: 12px; }
.blog-share-brand { color: var(--primary); font-size: 12px; font-weight: 700; }
.blog-share-preview strong { display: block; margin: 4px 0; }
.blog-share-preview p { margin: 0; color: var(--muted); }

.blog-public { padding-bottom: 48px; }
.blog-public-head { margin: 28px 0 24px; }
.blog-public-head .mk-eyebrow, .blog-eyebrow {
    display: block;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .04em;
    margin-bottom: 6px;
}
.blog-public-head h1, .blog-public-head h2 { margin: 0; }
.blog-public-tools { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.blog-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.blog-pills a {
    padding: 6px 12px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--muted);
    font-weight: 600;
}
.blog-pills a.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.blog-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.blog-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-1);
    min-height: 100%;
}
.blog-card:hover { box-shadow: var(--shadow-2); }
.blog-card-cover { position: relative; height: 200px; background: var(--surface-low); }
.blog-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.blog-card-cover .blog-chip { position: absolute; top: 10px; right: 10px; background: rgba(255,255,255,.92); color: var(--primary); }
.blog-card-body { padding: 18px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.blog-card-meta { color: var(--faint); font-size: 12px; display: flex; gap: 8px; }
.blog-card h3 { font-size: 18px; line-height: 26px; margin: 0; }
.blog-card h3 a { color: var(--heading); }
.blog-card p { margin: 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.blog-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 8px; }
.blog-card-more { font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.blog-cta {
    margin-top: 48px;
    padding: 40px 24px;
    border-radius: 24px;
    background: linear-gradient(135deg, #30198e, #6c31f5);
    color: #fff;
    text-align: center;
}
.blog-cta h2 { color: #fff; }
.blog-cta p { color: #e8ddff; max-width: 36rem; margin: 8px auto 20px; }
.blog-cta .actions { justify-content: center; }
.blog-cta .btn { background: #fff; color: #5300d7; box-shadow: none; }
.blog-cta .btn.secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }

.blog-article-title { font-size: 36px; line-height: 46px; max-width: 52rem; }
.blog-article-lede { font-size: 16px; line-height: 26px; color: var(--muted); max-width: 46rem; }
.blog-byline {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    margin: 20px 0 24px;
}
.blog-share { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.blog-share button, .blog-share a {
    min-width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: var(--surface-low);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 10px;
    font: inherit;
    cursor: pointer;
}
.blog-hero-cover {
    border-radius: 24px;
    overflow: hidden;
    margin-bottom: 32px;
    background: var(--surface-mid);
}
.blog-hero-cover img { width: 100%; aspect-ratio: 21 / 9; object-fit: cover; display: block; }
.blog-article-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr); gap: 32px; align-items: start; }
.blog-article-body { font-size: 17px; line-height: 1.85; color: var(--muted); }
.blog-article-body h2 { color: var(--heading); margin: 28px 0 12px; }
.blog-article-body h3 { color: var(--heading); margin: 20px 0 8px; }
.blog-article-body blockquote {
    margin: 20px 0;
    padding: 8px 16px;
    border-right: 4px solid var(--primary);
    background: var(--primary-subtle);
    border-radius: 0 12px 12px 0;
    color: var(--heading);
    font-style: italic;
}
.blog-toc, .blog-related-side {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 18px;
    box-shadow: var(--shadow-1);
}
.blog-toc { position: sticky; top: 96px; }
.blog-toc a, .blog-related-side a { display: block; color: var(--muted); padding: 6px 8px; border-radius: 10px; }
.blog-toc a:hover, .blog-related-side a:hover { background: var(--surface-low); color: var(--primary); }
.blog-related-item { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.blog-related-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; background: var(--surface-low); }
.blog-recent { margin-top: 48px; padding: 40px 0; background: var(--surface-low); border-radius: 24px; }
.blog-progress {
    position: sticky;
    top: 0;
    height: 3px;
    background: var(--surface-mid);
    z-index: 30;
}
.blog-progress > i { display: block; height: 100%; width: 0; background: var(--primary); }
.blog-preview-banner {
    background: var(--warn-bg);
    color: var(--warn);
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-weight: 600;
}

@media (max-width: 1023px) {
    .menu-btn { display: inline-flex; align-items: center; }
    .sidebar { transform: translateX(110%); transition: transform .2s ease; }
    .sidebar.open { transform: none; }
    .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(26, 16, 60, .45); z-index: 30; }
    .workspace { margin-right: 0; }
    .workspace:has(.chat-shell) {
        height: 100svh;
        max-height: 100svh;
        min-height: 0;
    }
    .header { padding: 0 16px; }
    .header-chip { display: none; }
    .header-search { max-width: none; }
    .main { padding: 16px; }
    .main:has(.chat-shell) { padding: 0; }
    .chat-shell {
        grid-template-columns: 1fr;
        position: relative;
        min-height: 0;
        height: 100%;
    }
    .chat-stage { height: 100%; min-height: 0; }
    .chat-composer .faint { display: none; }
    .chat-composer {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
    .chat-mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
        background: var(--surface);
        flex-shrink: 0;
    }
    .chat-rail-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(26, 16, 60, 0.4);
        z-index: 28;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    .chat-rail-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }
    .chat-rail {
        position: fixed;
        top: var(--header);
        right: 0;
        bottom: 0;
        width: min(320px, 88vw);
        max-height: none;
        border-left: 0;
        border-bottom: 0;
        z-index: 29;
        transform: translateX(110%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-2);
    }
    .chat-rail.open { transform: none; }
    .chat-composer-row { flex-wrap: nowrap; }
    .chat-thread .bubble { max-width: 94%; }
    .page-head, .grid-3, .grid-4, .form-grid, .blog-editor-grid, .blog-article-grid, .blog-cards, .dash-split { display: grid; grid-template-columns: 1fr; }
    .dash-hero { flex-direction: column; align-items: stretch; }
    .blog-article-title { font-size: 28px; line-height: 36px; }
    .blog-toc { position: static; }
    .hero { padding-top: 36px; }
    .hero .brand-hero .brand-name { font-size: 30px; }
    .hero .brand-hero img { width: 56px; height: 56px; }
    .hero h1 { font-size: 26px; line-height: 34px; }
    .guest-top, .topbar { flex-wrap: wrap; }
    table { min-width: 520px; }
}
