:root {
    --bg: #0b1220;
    --bg-soft: #121a2b;
    --surface: #162033;
    --surface-2: #1c2940;
    --ink: #e8eef9;
    --muted: #93a0b8;
    --line: rgba(148, 163, 184, 0.18);
    --primary: #1f9d8a;
    --primary-ink: #041512;
    --secondary: #3d7ea6;
    --accent: #e2a35a;
    --danger: #d45d5d;
    --success: #3caf73;
    --shadow: 0 20px 50px rgba(2, 8, 23, 0.35);
    --radius: 18px;
    --font: "Vazirmatn", sans-serif;
    --sidebar-w: 280px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 8%, rgba(31, 157, 138, 0.18), transparent 34%),
        radial-gradient(circle at 88% 0%, rgba(61, 126, 166, 0.16), transparent 30%),
        linear-gradient(165deg, #0a101c 0%, #101827 48%, #0d1524 100%);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    min-height: 100vh;
}

.login-shell { width: min(420px, 100%); }

.login-card {
    background: color-mix(in srgb, var(--surface) 88%, white 4%);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: 28px;
    padding: 32px;
}

.brand {
    margin: 0;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--primary);
}

.eyebrow {
    margin: 0;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 600;
}

h1, h2 {
    margin: 8px 0 0;
    font-weight: 700;
}

.muted { color: var(--muted); margin: 8px 0 0; }

.stack { display: grid; gap: 16px; }

label {
    display: grid;
    gap: 8px;
    font-size: 0.92rem;
}

input, textarea, select, button {
    font: inherit;
}

input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--ink);
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    flex-shrink: 0;
}

textarea { resize: vertical; }

.btn {
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    cursor: pointer;
    transition: transform .15s ease, opacity .15s ease, background .15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover { transform: translateY(-1px); }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }
.btn-primary { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
}
.btn-danger { background: var(--danger); color: #fff; }

.admin-frame {
    direction: ltr;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    direction: rtl;
    background: linear-gradient(180deg, #152338 0%, #0e1726 100%);
    border-left: 1px solid var(--line);
    z-index: 40;
}

.sidebar-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 18px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 8px;
}

.sidebar-logo {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #041512;
    background: linear-gradient(145deg, #2bd4b7, #1f9d8a);
    box-shadow: 0 8px 20px rgba(31, 157, 138, 0.28);
}

.sidebar-brand-text {
    min-width: 0;
}

.sidebar-brand .brand {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: none;
    white-space: nowrap;
}

.sidebar-tagline {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.sidebar-section-label {
    margin: 0;
    padding: 0 10px;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6f7d96;
    font-weight: 600;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 12px 14px;
    border-radius: 16px;
    color: var(--muted);
    border: 1px solid transparent;
    background: transparent;
    transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}

.nav-link:hover {
    background: rgba(255,255,255,0.04);
    color: var(--ink);
    transform: translateX(-2px);
}

.nav-link.active {
    background: rgba(31, 157, 138, 0.14);
    color: #d7fff6;
    border-color: rgba(31, 157, 138, 0.35);
    box-shadow: inset 3px 0 0 #1f9d8a;
}

.nav-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.06);
    color: inherit;
}

.nav-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.nav-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: inherit;
    line-height: 1.3;
}

.nav-hint {
    font-size: 0.75rem;
    color: #8090aa;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-link.active .nav-hint {
    color: rgba(184, 243, 232, 0.75);
}

.sidebar-foot {
    display: grid;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 2px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    flex: 0 0 36px;
    background: rgba(61, 126, 166, 0.25);
    border: 1px solid rgba(61, 126, 166, 0.35);
    font-weight: 700;
}

.sidebar-user-meta {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--muted);
}

.btn-block {
    width: 100%;
}

.sidebar-logout {
    margin: 0;
}

.admin-main {
    min-width: 0;
    direction: rtl;
    padding: 24px;
}

.mobile-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-content {
    width: min(1100px, 100%);
    margin: 0 auto;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 20px;
}

.user-chip {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.9rem;
    display: inline-flex;
    width: fit-content;
}

#custom-model-wrap.is-hidden {
    display: none !important;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.tab {
    border: 1px solid var(--line);
    background: transparent;
    border-radius: 999px;
    padding: 10px 16px;
    cursor: pointer;
    color: var(--muted);
}

.tab.active {
    background: var(--ink);
    color: #0b1220;
    border-color: var(--ink);
}

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 18px; }

.panel {
    background: color-mix(in srgb, var(--surface) 92%, white 3%);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    padding: 22px;
}

.panel-head { margin-bottom: 8px; }

.egg-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.egg-card, .toggles {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    background: rgba(255,255,255,0.03);
}

.egg-card legend, .toggles legend {
    padding: 0 8px;
    font-weight: 600;
}

.toggles {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    white-space: nowrap;
    margin: 0;
}

