:root {
    --bg: #edf0f2;
    --bg-2: #f8f2e9;
    --surface: #ffffff;
    --surface-alt: #f6f7f8;
    --stroke: #d9dee3;
    --ink: #1f2933;
    --ink-muted: #5b6574;
    --accent: #0f766e;
    --accent-strong: #0a5c55;
    --accent-soft: #cce9e4;
    --sun: #f4a72b;
    --shadow-lg: 0 24px 70px rgba(31, 41, 51, 0.16);
    --shadow-md: 0 12px 30px rgba(31, 41, 51, 0.12);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --font-sans: "Avenir Next", "Avenir", "Futura", "Gill Sans", "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    color: var(--ink);
    font-family: var(--font-sans);
    background: radial-gradient(1200px 800px at 15% -10%, #ffffff 0%, var(--bg) 40%, var(--bg-2) 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(rgba(15, 118, 110, 0.08) 1px, transparent 1px);
    background-size: 28px 28px;
    opacity: 0.4;
    pointer-events: none;
}

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

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

.app-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 24px;
    padding: 24px;
    height: 100vh;
    margin: 0 auto;
    max-width: 1400px;
}

.icon-button {
    border: 1px solid var(--stroke);
    background: var(--surface);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: rgba(15, 118, 110, 0.35);
}

.btn {
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: none;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    box-shadow: 0 12px 20px rgba(15, 118, 110, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--stroke);
    color: var(--ink);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--ink-muted);
}

.btn-block {
    width: 100%;
}

.sidebar {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--stroke);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    animation: floatIn 0.6s ease-out;
}

.sidebar__header {
    padding: 24px;
    border-bottom: 1px solid var(--stroke);
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand__mark {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent), var(--sun));
    color: #fff;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
    box-shadow: 0 12px 24px rgba(244, 167, 43, 0.25);
}

.brand__text h1 {
    margin: 0;
    font-size: 1.35rem;
    letter-spacing: 0.02em;
}

.brand__text p {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--ink-muted);
}

.sidebar__body {
    padding: 20px 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-card {
    background: var(--surface-alt);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

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

.card__meta {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
}

.key-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--ink-muted);
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: 999px;
    padding: 6px 10px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.field label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
}

.field__control {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.input,
.select,
.textarea {
    width: 100%;
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    background: var(--surface);
    color: var(--ink);
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: rgba(15, 118, 110, 0.6);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.input--with-action {
    padding-right: 44px;
}

.field__hint {
    font-size: 0.75rem;
    color: var(--ink-muted);
}

.select {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235b6574' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.range {
    width: 100%;
    accent-color: var(--accent);
}

.range-value {
    font-weight: 600;
    color: var(--accent);
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--stroke);
    background: var(--surface);
}

.control-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-text strong {
    font-size: 0.9rem;
}

.control-text span {
    font-size: 0.75rem;
    color: var(--ink-muted);
}

.checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--accent);
    border-radius: 6px;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 140px;
    overflow-y: auto;
}

.file-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--stroke);
    font-size: 0.85rem;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.file-thumb {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid var(--stroke);
    background: #fff;
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.file-icon {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 118, 110, 0.12);
    color: var(--accent-strong);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    border: 1px solid rgba(15, 118, 110, 0.2);
}

.file-pill button {
    background: transparent;
    border: none;
    color: #c2410c;
    font-size: 1.1rem;
    cursor: pointer;
}

.sidebar__footer {
    padding: 16px 24px 20px;
    font-size: 0.75rem;
    color: var(--ink-muted);
    border-top: 1px solid var(--stroke);
}

.chat {
    background: rgba(255, 255, 255, 0.96);
    border-radius: var(--radius-lg);
    border: 1px solid var(--stroke);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    animation: floatIn 0.6s ease-out 0.08s both;
}

.chat__header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--stroke);
}

.chat__title h2 {
    margin: 0;
    font-size: 1.2rem;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--ink-muted);
}

.status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9aa3af;
    box-shadow: 0 0 0 4px rgba(154, 163, 175, 0.2);
}

.status--ok::before {
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.2);
}

.status--busy::before {
    background: var(--sun);
    box-shadow: 0 0 0 4px rgba(244, 167, 43, 0.2);
}

.status--error::before {
    background: #dc2626;
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2);
}

.chat__messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--ink-muted);
    max-width: 420px;
}

.empty-state h3 {
    color: var(--ink);
    margin-bottom: 6px;
}

.message {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    animation: messageIn 0.2s ease;
}

.message--user {
    justify-content: flex-end;
}

.message__bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 18px;
    background: #f3f4f6;
    border: 1px solid #e1e6eb;
    box-shadow: none;
}

.message--user .message__bubble {
    background: #0f766e;
    color: #fff;
    border: none;
}

.message--typing .message__bubble {
    width: fit-content;
    padding: 6px 10px;
    background: #eef1f4;
}

.message-content {
    line-height: 1.6;
}

.message-content a {
    color: var(--accent-strong);
    font-weight: 600;
}

.message--user .message-content a {
    color: #fff;
}

.message-content ul,
.message-content ol {
    padding-left: 20px;
}

.message-content pre {
    background: #1c1f24;
    border-radius: 12px;
    padding: 16px;
    overflow-x: auto;
}

.message-content code {
    background: rgba(15, 118, 110, 0.12);
    color: inherit;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.9rem;
}

.message-content pre code {
    background: transparent;
    color: #e2e8f0;
    padding: 0;
}

.typing-indicator {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

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

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

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

@keyframes pulse {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-4px); opacity: 1; }
}

.chat__composer {
    padding: 20px 24px 24px;
    border-top: 1px solid var(--stroke);
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.tool-btn {
    border-radius: 999px;
    padding: 8px 14px;
    border: 1px solid var(--stroke);
    background: var(--surface);
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: border 0.2s ease, transform 0.2s ease;
}

.tool-btn--soft {
    background: rgba(15, 118, 110, 0.08);
    border-color: rgba(15, 118, 110, 0.3);
    color: var(--accent-strong);
}

.tool-btn:hover {
    border-color: rgba(15, 118, 110, 0.4);
    transform: translateY(-1px);
}

.attachment {
    border: 1px solid var(--stroke);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.attachment__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.composer__input {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.textarea {
    min-height: 46px;
    max-height: 200px;
    resize: none;
    padding: 10px 14px;
    border-radius: 14px;
}

.composer__input .btn {
    height: 46px;
    border-radius: 14px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.composer__hint {
    font-size: 0.75rem;
    color: var(--ink-muted);
    text-align: center;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: 24px;
    backdrop-filter: blur(6px);
}

.modal.hidden {
    display: none;
}

.modal__card {
    width: min(480px, 92vw);
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--stroke);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: floatIn 0.3s ease;
}

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

.modal__header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal__actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.hidden {
    display: none;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 280px minmax(0, 1fr);
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 18px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: min(90vw, 360px);
        transform: translateX(-105%);
        transition: transform 0.3s ease;
        z-index: 9;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .chat__header {
        padding-left: 16px;
    }
}

@media (max-width: 640px) {
    .chat__messages {
        padding: 18px;
    }

    .chat__header,
    .chat__composer {
        padding: 16px;
    }

    .message__bubble {
        max-width: 100%;
    }

    .composer__input {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        width: 100%;
    }
}
