:root {
    --bg: #f7efe7;
    --bg-deep: #efe5d9;
    --panel: rgba(255, 250, 245, 0.82);
    --panel-strong: #fffaf6;
    --ink: #152033;
    --muted: #67768f;
    --accent: #0f9d8f;
    --accent-deep: #0a7d71;
    --warm: #ef7b5d;
    --danger: #b42318;
    --border: rgba(21, 32, 51, 0.08);
    --shadow: 0 24px 80px rgba(21, 32, 51, 0.14);
    --radius-xl: 28px;
    --radius-lg: 22px;
    --radius-md: 16px;
}

* {
    box-sizing: border-box;
}

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

body {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at top left, rgba(239, 123, 93, 0.18), transparent 28%),
        radial-gradient(circle at bottom right, rgba(15, 157, 143, 0.18), transparent 28%),
        linear-gradient(145deg, var(--bg), var(--bg-deep));
    color: var(--ink);
    font-family: "Segoe UI Variable", "Aptos", "Trebuchet MS", sans-serif;
}

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

.ambient {
    position: fixed;
    border-radius: 999px;
    filter: blur(18px);
    opacity: 0.55;
    pointer-events: none;
}

.ambient-one {
    top: -90px;
    left: -70px;
    width: 240px;
    height: 240px;
    background: rgba(239, 123, 93, 0.26);
}

.ambient-two {
    right: 6%;
    bottom: -90px;
    width: 280px;
    height: 280px;
    background: rgba(15, 157, 143, 0.18);
}

.app-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(300px, 360px) 1fr;
    gap: 24px;
    height: 100vh;
    padding: 24px;
}

.side-panel,
.chat-stage {
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.64);
    backdrop-filter: blur(24px);
    box-shadow: var(--shadow);
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
    border-radius: var(--radius-xl);
}

.brand-card,
.status-card,
.tool-card,
.composer-panel,
.message-card,
.welcome-state {
    border: 1px solid var(--border);
}

.brand-card {
    display: flex;
    gap: 14px;
    padding: 18px;
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(255, 248, 242, 0.78));
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), var(--warm));
    color: #fff;
    font-size: 1.2rem;
    font-weight: 800;
}

.brand-card h1,
.section-head h2,
.stage-header h2,
.welcome-state h3 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.78rem;
}

.muted-copy {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.65;
}

.status-card,
.tool-card {
    padding: 18px;
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 251, 247, 0.72));
}

.status-pill,
.badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(21, 32, 51, 0.06);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 0 6px rgba(15, 157, 143, 0.14);
}

.section-head {
    margin-bottom: 14px;
}

.field {
    display: block;
}

.field span {
    display: block;
    margin-bottom: 8px;
    font-size: 0.92rem;
    font-weight: 700;
}

.field select,
.field textarea {
    width: 100%;
    border: 1px solid rgba(21, 32, 51, 0.1);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--ink);
    padding: 14px 16px;
    font: inherit;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field select:focus,
.field textarea:focus {
    border-color: rgba(15, 157, 143, 0.4);
    box-shadow: 0 0 0 4px rgba(15, 157, 143, 0.12);
}

.field textarea {
    resize: none;
    min-height: 56px;
    max-height: 220px;
}

.button-stack,
.composer-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.button-stack {
    margin-top: 14px;
    flex-direction: column;
    align-items: stretch;
}

