:root {
    color-scheme: light;
    --page: #eef2ee;
    --paper: #fbfcfb;
    --surface: #ffffff;
    --surface-soft: #f4f6f4;
    --ink: #15191c;
    --muted: #647076;
    --line: #d8e0dc;
    --line-strong: #c2cdc8;
    --accent: #0b6f68;
    --accent-strong: #064f4a;
    --accent-soft: #dcefeb;
    --blue: #2f6db3;
    --sun: #d08a23;
    --danger: #c84c4c;
    --shadow: 0 18px 48px rgba(24, 33, 35, 0.13);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--page);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
    background:
            linear-gradient(135deg, rgba(11, 111, 104, 0.1), transparent 34%),
            linear-gradient(180deg, rgba(208, 138, 35, 0.08), transparent 42%),
            var(--page);
}

body.modal-open {
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

a {
    color: inherit;
}

.app-shell {
    width: min(1180px, calc(100% - 28px));
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: 14px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex: 0 0 auto;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    color: #fff;
    background: #15191c;
    font-weight: 850;
}

.brand-copy {
    display: grid;
    min-width: 0;
    line-height: 1.05;
}

.brand-name {
    font-size: 1rem;
    font-weight: 820;
}

.brand-subtitle {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
}

.top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.top-link,
.usage-pill,
.ghost-button,
.primary-button,
.text-button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border-radius: var(--radius);
    text-decoration: none;
    white-space: nowrap;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.top-link,
.usage-pill {
    border: 1px solid rgba(216, 224, 220, 0.92);
    padding: 0 12px;
    background: rgba(255, 255, 255, 0.78);
    color: #3e4a4d;
    font-size: 0.88rem;
    font-weight: 720;
    backdrop-filter: blur(14px);
}

.top-link:hover,
.ghost-button:hover,
.text-button:hover,
.icon-button:hover {
    transform: translateY(-1px);
    border-color: rgba(11, 111, 104, 0.38);
    color: var(--accent-strong);
}

.usage-pill.is-empty {
    border-color: rgba(200, 76, 76, 0.34);
    color: var(--danger);
    background: #fff7f6;
}

.ghost-button {
    border: 1px solid var(--line);
    padding: 0 13px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    font-weight: 760;
}

.ghost-button.is-account {
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.primary-button {
    border: 1px solid transparent;
    padding: 0 16px;
    color: #fff;
    background: var(--accent);
    box-shadow: 0 12px 24px rgba(11, 111, 104, 0.22);
    font-weight: 800;
}

.primary-button:hover {
    transform: translateY(-1px);
    background: var(--accent-strong);
}

.primary-button.compact {
    min-height: 36px;
    padding: 0 13px;
    font-size: 0.92rem;
}

.text-button {
    border: 1px solid var(--line);
    min-height: 36px;
    padding: 0 12px;
    color: var(--accent-strong);
    background: #fff;
    font-weight: 760;
}

.icon-button {
    width: 40px;
    min-width: 40px;
    border: 1px solid var(--line);
    color: #283437;
    background: rgba(255, 255, 255, 0.92);
    font-size: 1.05rem;
    font-weight: 850;
}

.chat-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 12px;
}

.conversation-panel {
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(216, 224, 220, 0.94);
    border-radius: var(--radius);
    background: rgba(251, 252, 251, 0.78);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.conversation {
    height: 100%;
    overflow: auto;
    padding: clamp(16px, 2.4vw, 26px);
    display: grid;
    align-content: start;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: grid;
    gap: 10px;
    animation: messageIn 220ms ease both;
}

.assistant-message {
    grid-template-columns: 40px minmax(0, 1fr);
    align-items: start;
    justify-items: start;
}

.user-message {
    justify-items: end;
}

.avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    color: #fff;
    background: var(--accent);
    font-size: 0.78rem;
    font-weight: 860;
    box-shadow: 0 10px 20px rgba(11, 111, 104, 0.2);
}

.bubble {
    width: fit-content;
    max-width: min(760px, 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 13px;
    background: var(--surface);
    box-shadow: 0 10px 24px rgba(24, 33, 35, 0.08);
}

.user-message .bubble {
    max-width: min(680px, 88%);
    border-color: rgba(11, 111, 104, 0.2);
    color: #fff;
    background: var(--accent);
}

.bubble p {
    margin: 0;
    line-height: 1.65;
    white-space: pre-wrap;
}

.message-meta {
    display: block;
    margin-top: 8px;
    color: rgba(255, 255, 255, 0.76);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.quick-prompts button {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 10px;
    color: #384649;
    background: var(--surface-soft);
    font-size: 0.9rem;
    font-weight: 720;
}

.quick-prompts button:hover {
    border-color: rgba(11, 111, 104, 0.35);
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.chat-composer {
    flex: 0 0 auto;
    border: 1px solid rgba(216, 224, 220, 0.96);
    border-radius: var(--radius);
    padding: 12px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.composer-controls {
    display: grid;
    grid-template-columns: minmax(220px, 300px) minmax(140px, 190px) 40px;
    gap: 10px;
    align-items: end;
    margin-bottom: 10px;
}

.control-field {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.control-field span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 760;
}

select,
input {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 11px;
    color: var(--ink);
    background: #fff;
    outline: none;
}

select:focus,
input:focus,
textarea:focus {
    border-color: rgba(11, 111, 104, 0.55);
    box-shadow: 0 0 0 4px rgba(11, 111, 104, 0.12);
}

.composer-input {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}

textarea {
    width: 100%;
    min-height: 72px;
    max-height: 180px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 13px 14px;
    color: var(--ink);
    background: #fff;
    outline: none;
    line-height: 1.55;
}

.composer-side {
    display: grid;
    gap: 8px;
    justify-items: end;
}

.prompt-count {
    min-height: 18px;
    color: var(--muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.send-button {
    position: relative;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: var(--radius);
    color: #fff;
    background: var(--accent);
    box-shadow: 0 14px 26px rgba(11, 111, 104, 0.25);
    transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.send-button:hover {
    transform: translateY(-1px);
    background: var(--accent-strong);
}

.send-icon {
    font-size: 1.28rem;
    font-weight: 900;
}

.loader {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.38);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 850ms linear infinite;
}

.is-loading .send-icon {
    display: none;
}

.is-loading .loader {
    display: block;
}

.generation-progress {
    min-width: min(520px, 100%);
    display: grid;
    gap: 9px;
}

.progress-copy {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.progress-copy span:first-child {
    font-weight: 800;
}

.progress-copy span:last-child {
    color: var(--accent-strong);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
}

.progress-track {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #e3ebe7;
}

.progress-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--blue), var(--sun));
    transition: width 360ms ease;
}

.generation-progress.is-error .progress-track span {
    background: var(--danger);
}

.generation-progress p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.result-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.result-heading strong {
    font-size: 0.98rem;
}

.result-heading span {
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 720;
}

.image-grid {
    width: min(760px, 100%);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 12px;
}

.image-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 10px 28px rgba(24, 33, 35, 0.1);
}

.image-card figure {
    margin: 0;
    min-height: 220px;
    background: #eaf0ed;
}

.image-card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 220ms ease, transform 360ms ease;
}

.image-card img.is-ready {
    opacity: 1;
}

.image-card:hover img {
    transform: scale(1.012);
}

.card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 54px;
    padding: 9px;
}

.notice-text {
    color: #384649;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(13, 18, 20, 0.42);
    backdrop-filter: blur(7px);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(420px, 100%);
    border: 1px solid rgba(216, 224, 220, 0.95);
    border-radius: var(--radius);
    padding: 20px;
    background: var(--surface);
    box-shadow: 0 24px 80px rgba(12, 18, 20, 0.26);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 1.2rem;
}

.modal-panel h2 {
    margin: 0 42px 16px 0;
    font-size: 1.35rem;
}

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.auth-tabs button {
    min-height: 36px;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    font-weight: 780;
}

.auth-tabs button.is-active {
    color: var(--ink);
    background: #fff;
    box-shadow: 0 8px 18px rgba(24, 33, 35, 0.08);
}

.auth-form {
    display: grid;
    gap: 13px;
    margin-top: 16px;
}

.auth-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 750;
}

.auth-hint {
    margin: -2px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 30;
    max-width: min(92vw, 520px);
    min-height: 42px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: #fff;
    background: #15191c;
    box-shadow: 0 18px 50px rgba(23, 26, 28, 0.24);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.admin-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

.admin-main {
    display: grid;
    gap: 14px;
}

.admin-head,
.admin-gate,
.users-panel {
    border: 1px solid rgba(216, 224, 220, 0.94);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.admin-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--sun);
    font-size: 0.75rem;
    font-weight: 850;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    line-height: 1;
    letter-spacing: 0;
}

.admin-gate {
    padding: 22px;
}

.admin-gate h2 {
    margin: 0 0 8px;
}

.admin-gate p {
    margin: 0 0 16px;
    color: var(--muted);
}

.users-panel {
    overflow: hidden;
}

.table-wrap {
    overflow: auto;
}

.users-table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
}

