:root {
    color-scheme: dark;
    --bg: #160919;
    --panel: rgba(41, 18, 49, .9);
    --panel-2: rgba(72, 30, 86, .72);
    --soft: rgba(255, 255, 255, .08);
    --line: rgba(255, 198, 233, .28);
    --text: #fff7fd;
    --muted: #f1b9d7;
    --accent: #ff5fb7;
    --accent-2: #70e5ff;
    --accent-3: #ffe66d;
    --button-text: #2b061d;
    --danger: #ff5268;
    --shadow: 0 22px 70px rgba(13, 3, 20, .36);
    --stripe: repeating-linear-gradient(135deg, rgba(255, 95, 183, .34) 0 12px, rgba(112, 229, 255, .24) 12px 24px, rgba(255, 230, 109, .24) 24px 36px);
}

body[data-theme="nebula"] {
    --bg: #08091c;
    --panel: rgba(21, 23, 62, .9);
    --panel-2: rgba(40, 44, 109, .72);
    --soft: rgba(255, 255, 255, .07);
    --line: rgba(159, 180, 255, .28);
    --text: #f4f7ff;
    --muted: #abb8ef;
    --accent: #8f7bff;
    --accent-2: #45e0ff;
    --accent-3: #ff7ad9;
    --button-text: #08091c;
    --stripe: repeating-linear-gradient(135deg, rgba(143, 123, 255, .34) 0 12px, rgba(69, 224, 255, .22) 12px 24px, rgba(255, 122, 217, .2) 24px 36px);
}

body[data-theme="mint"] {
    --bg: #061412;
    --panel: rgba(11, 39, 35, .92);
    --panel-2: rgba(16, 72, 64, .72);
    --soft: rgba(237, 255, 248, .07);
    --line: rgba(129, 255, 210, .26);
    --text: #f1fff9;
    --muted: #a7e9d1;
    --accent: #63f7bd;
    --accent-2: #9ae6ff;
    --accent-3: #f7f06a;
    --button-text: #052015;
    --stripe: repeating-linear-gradient(135deg, rgba(99, 247, 189, .32) 0 12px, rgba(154, 230, 255, .2) 12px 24px, rgba(247, 240, 106, .2) 24px 36px);
}

body[data-theme="sunset"] {
    --bg: #190a12;
    --panel: rgba(54, 20, 39, .92);
    --panel-2: rgba(96, 39, 62, .74);
    --soft: rgba(255, 245, 238, .08);
    --line: rgba(255, 188, 148, .3);
    --text: #fff8f2;
    --muted: #ffc5aa;
    --accent: #ff8a5b;
    --accent-2: #ff5fb7;
    --accent-3: #ffe66d;
    --button-text: #2d0a05;
    --stripe: repeating-linear-gradient(135deg, rgba(255, 138, 91, .34) 0 12px, rgba(255, 95, 183, .22) 12px 24px, rgba(255, 230, 109, .22) 24px 36px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(120deg, rgba(255, 255, 255, .035), transparent 34%),
        var(--stripe),
        var(--bg);
    background-blend-mode: screen, soft-light, normal;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .8), transparent 78%);
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(180deg, var(--panel-2), var(--soft));
    color: var(--text);
    padding: 10px 14px;
    cursor: pointer;
    transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

button:hover {
    transform: translateY(-1px);
    border-color: var(--accent-2);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .2);
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.primary-button {
    border-color: rgba(255, 255, 255, .45);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: var(--button-text);
    font-weight: 800;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel,
.panel {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 80%, black));
    box-shadow: var(--shadow);
    animation: panelIn .34s ease both;
}

.login-panel::before,
.panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 5px;
    background: var(--stripe);
    opacity: .85;
}

.login-panel {
    width: min(520px, 100%);
    padding: 30px;
}

.login-panel h1,
.topbar h1,
.panel h2 {
    margin: 0;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent-2);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.app-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 26px 0 44px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.identity {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(4, 30px);
    gap: 8px;
}

.theme-dot {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
}

.theme-dot:hover,
.theme-dot.active {
    transform: translateY(-2px) scale(1.04);
    border-color: rgba(255, 255, 255, .8);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, .09);
}

.theme-dot[data-theme-option="candy"] {
    background: conic-gradient(#ff5fb7, #70e5ff, #ffe66d, #ff5fb7);
}

.theme-dot[data-theme-option="nebula"] {
    background: conic-gradient(#8f7bff, #45e0ff, #ff7ad9, #8f7bff);
}

.theme-dot[data-theme-option="mint"] {
    background: conic-gradient(#63f7bd, #9ae6ff, #f7f06a, #63f7bd);
}

.theme-dot[data-theme-option="sunset"] {
    background: conic-gradient(#ff8a5b, #ff5fb7, #ffe66d, #ff8a5b);
}

.panel {
    padding: 18px;
    margin-bottom: 18px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-actions {
    display: flex;
    gap: 8px;
}

.panel-heading p,
.login-panel p,
.muted {
    color: var(--muted);
}

label {
    display: block;
    margin: 12px 0 7px;
    color: color-mix(in srgb, var(--accent-2) 70%, white);
    font-size: 13px;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(6, 8, 18, .62);
    color: var(--text);
    padding: 11px 12px;
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease;
}

input:focus,
textarea:focus {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-2) 22%, transparent);
}

.stack {
    display: grid;
    gap: 2px;
}

.info-list {
    display: grid;
    gap: 10px;
}

.info-list p {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
    color: var(--muted);
    padding: 12px;
}

.info-list strong {
    color: var(--text);
}

.document-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 18px;
}

.status-box {
    min-height: 44px;
    margin: 14px 0 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(6, 8, 18, .62);
    color: var(--text);
    padding: 12px;
    overflow: auto;
    white-space: pre-wrap;
}

.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.document-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
    padding: 14px;
    transition: transform .16s ease, border-color .16s ease;
}

.document-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-2);
}

.document-card h3 {
    margin: 0 0 8px;
}

.document-card p {
    min-height: 42px;
    margin: 0 0 12px;
    color: var(--muted);
}

.document-card code {
    display: block;
    margin: 0 0 12px;
    color: color-mix(in srgb, var(--accent-2) 80%, white);
    overflow-wrap: anywhere;
}

.card-actions {
    display: flex;
    gap: 8px;
}

.preview-panel iframe {
    width: 100%;
    height: min(74vh, 820px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.loader-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    pointer-events: none;
    opacity: 0;
    background: rgba(8, 5, 14, .38);
    backdrop-filter: blur(4px);
    transition: opacity .18s ease;
}

body.is-loading .loader-overlay {
    opacity: 1;
}

.lollipop-loader {
    display: grid;
    justify-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 20px 22px;
    box-shadow: var(--shadow);
}

.lollipop-loader span {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: conic-gradient(var(--accent), var(--accent-2), var(--accent-3), var(--accent));
    position: relative;
    animation: spin 1s linear infinite;
}

.lollipop-loader span::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 42px;
    background: rgba(255, 255, 255, .82);
    border-radius: 999px;
    left: 50%;
    top: 42px;
    transform: translateX(-50%) rotate(-18deg);
    transform-origin: top;
}

body.logged-out #appView,
body.logged-in #loginView {
    display: none;
}

body:not(.access-granted) .topbar,
body:not(.access-granted) #documentView,
body:not(.access-granted) #previewView {
    display: none !important;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media (max-width: 820px) {
    .topbar,
    .panel-heading,
    .identity {
        align-items: stretch;
        flex-direction: column;
    }

    .document-layout {
        grid-template-columns: 1fr;
    }
}
