:root {
    --bg-primary: #0d0d0f;
    --bg-secondary: #18181b;
    --bg-card: #1e1e24;
    --bg-input: #27272d;
    --border: #2e2e35;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-soft: rgba(139, 92, 246, 0.12);
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --instagram-gradient: linear-gradient(45deg, #833ab4, #fd1d1d, #fcb045);
    --shadow-soft: 0 18px 50px rgba(0, 0, 0, 0.28);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --color-primary-500: #8b5cf6;
    --color-primary-400: #a78bfa;
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(139, 92, 246, 0.18), transparent 22%),
        radial-gradient(circle at bottom left, rgba(253, 29, 29, 0.1), transparent 25%),
        var(--bg-primary);
    color: var(--text-primary);
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.guest-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 16px 24px;
}

.auth-shell {
    width: min(1160px, 100%);
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 28px;
}

.auth-shell-register {
    max-width: 860px;
    grid-template-columns: 1fr;
}

.auth-panel {
    background: rgba(24, 24, 27, 0.9);
    border: 1px solid var(--border);
    border-radius: 32px;
    box-shadow: var(--shadow-soft);
}

.auth-panel-brand {
    padding: 32px 38px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent),
        radial-gradient(circle at top left, rgba(139, 92, 246, 0.22), transparent 30%),
        var(--bg-secondary);
}

.brand-mark,
.brand-lockup {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-size: 1.05rem;
    font-weight: 700;
}

.brand-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--instagram-gradient);
    box-shadow: 0 0 0 6px var(--accent-soft);
}

.auth-panel-brand h1 {
    max-width: 14ch;
    font-size: clamp(1.6rem, 2.8vw, 2.6rem);
    line-height: 1.1;
    margin: 16px 0;
}

.auth-panel-brand p,
.auth-panel-form p,
.note-box p,
.empty-state p {
    color: var(--text-secondary);
    line-height: 1.7;
}

.auth-stats {
    display: grid;
    gap: 10px;
}

.auth-stat-card,
.note-box {
    padding: 12px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03);
}

.auth-stat-card strong {
    display: block;
    margin-bottom: 6px;
}

.auth-panel-form {
    padding: 32px 36px;
    display: grid;
    align-items: center;
}

.auth-panel-form-wide {
    max-width: 680px;
    margin-inline: auto;
}

.auth-form-wrap {
    max-width: 460px;
    width: 100%;
    margin: 0 auto;
}

.auth-form-wrap h2,
.section-title-row h1,
.section-title-row h2 {
    margin: 0 0 8px;
    font-size: clamp(1.6rem, 2vw, 2.1rem);
}

.panel-form {
    display: grid;
    gap: 14px;
    margin-top: 24px;
}

.panel-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel-form-grid button {
    grid-column: 1 / -1;
}

label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.94rem;
    margin-bottom: 2px;
}

