:root {
    --bg: #FDFBF5;
    --surface: #ffffff;
    --surface-warm: #ffef98;
    --surface-strong: #fadc62;
    --ink: #000000;
    --muted: #555555;
    --line: #ffda46;
    --line-soft: #e6d398;
    --accent: #870202;
    --accent-strong: #d31141;
    --accent-hot: #ff0000;
    --gold: #ffdb49;
    --gold-deep: #fab42d;
    --shadow: 10px 10px 20px rgba(0, 0, 0, 0.28);
    --soft-shadow: 0 8px 22px rgba(80, 54, 0, 0.16);
    --danger: #a32424;
    --success: #1f6b45;
}

* { box-sizing: border-box; }

html, body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Poppins", Arial, Helvetica, sans-serif;
    line-height: 1.55;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.25ch;
}

a:hover,
a:focus {
    color: var(--accent-hot);
    text-decoration-style: dashed;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: min(1180px, calc(100% - 24px));
    margin: 18px auto 0;
    padding: 14px 18px;
    color: #000;
    border: 2px solid #ffcc33;
    border-radius: 8px;
    background-color: var(--gold);
    background-image: linear-gradient(to bottom, #ffdb49 0%, #ffdb49 2px, #f3c31e 80%, #fab42d 100%);
    box-shadow: var(--shadow);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #000;
    font-weight: 700;
    text-decoration: none;
}

.brand:hover {
    color: #000;
    text-decoration: none;
}

.brand small {
    display: block;
    color: #2b2b2b;
    font-weight: 500;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid #870202;
    border-radius: 7px;
    background: #ffffff;
    color: var(--accent);
    box-shadow: 0 0 0 1px #ffffff inset;
}

nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

nav a {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 5px;
    color: #000;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

nav a:hover {
    background: #ffffcc;
    color: var(--accent-strong);
    text-decoration: none;
}

.menu-toggle {
    display: none;
}

.menu-icon,
.menu-icon::before,
.menu-icon::after {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
}

.menu-icon {
    position: relative;
}

.menu-icon::before,
.menu-icon::after {
    content: "";
    position: absolute;
    left: 0;
}

.menu-icon::before {
    top: -6px;
}

.menu-icon::after {
    top: 6px;
}

.page {
    width: min(1120px, calc(100% - 32px));
    margin: 34px auto;
}

.site-footer {
    width: min(1120px, calc(100% - 32px));
    margin: 30px auto;
    color: var(--muted);
    font-size: 14px;
}

.hero,
.chat-shell,
.admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    align-items: start;
}

.hero {
    min-height: 430px;
    align-items: center;
}

.chat-shell {
    grid-template-columns: minmax(0, 1fr);
}

.chat-main,
.chat-shell .side-panel {
    min-width: 0;
}

h1 {
    margin: 0 0 16px;
    color: #000;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.08;
}

h2 {
    margin: 0 0 12px;
    color: #000;
    font-size: 21px;
}

.eyebrow {
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 13px;
}

.lead {
    max-width: 680px;
    color: #333;
    font-size: 20px;
}

.panel,
.limit-box,
.side-panel,
.stats,
.install-panel {
    background: var(--surface);
    border: 2px solid #ffcc33;
    border-radius: 8px;
    padding: 22px;
    box-shadow: var(--soft-shadow);
}

.panel {
    background: linear-gradient(to bottom, #fffdf1 0%, #ffef98 100%);
}

.limit-box,
.side-panel {
    background: #ffffff;
}

.narrow {
    max-width: 520px;
    margin: 0 auto;
}

.readable {
    max-width: 780px;
    margin: 0 auto;
}

.actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 22px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border: 1px solid #c7c3bf;
    border-radius: 6px;
    background-color: #e9e9e9;
    background-image: linear-gradient(to bottom, #ffffff 0%, #e9e9e9 100%);
    box-shadow: 0 0 0 1px #ffffff inset;
    color: var(--accent-strong);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

.button.small {
    min-height: 34px;
    padding: 6px 10px;
}

.button.primary,
button[type="submit"] {
    border-color: #666666;
    background-color: var(--gold);
    background-image: linear-gradient(to bottom, #ffec8e 0%, #fab42d 100%);
    color: #000000;
}

button:hover,
button:focus,
.button:hover,
.button:focus {
    border-color: var(--accent-hot);
    background-image: linear-gradient(to bottom, #e9e9e9 0%, #ffffff 100%);
    color: var(--accent-hot);
    text-decoration: none;
}

button.danger {
    width: 100%;
    border-color: var(--danger);
    background: var(--danger);
    color: #ffffff;
}

.notice {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-top: 2px solid var(--line);
    border-radius: 6px;
    background: #ffffcc;
}

.notice.success { color: var(--success); }
.notice.danger { color: var(--danger); }

.form-stack,
.form-grid {
    display: grid;
    gap: 14px;
}

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

.form-grid h2 {
    grid-column: 1 / -1;
    margin-top: 10px;
}

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

label {
    display: grid;
    gap: 6px;
    color: #000;
    font-weight: 700;
}

label.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 400;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid #b4bac0;
    border-radius: 6px;
    padding: 11px 12px;
    background: #ffffff;
    color: #333333;
    font: inherit;
}

.password-field {
    display: grid;
    grid-template-columns: 1fr 44px;
    gap: 8px;
    align-items: stretch;
}

.password-field input {
    min-width: 0;
}

.password-toggle {
    min-height: 0;
    padding: 0;
    font-size: 18px;
    line-height: 1;
}

input:hover,
textarea:hover,
select:hover,
input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent-hot);
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.12);
}

textarea {
    resize: vertical;
}

.chat-window {
    position: relative;
    display: grid;
    gap: 14px;
    min-height: 360px;
    max-height: 60vh;
    overflow: auto;
    padding: 18px;
    background: #ffffff;
    border: 2px solid #ffcc33;
    border-radius: 8px;
    box-shadow: var(--soft-shadow);
}

.bubble {
    max-width: 80%;
    padding: 14px;
    border: 1px solid #dbdbce;
    border-radius: 7px;
    background: #ffffcc;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.22);
}

.bubble.user {
    justify-self: end;
    background: #ffef98;
}

.bubble.assistant {
    background: #ffffff;
}

.bubble p {
    margin: 6px 0 0;
}

.conversation-end {
    height: 1px;
}

.empty-state {
    color: var(--muted);
}

.payment-box {
    display: grid;
    gap: 12px;
    margin: 18px 0;
    padding: 16px;
    border: 2px solid #ffcc33;
    border-radius: 8px;
    background: #ffffcc;
}

.payment-summary {
    display: grid;
    gap: 6px;
    margin: 18px 0 0;
    padding: 14px;
    border: 1px solid #ffcc33;
    border-radius: 8px;
    background: #ffffcc;
}

.payment-summary p {
    margin: 0;
}

.payment-plans {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin: 18px 0;
}

.payment-plan-card,
.payment-plan-admin {
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 2px solid #ffcc33;
    border-radius: 8px;
    background: #ffffcc;
}

.payment-plan-card h2 {
    margin: 0;
}

.payment-plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.conversation-manager {
    display: grid;
    gap: 14px;
    min-width: 0;
    max-width: 100%;
    margin-bottom: 18px;
}

.conversation-manager h2,
.conversation-manager p {
    margin: 0;
}

.conversation-manager-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
    gap: 14px;
    align-items: end;
    min-width: 0;
}

