:root {
    --page: #eef1f5;
    --surface: #ffffff;
    --surface-muted: #f7f8fa;
    --ink: #1d2733;
    --muted: #687482;
    --line: #dce2e8;
    --brand: #123b63;
    --brand-deep: #0c2d4d;
    --brand-soft: #e8f0f7;
    --accent: #c99a3e;
    --accent-soft: #f7f0e2;
    --danger: #a84747;
    --danger-soft: #f9eded;
    --shadow: 0 18px 45px rgba(27, 45, 63, 0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

body {
    min-height: 100vh;
    padding: 20px 14px;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 0%, rgba(201, 154, 62, 0.1), transparent 34%),
        var(--page);
}

.chat-container {
    width: min(100%, 880px);
    height: min(760px, calc(100vh - 40px));
    min-height: 500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid rgba(18, 59, 99, 0.12);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.chat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 22px;
    color: white;
    background: var(--brand);
}

.chat-header::after {
    content: "";
    position: absolute;
    right: 22px;
    bottom: 0;
    width: 64px;
    height: 2px;
    background: var(--accent);
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    flex: 0 0 38px;
    place-items: center;
    color: var(--brand);
    background: #fff;
    border: 3px solid rgba(201, 154, 62, 0.7);
    border-radius: 50%;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.eyebrow {
    margin-bottom: 2px;
    color: rgba(255, 255, 255, 0.68);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.chat-header h1 {
    margin-bottom: 1px;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0;
}

.header-note {
    color: rgba(255, 255, 255, 0.77);
    font-size: 0.76rem;
    line-height: 1.3;
}

.config-panel {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 12px 28px;
    color: #70551f;
    background: var(--accent-soft);
    border-bottom: 1px solid #e8d8b8;
    font-size: 0.82rem;
}

.config-panel span {
    flex: 0 1 auto;
}

.config-panel input {
    min-width: 180px;
    flex: 1;
    padding: 9px 11px;
    color: var(--ink);
    background: white;
    border: 1px solid #d6c69f;
    border-radius: 7px;
    outline: none;
}

.config-panel input:focus,
.chat-input-area input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(18, 59, 99, 0.12);
}

.config-panel button,
.chat-input-area button {
    border: 0;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 650;
    transition: background-color 160ms ease, transform 160ms ease;
}

.config-panel button {
    padding: 9px 14px;
    color: white;
    background: #9c7528;
}

.config-panel button:hover,
.chat-input-area button:hover {
    transform: translateY(-1px);
}

.chat-messages {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 14px;
    padding: 22px clamp(16px, 4vw, 42px);
    overflow-y: auto;
    background:
        linear-gradient(rgba(248, 249, 250, 0.96), rgba(248, 249, 250, 0.96)),
        repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(18, 59, 99, 0.018) 40px);
    scrollbar-color: #b7c1ca transparent;
    scrollbar-width: thin;
}

.message {
    max-width: min(82%, 620px);
    padding: 12px 15px;
    color: var(--ink);
    font-size: 0.94rem;
    line-height: 1.52;
    white-space: pre-wrap;
    animation: message-in 220ms ease-out both;
}

.message.bot {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 2px solid #d5b16a;
    border-radius: 4px 10px 10px 10px;
    box-shadow: 0 2px 8px rgba(36, 54, 70, 0.035);
}

.welcome-message {
    max-width: min(92%, 650px);
}

.welcome-title {
    margin-bottom: 5px;
    color: var(--brand);
    font-size: 1rem;
    font-weight: 650;
}

.welcome-note {
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.78rem;
}

.message.user {
    align-self: flex-end;
    color: white;
    background: var(--brand);
    border-radius: 10px 4px 10px 10px;
}

.message.error {
    align-self: center;
    max-width: 90%;
    color: #7d3434;
    text-align: center;
    background: var(--danger-soft);
    border: 1px solid #e8caca;
    border-radius: 9px;
    font-size: 0.84rem;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 13px clamp(16px, 4vw, 42px) 16px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.privacy-note {
    padding: 8px clamp(16px, 4vw, 42px) 0;
    color: var(--muted);
    background: var(--surface);
    font-size: 0.72rem;
    line-height: 1.4;
}

.chat-input-area input {
    min-width: 0;
    flex: 1;
    padding: 12px 14px;
    color: var(--ink);
    background: var(--surface-muted);
    border: 1px solid #cfd7df;
    border-radius: 7px;
    outline: none;
    font-size: 0.95rem;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.chat-input-area input::placeholder {
    color: #87929d;
}

.chat-input-area button {
    min-width: 88px;
    padding: 0 18px;
    color: white;
    background: var(--brand);
}

.chat-input-area button:hover {
    background: var(--brand-deep);
}

.chat-input-area button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
    width: 40px;
    padding: 5px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes message-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

@media (max-width: 640px) {
    body {
        padding: 0;
    }

    .chat-container {
        height: 100vh;
        min-height: 0;
        border: 0;
        border-radius: 0;
    }

    .chat-header {
        padding: 15px 16px;
    }

    .chat-header::after {
        right: 16px;
    }

    .config-panel {
        flex-wrap: wrap;
        padding: 12px 20px;
    }

    .config-panel span {
        width: 100%;
    }

    .message {
        max-width: 90%;
    }

    .chat-messages {
        padding-top: 22px;
        padding-bottom: 22px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