input,
textarea,
select {
    width: 100%;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

textarea {
    resize: vertical;
    min-height: 120px;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 48px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 14px;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.button:hover,
.card:hover,
.template-card:hover {
    transform: translateY(-2px);
}

.button-primary {
    background: var(--accent);
    color: #fff;
}

.button-primary:hover {
    background: var(--accent-hover);
}

.button-secondary {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
    border-color: var(--border);
}

.button-secondary:hover {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.08);
}

.button-danger {
    background: rgba(239, 68, 68, 0.12);
    color: #fff;
    border-color: rgba(239, 68, 68, 0.2);
}

.button-block {
    width: 100%;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.auth-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 20px;
    color: var(--text-secondary);
}

.auth-meta a,
.text-link {
    color: #d9ccff;
}

.app-shell {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px 18px;
    background: rgba(24, 24, 27, 0.88);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(20px);
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 16px;
    color: var(--text-secondary);
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.sidebar-link svg,
.sidebar-toggle svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.sidebar-link:hover,
.sidebar-link.active {
    background: var(--accent-soft);
    color: var(--text-primary);
}

.sidebar-bottom {
    display: grid;
    gap: 12px;
}

.user-card {
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.user-card span {
    display: block;
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.content-shell {
    min-width: 0;
    width: 100%;
    max-width: calc(100vw - 250px);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px 32px 0;
}

.breadcrumb {
    display: inline-flex;
    gap: 10px;
    align-items: center;
    padding: 12px 16px;
    border: 1px solid var(--border);
    background: rgba(24, 24, 27, 0.74);
    border-radius: 16px;
}

.breadcrumb span {
    color: var(--text-muted);
}

.sidebar-toggle {
    display: none;
    width: 48px;
    height: 48px;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.sidebar-toggle-inline {
    display: none;
}

.main-content {
    padding: 24px 20px 32px;
    min-width: 0;
}

.page-grid {
    display: grid;
    gap: 24px;
    min-width: 0;
}

.page-grid-dashboard {
    grid-template-columns: 1fr;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
}

.card,
.template-card {
    background: rgba(30, 30, 36, 0.92);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    min-width: 0;
    overflow: hidden;
}

.card:hover,
.template-card:hover {
    border-color: rgba(139, 92, 246, 0.35);
    background: rgba(34, 34, 40, 0.94);
}

.hero-card {
    display: grid;
    grid-template-columns: 1.2fr auto;
    gap: 24px;
    align-items: end;
    overflow: hidden;
    position: relative;
}

.hero-card::after {
    content: "";
    position: absolute;
    inset: auto -40px -50px auto;
    width: 240px;
    height: 240px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.22), transparent 70%);
    pointer-events: none;
}

.eyebrow {
    display: inline-block;
    margin-bottom: 10px;
    color: #d4c6ff;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.76rem;
}

.hero-card h1 {
    max-width: 18ch;
    font-size: clamp(2.2rem, 4vw, 3.5rem);
    line-height: 1.02;
    margin: 0 0 12px;
}

.hero-card p {
    max-width: 68ch;
    color: var(--text-secondary);
    margin: 0;
}

.hero-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.stat-card span,
.info-list span,
.meta-grid dt {
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.stat-card strong {
    display: block;
    margin: 10px 0 6px;
    font-size: 2.2rem;
}

.stat-card small,
.meta-grid dd,
.info-list strong {
    color: var(--text-primary);
}

.split-card,
.page-grid-settings,
.page-grid-templates,
.page-grid-logs {
    grid-template-columns: 1fr;
    max-width: 100%;
}

.section-title-row {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin: 0;
}

.meta-grid div,
.info-list div {
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.meta-grid dd {
    margin: 8px 0 0;
    word-break: break-all;
    overflow-wrap: break-word;
}

.info-list {
    display: grid;
    gap: 14px;
}

.empty-state {
    padding: 18px 0 4px;
}

.template-list {
    display: grid;
    gap: 16px;
}

.template-card {
    padding: 20px;
}

.template-card-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.template-card h3 {
    margin: 0 0 8px;
}

.template-scope {
    color: #d6c8ff;
}

.checkbox-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 6px;
}

.checkbox-row input {
    width: auto;
    accent-color: var(--accent);
}

.toolbar-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: end;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

th,
td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: middle;
    font-size: 0.78rem;
    overflow: hidden;
}

/* Specific column widths for logs */
.page-grid-logs th:nth-child(1), .page-grid-logs td:nth-child(1) { width: 30px; min-width: 30px; }
.page-grid-logs th:nth-child(2), .page-grid-logs td:nth-child(2) { min-width: 80px; }
.page-grid-logs th:nth-child(3), .page-grid-logs td:nth-child(3) { min-width: 80px; }
.page-grid-logs th:nth-child(4), .page-grid-logs td:nth-child(4) { width: 100px; min-width: 100px; font-family: monospace; font-size: 0.7rem; }
.page-grid-logs th:nth-child(5), .page-grid-logs td:nth-child(5),
.page-grid-logs th:nth-child(6), .page-grid-logs td:nth-child(6) { 
    min-width: 120px; 
    max-width: 200px;
    white-space: normal; 
    line-height: 1.3;
    word-break: break-word;
}
.page-grid-logs th:nth-child(7), .page-grid-logs td:nth-child(7) { min-width: 70px; }
.page-grid-logs th:nth-child(8), .page-grid-logs td:nth-child(8) { min-width: 70px; }
.page-grid-logs th:nth-child(9), .page-grid-logs td:nth-child(9) { min-width: 100px; font-size: 0.7rem; }

@media (max-width: 1300px) {
    .page-grid-logs th:nth-child(4), .page-grid-logs td:nth-child(4),
    .page-grid-logs th:nth-child(8), .page-grid-logs td:nth-child(8) {
        display: none;
    }
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}


.table-wrap td.expandable {
    white-space: normal;
    word-break: break-word;
}

th {
    color: var(--text-secondary);
    font-size: 0.86rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 84px;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 0.82rem;
    text-transform: capitalize;
}

.status-success {
    background: rgba(34, 197, 94, 0.14);
    color: #8cf7ae;
}

.status-failed {
    background: rgba(239, 68, 68, 0.14);
    color: #ff9f9f;
}

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1200;
    display: grid;
    gap: 12px;
    width: min(360px, calc(100vw - 32px));
}

.toast {
    display: grid;
    gap: 8px;
    padding: 16px 18px;
    border-radius: 18px;
    background: rgba(24, 24, 27, 0.96);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    transform: translateX(24px);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.toast.is-visible {
    transform: translateX(0);
    opacity: 1;
}

.toast.is-leaving {
    transform: translateX(30px);
    opacity: 0;
}

.toast-success {
    border-color: rgba(34, 197, 94, 0.3);
}

.toast-error {
    border-color: rgba(239, 68, 68, 0.34);
}

.toast-warning {
    border-color: rgba(245, 158, 11, 0.34);
}

.toast-info {
    border-color: rgba(139, 92, 246, 0.34);
}

.toast-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

.toast-message {
    color: var(--text-primary);
    line-height: 1.5;
}

@media (max-width: 1080px) {
    .auth-shell,
    .hero-card,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(290px, 84vw);
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 40;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-toggle,
    .sidebar-toggle-inline {
        display: inline-flex;
    }

    .topbar {
        padding-inline: 20px;
    }

    .main-content {
        padding-inline: 20px;
    }
}

@media (max-width: 720px) {
    .guest-body,
    .auth-panel-brand,
    .auth-panel-form,
    .main-content {
        padding: 20px;
    }

    .panel-form-grid,
    .meta-grid,
    .toolbar-form {
        grid-template-columns: 1fr;
    }

    .template-card-head,
    .section-title-row,
    .auth-meta {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.is-open {
    display: flex;
    opacity: 1;
}

.modal-container {
    width: min(720px, 100%);
    max-height: 90vh;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal.is-open .modal-container {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: background 0.2s ease, color 0.2s ease;
}

.modal-close:hover {
    background: var(--danger);
    color: #fff;
}

.modal-close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Post Selector Grid */
.post-selector-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-top: 8px;
}

.post-selector-item {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.1);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    background: #1a1a1a;
}

.post-selector-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.post-selector-item.is-selected {
    border-color: var(--color-primary-500);
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
    transform: scale(1.02);
}

.post-selector-item .post-type-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    padding: 6px;
    border-radius: 6px;
    line-height: 0;
    backdrop-filter: blur(4px);
}

.post-selector-item:hover {
    border-color: rgba(255,255,255,0.3);
}

/* Robust Pagination Design */
#visual-selector-container .post-pagination {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 32px !important;
    margin: 32px auto 10px !important;
    padding: 10px 24px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border-radius: 100px !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    backdrop-filter: blur(20px) !important;
    width: fit-content !important;
    box-shadow: 
        0 15px 35px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.05) !important;
    animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
}

#visual-selector-container .post-pagination button {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    height: 44px !important;
    background: rgba(255, 255, 255, 0.06) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    padding: 0 !important;
}