.primary-button,
.secondary-button,
.danger-button {
    appearance: none;
    border: 0;
    border-radius: 16px;
    padding: 14px 18px;
    font-size: 0.96rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover {
    transform: translateY(-1px);
}

.primary-button {
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    color: #fff;
    box-shadow: 0 14px 32px rgba(15, 157, 143, 0.24);
}

.secondary-button {
    background: rgba(255, 255, 255, 0.88);
    color: var(--ink);
}

.danger-button {
    background: rgba(180, 35, 24, 0.1);
    color: var(--danger);
}

.danger-button:hover {
    box-shadow: 0 12px 24px rgba(180, 35, 24, 0.12);
}

.accent-card {
    background: linear-gradient(180deg, rgba(15, 157, 143, 0.08), rgba(255, 255, 255, 0.82));
}

.mini-list {
    margin: 14px 0 0;
    padding-left: 18px;
    color: var(--muted);
    line-height: 1.7;
}

.chat-stage {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 0;
    padding: 24px;
    border-radius: 32px;
}

.stage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.header-badges {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.chat-stream {
    position: relative;
    overflow: auto;
    min-height: 0;
    padding: 26px 0 10px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.welcome-state {
    position: relative;
    margin: auto;
    max-width: 620px;
    padding: 44px 30px;
    border-radius: 28px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(255, 249, 245, 0.78));
    text-align: center;
    overflow: hidden;
}

.welcome-state p {
    margin: 12px 0 0;
    color: var(--muted);
    line-height: 1.7;
}

.welcome-orb {
    position: absolute;
    top: -36px;
    right: -28px;
    width: 130px;
    height: 130px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(15, 157, 143, 0.18), transparent 65%);
}

.message-card {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 16px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.86);
    animation: riseIn 220ms ease;
}

.message-card.user {
    align-self: flex-end;
    max-width: min(86%, 820px);
    background: linear-gradient(135deg, rgba(239, 123, 93, 0.12), rgba(255, 255, 255, 0.96));
}

.message-card.assistant {
    align-self: flex-start;
    max-width: min(88%, 840px);
}

.message-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    color: #fff;
    font-size: 0.92rem;
    font-weight: 700;
}

.message-card.user .message-avatar {
    background: linear-gradient(135deg, var(--warm), #ee9965);
}

.message-card.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent), #12b5a2);
}

.message-body {
    min-width: 0;
}

.message-role {
    margin: 2px 0 8px;
    font-size: 0.85rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.message-text {
    white-space: pre-wrap;
    line-height: 1.7;
    word-break: break-word;
    user-select: text !important;
    -webkit-user-select: text !important;
}

.message-card {
    user-select: text !important;
    -webkit-user-select: text !important;
}

.message-time {
    margin-top: 10px;
    color: #93a0b4;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.copy-btn {
    background: none;
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 6px;
    padding: 3px 8px;
    color: #8c9bb0;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.2s;
    opacity: 0.4;
    display: flex;
    align-items: center;
    gap: 5px;
}

.message-card:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    color: var(--accent);
    background: rgba(0,0,0,0.02);
    border-color: rgba(0,0,0,0.1);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    align-self: flex-start;
    padding: 12px 14px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--border);
}

.typing-bubble {
    display: inline-flex;
    gap: 8px;
}

.typing-bubble span {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--accent);
    animation: pulse 1.1s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-bubble span:nth-child(3) {
    animation-delay: 0.3s;
}

.is-hidden {
    display: none !important;
}

.composer-panel {
    padding: 18px;
    border-radius: 26px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 250, 245, 0.82));
}

.composer-actions {
    justify-content: space-between;
    margin-top: 14px;
}

.composer-note {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.toast-stack {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    min-width: 240px;
    max-width: 340px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(21, 32, 51, 0.92);
    color: #fff;
    box-shadow: var(--shadow);
    animation: riseIn 220ms ease;
}

.toast.error {
    background: rgba(180, 35, 24, 0.94);
}

code {
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(21, 32, 51, 0.06);
    font-family: "Cascadia Code", Consolas, monospace;
}

@keyframes pulse {
    0%,
    80%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.chat-item {
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,0.6);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-item:hover, .chat-item.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent-deep);
}

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

@media (max-width: 1080px) {
    body {
        overflow: auto;
    }

    .app-shell {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 100vh;
    }

    .chat-stage {
        min-height: 70vh;
    }
}

@media (max-width: 720px) {
    .app-shell {
        gap: 14px;
        padding: 14px;
    }

    .side-panel,
    .chat-stage {
        padding: 18px;
        border-radius: 24px;
    }

    .stage-header,
    .composer-actions {
        flex-direction: column;
        align-items: stretch;
    }

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

    .toast-stack {
        left: 14px;
        right: 14px;
        bottom: 14px;
    }

    .toast {
        max-width: none;
    }
}
