* {
    box-sizing: border-box;
}

:root {
    --green: #007a3d;
    --green-2: #00a85a;
    --green-3: #063f28;
    --black: #101316;
    --white: #ffffff;
    --red: #ce1126;
    --ink: #111827;
    --muted: #667085;
    --soft: #f6fbf8;
    --line: rgba(16, 19, 22, 0.10);
    --panel: rgba(255,255,255,0.80);
    --panel-strong: rgba(255,255,255,0.94);
    --shadow: 0 22px 70px rgba(16, 19, 22, 0.13);
    --shadow-soft: 0 12px 34px rgba(16, 19, 22, 0.08);
    --radius-xl: 30px;
    --radius-lg: 24px;
    --radius-md: 18px;
    --font: Tahoma, Arial, sans-serif;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    font-family: var(--font);
    background:
        radial-gradient(circle at 12% 10%, rgba(0, 168, 90, 0.20), transparent 27%),
        radial-gradient(circle at 90% 90%, rgba(206, 17, 38, 0.10), transparent 24%),
        linear-gradient(135deg, #f3fff8 0%, #ffffff 44%, #f5f7fb 100%);
    overflow: hidden;
}

button,
textarea {
    font-family: inherit;
}

button {
    border: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

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

.backdrop-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.36;
    background-image:
        linear-gradient(rgba(16,19,22,0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(16,19,22,0.035) 1px, transparent 1px);
    background-size: 44px 44px;
}

.glow {
    position: fixed;
    width: 420px;
    height: 420px;
    border-radius: 50%;
    filter: blur(72px);
    pointer-events: none;
    z-index: 0;
}

.glow-a {
    top: -160px;
    right: -110px;
    background: rgba(0, 168, 90, 0.36);
}

.glow-b {
    bottom: -170px;
    left: -110px;
    background: rgba(16, 19, 22, 0.16);
}

.app {
    position: relative;
    z-index: 1;
    width: min(1440px, calc(100vw - 30px));
    height: calc(100vh - 30px);
    margin: 15px auto;
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    gap: 16px;
}

.sidebar,
.chat-shell {
    min-height: 0;
    border: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
}

.sidebar {
    border-radius: var(--radius-xl);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 13px;
    overflow-y: auto;
}

.brand-card,
.side-panel {
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.brand-card {
    position: relative;
    padding: 16px;
    overflow: hidden;
}

.flag-line {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    margin-bottom: 17px;
    box-shadow: inset 0 0 0 1px rgba(16,19,22,0.06);
}

.flag-green { background: var(--green); }
.flag-white {
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: var(--red);
    font-size: 8px;
}
.flag-black { background: var(--black); }

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

.brand-logo {
    width: 58px;
    height: 58px;
    border-radius: 21px;
    color: white;
    display: grid;
    place-items: center;
    font-weight: 900;
    font-size: 25px;
    background: linear-gradient(135deg, var(--green), var(--black));
    box-shadow: 0 14px 30px rgba(0, 122, 61, 0.24);
}

.brand-card h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -0.4px;
}

.brand-card p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.7;
    font-size: 13px;
}

.primary-side-btn {
    width: 100%;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border-radius: 19px;
    color: white;
    font-weight: 900;
    font-size: 15px;
    background: linear-gradient(135deg, var(--green), var(--green-3));
    box-shadow: 0 18px 34px rgba(0, 122, 61, 0.24);
}

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

.side-panel {
    padding: 15px;
}

.panel-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-title span {
    font-weight: 900;
    color: var(--black);
}

.panel-title small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
    text-align: left;
}

.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mode-btn,
.quick-btn,
.ghost-btn,
.welcome-prompt {
    transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease;
}

.mode-btn {
    min-height: 40px;
    border-radius: 14px;
    color: var(--ink);
    background: rgba(16,19,22,0.045);
    font-weight: 800;
}

.mode-btn:hover {
    background: rgba(0, 122, 61, 0.10);
}

.mode-btn.active {
    color: white;
    background: linear-gradient(135deg, var(--green), var(--black));
    box-shadow: 0 10px 24px rgba(0, 122, 61, 0.16);
}

.quick-list {
    display: grid;
    gap: 8px;
}

.quick-btn {
    width: 100%;
    min-height: 43px;
    padding: 10px 12px;
    border-radius: 15px;
    color: var(--ink);
    background: rgba(0, 122, 61, 0.07);
    text-align: right;
    font-weight: 800;
    line-height: 1.6;
}

.quick-btn:hover {
    transform: translateX(-2px);
    background: rgba(0, 122, 61, 0.12);
}

.status-box {
    display: grid;
    grid-template-columns: 13px 1fr;
    gap: 8px 10px;
    align-items: center;
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--green-2);
    box-shadow: 0 0 0 7px rgba(0, 168, 90, 0.12);
}

