:root {
    --bg: #080b18;
    --panel: rgba(255,255,255,.08);
    --panel-strong: rgba(255,255,255,.12);
    --stroke: rgba(255,255,255,.16);
    --text-muted: #aab3c7;
    --accent: #42a5ff;
    --accent-2: #8b5cf6;
    --success: #34d399;
    --danger: #fb7185;
}

* { box-sizing: border-box; }
body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(66,165,255,.25), transparent 34rem),
        linear-gradient(135deg, #080b18 0%, #10142a 48%, #26164a 100%);
    color: #f8fafc;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a { color: inherit; }
.form-select option,
select option {
    color: #111827;
    background: #ffffff;
}
.auth-body {
    display: grid;
    place-items: center;
    padding: 1rem;
}
.auth-card,
.glass-card,
.table-wrap,
.stat-card {
    background: var(--panel);
    border: 1px solid var(--stroke);
    box-shadow: 0 24px 80px rgba(0,0,0,.28);
    backdrop-filter: blur(18px);
}
.auth-card {
    width: min(100%, 460px);
    border-radius: 8px;
    padding: 2rem;
}
.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-weight: 800;
    line-height: 1.05;
}
.brand small {
    color: var(--text-muted);
    font-weight: 600;
}
.brand-icon {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.app-shell {
    display: grid;
    grid-template-columns: 270px 1fr;
    min-height: 100vh;
}
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.25rem;
    border-right: 1px solid var(--stroke);
    background: rgba(4,8,20,.72);
    backdrop-filter: blur(18px);
}
.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    border-radius: 8px;
    color: var(--text-muted);
    padding: .8rem .9rem;
}
.sidebar .nav-link.active,
.sidebar .nav-link:hover {
    color: #fff;
    background: var(--panel-strong);
}
.content {
    padding: 1.5rem;
    max-width: 1500px;
    width: 100%;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.topbar h1 {
    margin: 0;
    font-size: clamp(1.45rem, 3vw, 2.4rem);
    font-weight: 800;
}
.eyebrow {
    color: #90c8ff;
    text-transform: uppercase;
    font-size: .76rem;
    letter-spacing: .08em;
    font-weight: 700;
}
.admin-chip {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .65rem .8rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: var(--panel);
    white-space: nowrap;
}
.stat-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 1rem;
}
.stat-card,
.glass-card {
    border-radius: 8px;
    padding: 1rem;
}
.stat-card .icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(66,165,255,.9), rgba(139,92,246,.9));
}
.stat-card strong {
    display: block;
    margin-top: .75rem;
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    line-height: 1;
}
.stat-card span,
.muted {
    color: var(--text-muted);
}
.stat-card span {
    display: block;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(300px, .9fr);
    gap: 1rem;
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}
.table-wrap {
    border-radius: 8px;
    overflow: hidden;
}
.table {
    margin: 0;
    --bs-table-bg: transparent;
    --bs-table-color: #f8fafc;
    --bs-table-border-color: rgba(255,255,255,.1);
}
.table td,
.table th {
    vertical-align: middle;
}
.form-control,
.form-select,
.form-control:focus,
.form-select:focus {
    background: rgba(255,255,255,.08);
    color: #fff;
    border-color: var(--stroke);
}
.form-control::placeholder {
    color: #77829a;
}
.btn-primary {
    --bs-btn-bg: #367dff;
    --bs-btn-border-color: #367dff;
    --bs-btn-hover-bg: #2568df;
    --bs-btn-hover-border-color: #2568df;
}
.badge-soft {
    background: rgba(52,211,153,.15);
    color: var(--success);
    border: 1px solid rgba(52,211,153,.28);
}
.badge-disabled {
    background: rgba(251,113,133,.15);
    color: var(--danger);
    border: 1px solid rgba(251,113,133,.28);
}
.chart-box {
    height: auto;
    min-height: 0;
    overflow: hidden;
    position: relative;
}
.chart-frame {
    position: relative;
    height: 260px !important;
    max-height: 260px !important;
    overflow: hidden;
}
.chart-box canvas {
    display: block;
    width: 100% !important;
    height: 260px !important;
    max-height: 260px !important;
}
.copy-input {
    min-width: 220px;
}
.glass-alert {
    border: 1px solid var(--stroke);
}
.utm-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .75rem;
}
.content-tabs {
    display: flex;
    gap: .25rem;
    border-bottom: 1px solid var(--stroke);
    overflow-x: auto;
}
.content-tab {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .8rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.content-tab.active,
.content-tab:hover {
    color: #fff;
    border-bottom-color: var(--accent);
}
.content-tab span {
    display: inline-grid;
    min-width: 24px;
    height: 22px;
    place-items: center;
    border-radius: 999px;
    background: rgba(255,255,255,.1);
    font-size: .75rem;
}
.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
}
.content-name-row,
.library-toolbar,
.content-actions,
.entry-actions {
    display: flex;
    gap: .65rem;
    flex-wrap: wrap;
}
.content-name-row input,
.search-wrap input {
    width: 100%;
    background: rgba(255,255,255,.08);
    color: #fff;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    padding: .75rem .9rem;
}
.content-name-row input {
    flex: 1 1 280px;
}
.content-name-row input:focus,
.search-wrap input:focus {
    outline: 0;
    border-color: var(--accent);
}
.content-panel,
.preview-section,
.entry-card {
    min-width: 0;
}
.panel-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: #90c8ff;
    font-weight: 800;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 1rem;
}
.field-group {
    margin-bottom: .9rem;
}
.field-group .form-label {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    color: var(--text-muted);
    font-size: .82rem;
}
.upload-zone {
    position: relative;
    display: block;
    text-align: center;
    border: 1.5px dashed var(--stroke);
    border-radius: 8px;
    padding: 2rem 1rem;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(66,165,255,.1);
}
.upload-zone input {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
    cursor: pointer;
}
.upload-icon {
    color: var(--text-muted);
    font-size: 2rem;
    margin-bottom: .5rem;
}
.upload-zone p {
    margin: 0;
}
.upload-zone small {
    color: var(--text-muted);
}
.poster-preview,
.preview-img {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    border-radius: 8px;
    margin-top: 1rem;
    background: rgba(0,0,0,.22);
}
.img-meta {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .75rem;
    flex-wrap: wrap;
}
.preview-section {
    background: var(--panel);
    border: 1px solid var(--stroke);
    border-radius: 8px;
    overflow: hidden;
}
.preview-top {
    padding: 1rem;
    border-bottom: 1px solid var(--stroke);
}
.preview-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.preview-left,
.preview-right {
    min-width: 0;
    padding: 1rem;
}
.preview-left {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    border-right: 1px solid var(--stroke);
}
.no-poster {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
}
.no-poster i {
    display: block;
    font-size: 2rem;
    margin-bottom: .5rem;
}
.preview-copy-output {
    min-height: 160px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.75;
}
.preview-empty {
    color: var(--text-muted);
    font-style: italic;
}
.library-toolbar {
    align-items: center;
}
.search-wrap {
    position: relative;
    flex: 1 1 260px;
}
.search-wrap i {
    position: absolute;
    left: .8rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
.search-wrap input {
    padding-left: 2.25rem;
}
.import-form,
.entry-actions form {
    margin: 0;
}
.entries-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
.entry-card {
    background: var(--panel);
    border: 1px solid var(--stroke);
    border-radius: 8px;
    overflow: hidden;
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
}
.entry-image-button {
    display: block;
    width: 170px;
    height: 170px;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: hidden;
}
.entry-card-img {
    display: block;
    width: 170px;
    height: 170px;
    object-fit: cover;
}
.entry-card-no-img {
    width: 170px;
    height: 110px;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    background: rgba(255,255,255,.06);
}
.entry-card-body {
    padding: 1rem;
}
.entry-title {
    font-size: 1rem;
    margin: 0 0 .3rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.entry-date {
    color: var(--text-muted);
    font-size: .78rem;
    margin-bottom: .75rem;
}
.entry-preview {
    color: #dbe4ff;
    white-space: pre-wrap;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    line-height: 1.55;
    margin-bottom: 1rem;
}
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
}
.empty-state i {
    display: block;
    font-size: 2.25rem;
    margin-bottom: .75rem;
}
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0,0,0,.88);
}
.lightbox.open {
    display: flex;
}
.lightbox img {
    max-width: 94vw;
    max-height: 92vh;
    border-radius: 8px;
}
.lightbox-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--stroke);
    background: rgba(255,255,255,.12);
    color: #fff;
}
.toast-lite {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: .5rem;
    max-width: calc(100vw - 2rem);
    padding: .75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--stroke);
    background: rgba(8,11,24,.94);
    color: #fff;
    opacity: 0;
    transform: translateY(.5rem);
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
.toast-lite.show {
    opacity: 1;
    transform: translateY(0);
}
.toast-lite i {
    color: var(--success);
}
.ai-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1rem;
    align-items: start;
}
.ai-workspace {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 300px;
    gap: 1rem;
    align-items: start;
}
.ai-session-panel {
    position: sticky;
    top: 1rem;
}
.ai-session-list {
    display: grid;
    gap: .5rem;
    max-height: 65vh;
    overflow: auto;
}
.ai-session-link {
    display: grid;
    gap: .2rem;
    padding: .7rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.05);
    text-decoration: none;
}
.ai-session-link.active {
    border-color: rgba(66,165,255,.55);
    background: rgba(66,165,255,.14);
}
.ai-session-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}
.ai-session-link small {
    color: var(--text-muted);
}
.folder-select {
    max-width: 280px;
}
.ai-chat-panel,
.ai-side {
    min-width: 0;
}
.ai-messages {
    display: flex;
    flex-direction: column;
    gap: .85rem;
    max-height: 58vh;
    overflow-y: auto;
    padding: .25rem;
}
.ai-empty {
    display: grid;
    place-items: center;
    gap: .45rem;
    min-height: 220px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.04);
}
.ai-empty i {
    color: #90c8ff;
    font-size: 2rem;
}
.ai-empty strong {
    color: #fff;
}
.ai-message {
    max-width: min(760px, 92%);
    border: 1px solid var(--stroke);
    border-radius: 8px;
    padding: .85rem;
    background: rgba(255,255,255,.06);
}
.ai-message.user {
    align-self: flex-end;
    background: rgba(66,165,255,.15);
}
.ai-message.assistant {
    align-self: flex-start;
}
.ai-message-meta {
    color: #90c8ff;
    font-size: .78rem;
    font-weight: 800;
    margin-bottom: .45rem;
}
.ai-message-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.65;
}
.ai-composer {
    border-top: 1px solid var(--stroke);
    padding-top: 1rem;
}
.ai-loading {
    display: grid;
    gap: .45rem;
    margin-bottom: 1rem;
    padding: .85rem;
    border: 1px solid rgba(45,212,255,.28);
    border-radius: 8px;
    background: rgba(45,212,255,.08);
}
.ai-loading[hidden] {
    display: none;
}
.ai-loading small {
    color: var(--text-muted);
}
.ai-loading-bar {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255,255,255,.1);
}
.ai-loading-bar span {
    display: block;
    width: 42%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2dd4ff, #8b5cf6);
    animation: ai-loading 1s ease-in-out infinite alternate;
}
.ai-terminal {
    overflow: hidden;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: #050814;
}
.ai-terminal-head {
    display: flex;
    gap: .5rem;
    align-items: center;
    padding: .65rem .85rem;
    border-bottom: 1px solid var(--stroke);
    color: #90c8ff;
    font-weight: 800;
}
.ai-terminal pre {
    min-height: 120px;
    max-height: 190px;
    margin: 0;
    padding: .85rem;
    overflow: auto;
    color: #d9f99d;
    font-size: .82rem;
    white-space: pre-wrap;
}
.provider-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .75rem;
    align-items: center;
    padding: .75rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
}
.provider-row span,
.provider-row small {
    display: block;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}