.check input { width: auto; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.alert {
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 16px;
}

.alert-success { background: rgba(60, 175, 115, 0.15); color: #8ee0b2; }
.alert-error { background: rgba(212, 93, 93, 0.16); color: #ffb4b4; }

.preview-panel { background: #0a0f18; color: #f3f6fb; }
.preview-panel .muted { color: #9eabbf; }
.preview-canvas { display: grid; gap: 16px; }
.preview-publish,
.preview-publish-hint {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.preview-heading { font-weight: 700; margin-bottom: 8px; }
.preview-photo img,
.preview-gallery img {
    width: 100%;
    object-fit: cover;
    border-radius: 10px;
}
.preview-photo img {
    max-height: 280px;
    border-radius: 14px;
}
.preview-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow: hidden;
    border-radius: 14px;
}
.preview-gallery.is-single {
    grid-template-columns: 1fr;
}
.preview-gallery.is-single img {
    max-height: 280px;
    border-radius: 14px;
}
.preview-gallery[data-count="3"] img:first-child {
    grid-column: 1 / -1;
    max-height: 200px;
}
.preview-gallery img {
    height: 150px;
}
.preview-gallery.preview-gallery-slideshow {
    display: flex;
    grid-template-columns: none;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 8px;
    padding-bottom: 4px;
}
.preview-gallery.preview-gallery-slideshow img {
    flex: 0 0 78%;
    height: 220px;
    scroll-snap-align: start;
    border-radius: 14px;
}
.preview-html {
    line-height: 1.7;
    white-space: normal;
}
.preview-caption { margin-top: 8px; opacity: 0.9; }
.preview-block blockquote {
    margin: 0;
    padding: 12px 14px;
    border-right: 3px solid var(--accent);
    background: rgba(255,255,255,0.06);
    border-radius: 10px;
}
.preview-details {
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.04);
}
.preview-details > summary {
    cursor: pointer;
    list-style: none;
    margin-bottom: 0;
}
.preview-details[open] > summary {
    margin-bottom: 10px;
}
.preview-details > summary::-webkit-details-marker {
    display: none;
}
.preview-details > summary::before {
    content: "▸ ";
    color: var(--accent);
}
.preview-details[open] > summary::before {
    content: "▾ ";
}
.preview-footer {
    opacity: 0.85;
    border-top: 1px dashed rgba(255,255,255,0.15);
    padding-top: 12px;
}
.preview-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 12px;
}
.preview-table th, .preview-table td {
    border: 1px solid rgba(255,255,255,0.12);
    padding: 10px;
    text-align: center;
}
.preview-table th { background: rgba(255,255,255,0.08); }
.preview-table.is-striped tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.04);
}

.preview-table caption {
    caption-side: bottom;
    padding-top: 8px;
    color: #9eabbf;
    font-size: 0.85rem;
}

.preview-canvas .cc-kb-preview-wrap {
    margin-top: 8px;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .data-table td {
    border-bottom: 1px solid var(--line);
    padding: 12px 8px;
    text-align: right;
    vertical-align: top;
}

.inline-edit {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
    gap: 8px;
    margin-bottom: 8px;
}

.inline-delete { display: inline-block; }

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.pred-field[hidden],
.history-field[hidden],
.history-col[hidden],
.pred-field.is-hidden,
.history-field.is-hidden,
.history-col.is-hidden,
#manual-channel-wrap.is-hidden {
    display: none !important;
}

.labels-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.mode-switch {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-chip {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 10px 16px;
    color: var(--muted);
}

.mode-chip.active {
    background: rgba(226, 163, 90, 0.18);
    border-color: rgba(226, 163, 90, 0.45);
    color: #f3d2a4;
}

.image-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.thumb {
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: rgba(255,255,255,0.03);
}

.thumb img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}

.thumb form {
    padding: 8px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.stat {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: rgba(255,255,255,0.03);
}

.stat-label {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-bottom: 6px;
}

.EasyMDEContainer .CodeMirror {
    background: var(--bg-soft);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.EasyMDEContainer .editor-toolbar {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
}

.EasyMDEContainer .editor-toolbar a {
    color: var(--ink) !important;
}

.sidebar-backdrop {
    display: none;
}

body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 30;
}

@media (max-width: 980px) {
    .admin-frame {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: auto;
        width: min(88vw, var(--sidebar-w));
        transform: translateX(105%);
        transition: transform .2s ease;
        box-shadow: var(--shadow);
        border-left: 1px solid var(--line);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .mobile-bar { display: flex; }

    .egg-grid,
    .grid-form,
    .inline-edit,
    .labels-grid,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .page-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .cc-table-card-head,
    .cc-builder-section-head {
        flex-direction: column;
        align-items: flex-start;
    }
}

.cc-builder {
    display: grid;
    gap: 14px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
}

.cc-builder-list {
    display: grid;
    gap: 14px;
}

.cc-builder-empty {
    margin: 0;
}

.cc-table-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.03);
    display: grid;
    gap: 14px;
}

.cc-table-card-head,
.cc-builder-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.cc-builder-section {
    display: grid;
    gap: 8px;
}

.cc-builder-checks {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    min-height: 100%;
}

.cc-builder-checks .check[hidden] {
    display: none !important;
}

.cc-builder-grid input,
.cc-builder-grid select {
    padding: 8px 10px;
}

.cc-builder-grid th:last-child,
.cc-builder-grid td:last-child {
    width: 1%;
    white-space: nowrap;
}

.cc-kb-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.cc-kb-button-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: rgba(11, 18, 32, 0.35);
    display: grid;
    gap: 10px;
}

.cc-kb-button-card [hidden],
.cc-kb-preview-wrap[hidden] {
    display: none !important;
}

.cc-kb-preview-wrap {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px dashed var(--line);
    border-radius: 14px;
    background: #0a0f18;
}

.cc-kb-preview {
    display: grid;
    gap: 8px;
}

.cc-kb-preview-row {
    display: flex;
    gap: 8px;
}

.cc-kb-preview-btn {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.88rem;
    font-weight: 600;
}

.cc-kb-preview-btn.style-primary {
    background: #1d4f91;
    border-color: #2d6cbd;
    color: #fff;
}

.cc-kb-preview-btn.style-success {
    background: #1f7a4d;
    border-color: #2e9a64;
    color: #fff;
}

.cc-kb-preview-btn.style-danger {
    background: #a33b3b;
    border-color: #c45454;
    color: #fff;
}