.conversation-create,
.conversation-inline-form {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.conversation-create {
    grid-template-columns: minmax(0, 1fr) auto;
}

.conversation-create input {
    min-width: 0;
}

.conversation-create button {
    white-space: nowrap;
}

.conversation-new-link {
    margin: 0;
    justify-self: end;
}

.conversation-tabs {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
}

.conversation-tabs a {
    flex: 0 0 190px;
    display: grid;
    gap: 2px;
    min-width: 190px;
    max-width: 280px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #ffffff;
    color: #000000;
    text-decoration: none;
}

.conversation-tabs a.is-active {
    border-color: var(--accent);
    background: #ffef98;
    box-shadow: inset 0 0 0 1px var(--accent);
}

.conversation-tabs strong,
.conversation-tabs span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-tabs span,
.conversation-manager p {
    color: var(--muted);
    font-size: 14px;
}

.conversation-tools,
.conversation-archives {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.conversation-tools summary,
.conversation-archives summary {
    color: var(--accent);
    cursor: pointer;
    font-weight: 700;
}

.conversation-archives-inline summary {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid #c7c3bf;
    border-radius: 6px;
    background-image: linear-gradient(to bottom, #ffffff 0%, #e9e9e9 100%);
    box-shadow: 0 0 0 1px #ffffff inset;
}

.conversation-tools[open],
.conversation-archives[open] {
    display: grid;
    gap: 12px;
}

.archive-conversation-picker {
    display: grid;
    gap: 7px;
    max-width: 640px;
}

.archive-conversation-picker label {
    font-weight: 700;
}

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

.archive-conversation-picker select {
    min-width: 0;
    width: 100%;
}

.archive-conversation-picker button {
    min-height: 42px;
    white-space: nowrap;
}

.archived-conversation-actions {
    display: grid;
    gap: 12px;
}

.archived-conversation-actions p {
    margin: 0;
}

.archived-conversation-actions .actions {
    margin-top: 0;
}

.price {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 700;
}

.delete-account-form {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-top: 14px;
    align-items: end;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    background: #ffffff;
}

.stats div {
    padding: 16px;
    border: 1px solid #ffffff;
    border-radius: 6px;
    background: var(--surface-strong);
}

.stats strong {
    display: block;
    font-size: 30px;
}

.stats span {
    color: #333333;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    color: #000;
    text-align: left;
    vertical-align: top;
}

thead th {
    background: var(--gold);
    font-size: 13px;
}

tbody tr:nth-child(odd) {
    background: #fadc62;
}

tbody tr:nth-child(even) {
    background: #ffef98;
}

tbody tr:hover {
    background: #fab42c;
}

.inline-form {
    display: inline-block;
    margin: 2px;
}

.inline-form button {
    min-height: 34px;
    padding: 6px 10px;
}

.install-body {
    display: grid;
    place-items: start center;
    min-height: 100vh;
    padding: 30px 16px;
}

.install-panel {
    width: min(760px, 100%);
}

.admin-user-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 24px;
    align-items: start;
    margin-bottom: 24px;
}

.details-list {
    display: grid;
    gap: 10px;
    margin: 18px 0 0;
}

.details-list div {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 12px;
    padding: 10px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.55);
}

.details-list.compact div {
    grid-template-columns: 1fr;
    gap: 2px;
}

.details-list dt {
    color: #333333;
    font-weight: 700;
}

.details-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.maintenance-panel {
    margin-top: 40px;
}

.text-editor-form textarea {
    min-height: 110px;
}

.text-editor-form label {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.64);
}