.coder-grid {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 360px;
    gap: 1rem;
    align-items: start;
}
.code-textarea {
    min-height: 520px;
    font-family: Consolas, Monaco, monospace;
    font-size: .9rem;
    line-height: 1.55;
}
.preview-frame {
    width: 100%;
    min-height: 680px;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: #fff;
}
.tool-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr);
    gap: 1rem;
    align-items: stretch;
}
.stat-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.score-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: .75rem;
}
.score-box {
    display: grid;
    gap: .25rem;
    padding: .9rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
}
.score-box span {
    color: var(--text-muted);
    font-size: .82rem;
}
.score-box strong {
    font-size: 1.7rem;
    line-height: 1;
}
.finding-list {
    display: grid;
    gap: .65rem;
}
.finding {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: .65rem;
    align-items: start;
    padding: .75rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
}
.finding.pass i {
    color: var(--success);
}
.finding.fail i {
    color: var(--danger);
}
.finding span {
    display: block;
    margin-top: .2rem;
    color: var(--text-muted);
}
.choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .6rem;
}
.choice-grid label {
    display: grid;
    grid-template-columns: 20px 1fr auto;
    gap: .55rem;
    align-items: center;
    min-height: 48px;
    padding: .7rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
}
.choice-grid strong {
    color: #90c8ff;
}
.pricing-total {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
}
.pricing-total div,
.package-box,
.quote-preview {
    padding: 1rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
}
.pricing-total span {
    color: var(--text-muted);
    display: block;
}
.pricing-total strong {
    font-size: 1.5rem;
}
@keyframes ai-loading {
    from { transform: translateX(-20%); }
    to { transform: translateX(160%); }
}