#visual-selector-container .post-pagination button:hover:not(:disabled) {
    background: var(--accent) !important;
    border-color: var(--color-primary-400) !important;
    transform: scale(1.1) translateY(-2px) !important;
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.5) !important;
}

#visual-selector-container .post-pagination button:disabled {
    opacity: 0.2 !important;
    cursor: not-allowed !important;
}

#visual-selector-container .post-pagination button svg {
    width: 24px !important;
    height: 24px !important;
    fill: currentColor !important;
    display: block !important;
}

#visual-selector-container .post-pagination-info {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    min-width: 100px !important;
}

#visual-selector-container .post-pagination-info .label {
    font-size: 11px !important;
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    text-transform: uppercase !important;
    letter-spacing: 2px !important;
    margin-bottom: 2px !important;
    opacity: 0.7 !important;
}

#visual-selector-container .post-pagination-numbers {
    display: flex !important;
    align-items: baseline !important;
    gap: 6px !important;
    font-family: 'Inter', system-ui, sans-serif !important;
}

#visual-selector-container #post-page-current {
    font-size: 20px !important;
    font-weight: 800 !important;
    color: #fff !important;
}

#visual-selector-container .separator {
    font-size: 16px !important;
    color: var(--text-muted) !important;
    font-weight: 300 !important;
}

#visual-selector-container #post-page-total {
    font-size: 16px !important;
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
/* Wizard Styles */
.wizard-steps { position: relative; margin-top: 24px; }
.wizard-step { display: none; animation: wizardFadeIn 0.4s ease forwards; }
.wizard-step.is-active { display: block; }
@keyframes wizardFadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.step-indicator { display: flex; justify-content: space-between; margin-bottom: 48px; position: relative; padding: 0 40px; }
.step-indicator::before { content: ''; position: absolute; top: 50%; left: 80px; right: 80px; height: 2px; background: var(--border); z-index: 1; transform: translateY(-50%); }
.step-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-card); border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--text-muted); position: relative; z-index: 2; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.step-dot.is-active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 15px var(--accent-soft); background: var(--bg-secondary); transform: scale(1.1); }
.step-dot.is-complete { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-label { position: absolute; top: 40px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 600; }
.step-dot.is-active .step-label { color: var(--text-primary); }
.wizard-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); }