.outbox-item {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.outbox-item textarea {
    width: 100%;
    min-height: 160px;
    font-family: Consolas, Monaco, monospace;
}

.emergency-action {
    margin: 16px 0;
    padding: 14px;
    border: 2px solid var(--danger);
    border-radius: 8px;
    background: #fff;
}

.source-result {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.source-result h3 {
    margin: 0 0 8px;
}

.full-source-content {
    max-height: 560px;
    overflow: auto;
}

.filters-form {
    align-items: end;
    margin-bottom: 18px;
}

.form-help {
    margin: -6px 0 4px;
    color: var(--muted);
    font-size: 14px;
}

@media (max-width: 820px) {
    .site-header {
        position: sticky;
        top: 0;
        z-index: 100;
        align-items: center;
        flex-direction: row;
        margin-top: 0;
        padding: 10px 12px;
    }

    .brand {
        min-width: 0;
    }

    .brand-mark {
        width: 34px;
        height: 34px;
        flex: 0 0 auto;
    }

    .brand small {
        font-size: 12px;
    }

    .menu-toggle {
        display: inline-flex;
        gap: 8px;
        min-height: 36px;
        margin-left: auto;
        padding: 6px 10px;
    }

    .site-header nav {
        position: absolute;
        z-index: 101;
        top: calc(100% + 8px);
        right: 0;
        left: 0;
        display: none;
        grid-template-columns: 1fr;
        gap: 2px;
        padding: 8px;
        border: 2px solid #ffcc33;
        border-radius: 8px;
        background: #ffffff;
        box-shadow: var(--shadow);
    }

    .site-header.is-menu-open nav {
        display: grid;
    }

    .site-header nav a {
        width: 100%;
        min-height: 42px;
        padding: 9px 12px;
        border-bottom: 1px solid var(--line-soft);
    }

    .site-header nav a:last-child {
        border-bottom: 0;
    }

    .hero,
    .chat-shell,
    .admin-grid,
    .admin-user-grid {
        grid-template-columns: 1fr;
    }

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

    .conversation-manager-head,
    .conversation-create {
        grid-template-columns: 1fr;
    }

    .conversation-tabs {
        display: grid;
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .conversation-tabs a {
        max-width: none;
        min-width: 0;
    }

    .archive-conversation-picker {
        max-width: none;
    }

    .archive-conversation-picker div {
        grid-template-columns: 1fr;
    }

    .archive-conversation-picker button {
        width: 100%;
    }

    .archived-conversation-actions .actions,
    .archived-conversation-actions .actions form,
    .archived-conversation-actions .actions button {
        width: 100%;
    }

    .bubble {
        max-width: 100%;
    }

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

body.is-embed {
    min-height: auto;
    background: transparent;
}

body.is-embed .page {
    width: 100%;
    margin: 0;
}

body.is-embed {
    padding-top: 0;
}

body.is-embed .hero,
body.is-embed .chat-shell,
body.is-embed .admin-grid,
body.is-embed .admin-user-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

body.is-embed .hero {
    min-height: 0;
    align-items: start;
}

body.is-embed .panel,
body.is-embed .limit-box,
body.is-embed .side-panel,
body.is-embed .stats,
body.is-embed .install-panel {
    box-shadow: none;
}

body.is-embed .hero > div,
body.is-embed .chat-main {
    min-width: 0;
}

body.is-embed h1 {
    font-size: clamp(28px, 4vw, 42px);
}

body.is-embed .lead {
    font-size: 18px;
}

body.is-embed .site-footer {
    display: none;
}

body.is-embed .site-header {
    width: 100%;
    margin: 0 0 16px;
    box-shadow: none;
}

body.is-embed .chat-window {
    max-height: none;
    overflow: visible;
}

body.is-fullscreen {
    background: #fdfbf5;
}

.fullscreen-bar {
    width: min(1180px, calc(100% - 48px));
    margin: 12px auto 0;
    display: flex;
    justify-content: flex-end;
    position: sticky;
    top: 0;
    z-index: 120;
    padding: 8px 0;
    background: #fdfbf5;
}

.fullscreen-bar .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
}

@media (max-width: 820px) {
    body.is-embed .chat-window {
        min-height: 0;
        padding: 12px;
    }

    body.is-embed .bubble {
        max-width: 100%;
    }

    .fullscreen-bar {
        width: calc(100% - 24px);
        justify-content: stretch;
    }

    .fullscreen-bar .button {
        width: 100%;
    }
}