.status-dot.busy {
    background: #f59e0b;
    box-shadow: 0 0 0 7px rgba(245, 158, 11, 0.16);
}

.status-dot.error {
    background: var(--red);
    box-shadow: 0 0 0 7px rgba(206, 17, 38, 0.13);
}

.status-box strong {
    font-size: 14px;
}

.status-box em {
    grid-column: 2;
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
}

.chat-shell {
    position: relative;
    height: 100%;
    border-radius: var(--radius-xl);
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    overflow: hidden;
}

.topbar {
    min-height: 82px;
    padding: 17px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,0.72);
}

.mobile-menu {
    display: none;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: white;
    border: 1px solid var(--line);
    font-size: 20px;
}

.kicker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--green);
    font-weight: 900;
    font-size: 12px;
    text-transform: uppercase;
}

.kicker::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
}

.topbar h2 {
    margin: 5px 0 0;
    font-size: clamp(18px, 2.1vw, 28px);
    letter-spacing: -0.5px;
}

.top-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.ghost-btn {
    min-height: 42px;
    padding: 0 14px;
    border-radius: 14px;
    color: var(--black);
    background: #fff;
    border: 1px solid var(--line);
    font-weight: 900;
}

.ghost-btn:hover {
    box-shadow: 0 10px 24px rgba(16,19,22,0.08);
    border-color: rgba(0,122,61,0.22);
}

.welcome-panel {
    position: relative;
    margin: 18px 22px 0;
    padding: 24px;
    border-radius: 28px;
    color: white;
    overflow: hidden;
    background:
        radial-gradient(circle at 15% 95%, rgba(206,17,38,0.22), transparent 31%),
        linear-gradient(120deg, rgba(0,122,61,0.98), rgba(16,19,22,0.97));
    box-shadow: 0 24px 54px rgba(0,122,61,0.16);
}

.welcome-panel.hidden {
    display: none;
}

.welcome-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0 34%, rgba(255,255,255,0.16) 34% 64%, transparent 64%);
    opacity: .75;
}

.welcome-content,
.flag-card {
    position: relative;
    z-index: 1;
}

.welcome-badge {
    display: inline-flex;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.13);
    border: 1px solid rgba(255,255,255,0.20);
    font-weight: 900;
    font-size: 13px;
}

.welcome-panel h3 {
    margin: 13px 0 8px;
    font-size: clamp(26px, 3.4vw, 46px);
    letter-spacing: -0.8px;
}

.welcome-panel p {
    max-width: 760px;
    margin: 0;
    color: rgba(255,255,255,0.82);
    line-height: 1.9;
}

.welcome-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.welcome-prompt {
    min-height: 40px;
    padding: 0 13px;
    border-radius: 999px;
    color: white;
    background: rgba(255,255,255,0.13);
    border: 1px solid rgba(255,255,255,0.20);
    font-weight: 800;
}

.welcome-prompt:hover {
    background: rgba(255,255,255,0.20);
}

.flag-card {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%) rotate(-8deg);
    width: 100px;
    height: 72px;
    border-radius: 18px;
    overflow: hidden;
    display: grid;
    grid-template-rows: 1fr 1fr 1fr;
    box-shadow: 0 20px 50px rgba(0,0,0,0.18);
    opacity: 0.9;
}

.flag-card span:nth-child(1) { background: var(--green); }
.flag-card span:nth-child(2) {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: white;
    color: var(--red);
    font-size: 11px;
}
.flag-card span:nth-child(3) { background: var(--black); }

.messages-wrap {
    position: relative;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 22px 20px;
    scroll-behavior: smooth;
}

.messages {
    min-height: 100%;
    padding-bottom: 4px;
}

.message {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 18px;
    animation: messageIn .18s ease both;
}

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

.message.user .avatar {
    grid-column: 2;
}

.message.user .bubble {
    grid-column: 1;
    justify-self: end;
}

.avatar {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 17px;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 12px 26px rgba(16,19,22,0.13);
}

.avatar.assistant {
    color: white;
    background: linear-gradient(135deg, var(--green), var(--black));
}

.avatar.user-avatar {
    color: var(--green);
    background: #fff;
    border: 1px solid rgba(0,122,61,0.18);
}

.bubble {
    width: fit-content;
    max-width: min(850px, 92%);
    padding: 15px 16px 13px;
    border-radius: 24px;
    border: 1px solid rgba(16,19,22,0.08);
    background: rgba(255,255,255,0.94);
    box-shadow: 0 18px 42px rgba(16,19,22,0.08);
    overflow: hidden;
}

.message.user .bubble {
    color: white;
    background: linear-gradient(135deg, var(--green), #063f28);
    border-color: rgba(255,255,255,0.20);
}

.message.error .bubble {
    color: #981225;
    background: #fff7f8;
    border-color: rgba(206,17,38,0.24);
}

.meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    color: var(--green);
    font-size: 12px;
    font-weight: 900;
}