.users-table th,
.users-table td {
    border-bottom: 1px solid var(--line);
    padding: 12px;
    text-align: left;
    vertical-align: middle;
}

.users-table th {
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 0.8rem;
    font-weight: 820;
}

.users-table tr:last-child td {
    border-bottom: 0;
}

.user-identity {
    display: grid;
    gap: 4px;
}

.user-identity strong {
    font-size: 0.96rem;
}

.user-identity span {
    color: var(--muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #334044;
    font-weight: 740;
}

.switch input {
    width: 18px;
    min-height: 18px;
    accent-color: var(--accent);
}

.usage-meter {
    min-width: 110px;
    display: grid;
    gap: 6px;
}

.usage-meter > span {
    color: #334044;
    font-weight: 780;
    font-variant-numeric: tabular-nums;
}

.usage-meter div {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2eae6;
}

.usage-meter div span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--sun));
}

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

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

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 720px);
        padding: 10px 0;
    }

    .topbar {
        align-items: flex-start;
    }

    .top-actions {
        flex-wrap: wrap;
    }

    .usage-pill {
        order: 3;
    }

    .conversation {
        padding: 14px;
    }

    .composer-controls {
        grid-template-columns: minmax(0, 1fr) 40px;
    }

    .custom-size {
        grid-column: 1 / -1;
        order: 3;
    }

    .composer-input {
        grid-template-columns: 1fr;
    }

    .composer-side {
        grid-template-columns: 1fr 46px;
        align-items: center;
    }

    .prompt-count {
        justify-self: start;
    }

    .send-button {
        justify-self: end;
    }

    .assistant-message {
        grid-template-columns: 34px minmax(0, 1fr);
    }

    .avatar,
    .brand-mark {
        width: 34px;
        height: 34px;
    }

    .bubble,
    .user-message .bubble {
        max-width: 100%;
    }

    .admin-head {
        align-items: start;
    }
}

@media (max-width: 520px) {
    .brand-subtitle,
    .top-link {
        display: none;
    }

    .top-actions {
        gap: 6px;
    }

    .ghost-button,
    .usage-pill {
        min-height: 34px;
        padding: 0 9px;
        font-size: 0.8rem;
    }

    .icon-button {
        width: 36px;
        min-width: 36px;
        min-height: 36px;
    }

    .chat-layout {
        gap: 10px;
    }

    .chat-composer {
        padding: 10px;
    }

    .quick-prompts button {
        flex: 1 1 45%;
    }

    .image-grid {
        grid-template-columns: 1fr;
    }
}

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