@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .ai-layout,
    .ai-workspace,
    .coder-grid,
    .tool-grid { grid-template-columns: 1fr; }
    .score-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--stroke);
    }
    .sidebar .nav {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }
    .sidebar .nav-link {
        min-height: 44px;
        padding: .7rem;
    }
    .content { padding: 1rem; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .stat-grid { grid-template-columns: 1fr; }
    .utm-row { grid-template-columns: 1fr; }
    .editor-grid,
    .preview-body {
        grid-template-columns: 1fr;
    }
    .preview-left {
        border-right: 0;
        border-bottom: 1px solid var(--stroke);
    }
    .content-name-row,
    .library-toolbar,
    .content-actions {
        align-items: stretch;
        flex-direction: column;
    }
    .content-name-row .btn,
    .library-toolbar .btn,
    .content-actions .btn,
    .import-form,
    .import-form label {
        width: 100%;
        justify-content: center;
    }
    .entries-grid {
        grid-template-columns: 1fr;
    }
    .entry-card {
        grid-template-columns: 1fr;
    }
    .entry-image-button,
    .entry-card-img,
    .entry-card-no-img {
        width: 100%;
        height: 190px;
    }
    .table-responsive { overflow-x: auto; }
    .chart-box { height: auto; }
    .chart-frame {
        height: 230px !important;
        max-height: 230px !important;
    }
    .chart-box canvas {
        height: 230px !important;
        max-height: 230px !important;
    }
    .ai-message {
        max-width: 100%;
    }
    .ai-messages {
        max-height: none;
    }
    .ai-session-panel {
        position: static;
    }
    .ai-session-list {
        max-height: 260px;
    }
    .score-row,
    .choice-grid,
    .pricing-total,
    .stat-grid.compact {
        grid-template-columns: 1fr;
    }
    .audit-form .input-group {
        display: grid;
        gap: .6rem;
    }
    .audit-form .input-group .btn,
    .audit-form .input-group .form-control {
        width: 100%;
        border-radius: 8px !important;
    }
}
@media (max-width: 420px) {
    .sidebar,
    .content {
        padding: .85rem;
    }
    .sidebar .nav {
        gap: .45rem;
    }
    .sidebar .nav-link {
        font-size: .9rem;
    }
    .topbar h1 {
        font-size: 1.55rem;
    }
    .stat-card,
    .glass-card,
    .content-panel,
    .preview-left,
    .preview-right,
    .entry-card-body {
        padding: .85rem;
    }
    .upload-zone {
        padding: 1.35rem .8rem;
    }
}