.message.user .meta {
    color: rgba(255,255,255,0.76);
}

.meta time {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.message.user .meta time {
    color: rgba(255,255,255,0.66);
}

.content {
    line-height: 1.9;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.content p {
    margin: 0 0 10px;
}

.content p:last-child {
    margin-bottom: 0;
}

.content strong {
    font-weight: 900;
}

.content code {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(16,19,22,0.08);
    font-family: Consolas, Monaco, monospace;
}

.content pre {
    direction: ltr;
    text-align: left;
    overflow-x: auto;
    max-width: 100%;
    padding: 14px;
    border-radius: 16px;
    background: #0f172a;
    color: #f8fafc;
    line-height: 1.7;
    white-space: pre;
}

.message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 11px;
}

.action-chip {
    min-height: 31px;
    padding: 0 10px;
    border-radius: 999px;
    color: var(--black);
    background: rgba(0,122,61,0.08);
    font-size: 12px;
    font-weight: 800;
}

.action-chip:hover {
    background: rgba(0,122,61,0.14);
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 18px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    animation: bounce 1.05s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: .14s; }
.typing-dots span:nth-child(3) { animation-delay: .28s; }

.messages-end {
    height: 1px;
}

.jump-bottom {
    position: sticky;
    bottom: 0;
    margin: 0 auto;
    display: none;
    min-height: 38px;
    padding: 0 13px;
    border-radius: 999px;
    color: white;
    background: var(--black);
    box-shadow: 0 12px 28px rgba(16,19,22,0.18);
    font-weight: 900;
}

.jump-bottom.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.composer {
    padding: 14px 22px 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,0.86) 25%);
}

.composer-box {
    border-radius: 25px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.96);
    box-shadow: 0 18px 46px rgba(16,19,22,0.09);
    padding: 12px;
}

#messageInput {
    width: 100%;
    min-height: 48px;
    max-height: 210px;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.8;
    padding: 3px 4px 6px;
}

#messageInput::placeholder {
    color: #94a3b8;
}

.composer-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid rgba(16,19,22,0.07);
    padding-top: 10px;
}

.hint {
    color: #7b8798;
    font-size: 12px;
    line-height: 1.6;
    margin-inline-end: auto;
}

.counter {
    color: #667085;
    font-size: 12px;
    direction: ltr;
    white-space: nowrap;
}

.send-btn {
    min-width: 122px;
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border-radius: 17px;
    color: white;
    background: linear-gradient(135deg, var(--green), var(--black));
    font-weight: 900;
    box-shadow: 0 13px 28px rgba(0,122,61,0.20);
}

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

.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 30;
    transform: translateX(-50%) translateY(16px);
    opacity: 0;
    pointer-events: none;
    padding: 12px 16px;
    border-radius: 999px;
    color: white;
    background: rgba(16,19,22,0.92);
    box-shadow: 0 18px 40px rgba(16,19,22,0.22);
    transition: .18s ease;
    font-weight: 800;
}

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

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

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: .45; }
    40% { transform: translateY(-5px); opacity: 1; }
}

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

    .app {
        width: min(100%, calc(100vw - 16px));
        height: auto;
        min-height: calc(100vh - 16px);
        margin: 8px auto;
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        z-index: 20;
        top: 10px;
        right: 10px;
        bottom: 10px;
        width: min(330px, calc(100vw - 20px));
        transform: translateX(calc(100% + 20px));
        transition: transform .22s ease;
    }

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

    .chat-shell {
        min-height: calc(100vh - 16px);
    }

    .mobile-menu {
        display: grid;
        place-items: center;
    }

    .welcome-panel {
        margin: 12px 12px 0;
        padding: 20px;
    }

    .flag-card {
        display: none;
    }

    .messages-wrap {
        padding: 16px 12px 16px;
    }

    .composer {
        padding: 10px 12px 14px;
    }

    .topbar {
        padding: 13px 12px;
    }

    .topbar h2 {
        font-size: 17px;
    }

    .top-actions {
        gap: 6px;
    }

    .ghost-btn {
        padding: 0 10px;
        min-height: 39px;
    }

    .bubble {
        max-width: 100%;
    }

    .hint {
        display: none;
    }
}

@media (max-width: 620px) {
    .topbar {
        flex-wrap: wrap;
    }

    .topbar-title {
        min-width: 0;
        flex: 1;
    }

    .top-actions {
        width: 100%;
        justify-content: flex-start;
    }

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

    .message.user .avatar {
        grid-column: 1;
    }

    .message.user .bubble {
        grid-column: 2;
        justify-self: stretch;
    }

    .avatar {
        width: 38px;
        height: 38px;
        border-radius: 14px;
        font-size: 12px;
    }

    .composer-footer {
        flex-wrap: wrap;
    }

    .send-btn {
        min-width: 100%;
    }

    .counter {
        margin-inline-start: auto;
    }
}
