@font-face {
    font-family: "JetBrains Sans";
    src: url("fonts/JetBrainsSans-Regular.woff2");
}

@font-face {
    font-family: "JetBrains Mono";
    src: url("fonts/JetBrainsMono-Regular.woff2");
}

:root {
    --bg-body: #0f0f10;
    --bg-card: rgba(22, 22, 24, 0.92);
    --bg-input: rgba(35, 35, 38, 0.95);
    --bg-bottom: #111113;
    --text-primary: rgba(255, 255, 255, 0.87);
    --text-secondary: rgba(255, 255, 255, 0.5);
    --text-muted: rgba(255, 255, 255, 0.38);
    --border-color: rgba(255, 255, 255, 0.12);
    --accent-green: #00dc82;
    --user-bubble: #1a2a1e;
    --user-border: rgba(0, 220, 130, 0.25);
    --danger-bg: rgba(117, 41, 41, 0.3);
    --danger-border: rgba(255, 96, 96, 0.3);
    --danger-text: rgba(255, 96, 96, 0.9);
    --radius-card: 28px;
    --radius-input: 12px;
    --radius-pill: 999px;
    --font-sans: "JetBrains Sans", Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", Inter, system-ui, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-weight: 300;
    color: var(--text-primary);
    background-color: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ----- App Shell: both screens get the same centered card ---- */
.app-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.page-container,
.chat-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ----- Desktop: both views get the same framed card ----- */
@media (min-width: 640px) {
    .app-shell {
        padding: 24px;
    }

    .page-container,
    .chat-container {
        height: 100%;
        max-height: 100%;
        border: 1px solid var(--border-color);
        border-radius: 32px;
        background: var(--bg-body);
        padding: 22px 18px 24px;
        max-width: 480px;
        overflow: hidden;
    }

    .bottom-bar {
        margin: 0 -18px -24px !important;
        border-radius: 0 0 32px 32px !important;
        padding-left: 18px !important;
        padding-right: 18px !important;
    }

    .chat-messages {
        max-height: none;
        flex: 1;
    }
}

/* ----- Top Bar ----- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0 10px;
    gap: 12px;
    flex-shrink: 0;
}

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

.logo-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-name {
    font-size: 17px;
    font-weight: 500;
    letter-spacing: 0.2px;
    line-height: 1.15;
}

.brand-sub {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.3;
}

.status-area {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    flex-shrink: 0;
}

.status-text {
    font-size: 11.5px;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.25);
}

.icon-btn.settings {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
}

/* ----- Settings ----- */
.settings-scroll {
    flex: 1;
    overflow-y: auto;
    padding-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

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

.section-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 4px;
}

.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-card);
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.field {
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: -6px;
}

.input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    padding: 13px 14px;
    outline: none;
    transition: border-color 0.15s;
}

.input:focus {
    border-color: rgba(255, 255, 255, 0.28);
}

.input-mono {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.2px;
}

.helper {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    margin: -10px 0 0;
    line-height: 1.4;
    word-break: break-all;
}

.password-field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    padding: 0 4px 0 14px;
    transition: border-color 0.15s;
}

.password-field:focus-within {
    border-color: rgba(255, 255, 255, 0.28);
}

.password-field .input {
    background: transparent;
    border: none;
    padding: 13px 0;
    flex: 1;
    min-width: 0;
}

.password-field .input:focus {
    border: none;
}

.show-toggle {
    font-family: var(--font-mono);
    font-size: 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 10px;
    border-radius: var(--radius-pill);
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
}

.show-toggle:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 400;
    padding: 13px 20px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.secondary-btn:hover {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.04);
}

.danger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-pill);
    color: var(--danger-text);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 400;
    padding: 13px 20px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.danger-btn:hover {
    background: rgba(117, 41, 41, 0.45);
    border-color: rgba(255, 96, 96, 0.45);
}

.plain-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    color: inherit;
}

.bottom-spacer {
    height: 30px;
    flex-shrink: 0;
}

/* ----- Bottom Bar ----- */
.bottom-bar {
    position: sticky;
    bottom: 0;
    background: var(--bg-bottom);
    padding: 14px 0 10px;
    border-top: 1px solid var(--border-color);
    margin: 0 -14px;
    padding-left: 14px;
    padding-right: 14px;
}

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: var(--accent-green);
    border: none;
    border-radius: var(--radius-pill);
    color: #001a0b;
    font-family: var(--font-sans);
    font-size: 15px;
    font-weight: 500;
    padding: 15px 20px;
    cursor: pointer;
    letter-spacing: 0.1px;
    transition: opacity 0.15s, transform 0.05s;
}

.primary-btn:hover {
    opacity: 0.92;
}

.primary-btn:active {
    transform: scale(0.985);
}

/* ----- Chat View ----- */
.chat-container {
    display: flex;
    flex-direction: column;
    background: var(--bg-body);
}

.chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border-color);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ----- Empty state ----- */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: var(--text-muted);
}

.empty-text {
    font-size: 14px;
    letter-spacing: 0.3px;
}

/* ----- Message Rows (minimal layout) ----- */
.message-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.message-row.user {
    align-items: flex-end;
}

.message-row.assistant {
    align-items: flex-start;
}

/* ----- Bubbles ----- */
.bubble {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 20px;
    border: 1px solid transparent;
    position: relative;
}

/* User bubbles: distinct style */
.user-bubble {
    background: var(--user-bubble);
    border: none;
    border-bottom-right-radius: 4px;
}

.user-bubble .bubble-body {
    color: rgba(255, 255, 255, 0.92);
}

.user-bubble .bubble-time {
    color: rgba(0, 220, 130, 0.5);
}

/* Assistant bubbles: transparent/minimal */
.assistant-bubble {
    background: transparent;
    border: none;
    border-radius: 0;
    padding-left: 0;
    padding-right: 0;
}

.assistant-bubble .bubble-body {
    color: var(--text-primary);
}

/* Tool Bar - placed above bubble for assistant */
.tool-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-left: 2px;
}

.tool-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.3px;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

.tool-icon {
    font-size: 9px;
}

.tool-chip.running {
    border-color: rgba(255, 255, 255, 0.25);
    color: var(--text-primary);
}

.tool-chip.completed {
    border-color: rgba(0, 220, 130, 0.35);
    color: rgba(0, 220, 130, 0.9);
}

.tool-chip.failed {
    border-color: rgba(255, 96, 96, 0.35);
    color: rgba(255, 96, 96, 0.9);
}

.tool-status-label {
    opacity: 0.7;
}

/* Thinking */
.bubble-thinking {
    font-style: italic;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.thinking-icon {
    animation: spin 1.2s linear infinite;
    font-size: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.typing-indicator .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-green);
    animation: bounce 1.2s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

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

/* Body */
.bubble-body {
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
}

.bubble-body p {
    margin: 0 0 10px;
}

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

.bubble-body h1, .bubble-body h2, .bubble-body h3, .bubble-body h4, .bubble-body h5, .bubble-body h6 {
    font-size: 16px;
    font-weight: 600;
    margin: 12px 0 8px;
    line-height: 1.3;
}

.bubble-body h1:first-child, .bubble-body h2:first-child, .bubble-body h3:first-child {
    margin-top: 0;
}

.bubble-body ul, .bubble-body ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bubble-body li {
    margin: 4px 0;
}

.bubble-body code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 5px;
    border-radius: 4px;
}

.bubble-body pre {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
}

.bubble-body pre code {
    background: transparent;
    padding: 0;
}

.bubble-body blockquote {
    border-left: 3px solid var(--border-color);
    padding-left: 12px;
    margin: 10px 0;
    color: var(--text-secondary);
}

.bubble-body a {
    color: var(--accent-green);
    text-decoration: none;
}

.bubble-body a:hover {
    text-decoration: underline;
}

.bubble-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

.bubble-body th, .bubble-body td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
}

.bubble-body th {
    background: rgba(255, 255, 255, 0.05);
}

.bubble-image {
    display: block;
    max-width: 100%;
    border-radius: 12px;
    margin-top: 6px;
    border: 1px solid var(--border-color);
}

.bubble-time {
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 2px;
}

/* Confirmation card */
.confirmation-card {
    margin-top: 6px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.04);
}

.confirmation-card strong {
    font-size: 13px;
    display: block;
    margin-bottom: 4px;
}

.confirmation-card p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 0 4px;
}

.confirmation-card ul {
    margin: 6px 0 0;
    padding-left: 16px;
    color: var(--text-secondary);
    font-size: 12px;
}

/* ----- Compose Area ----- */
.compose-area {
    position: sticky;
    bottom: 0;
    background: var(--bg-bottom);
    border-top: 1px solid var(--border-color);
    padding: 10px 14px 12px;
    flex-shrink: 0;
}

.compose-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 6px 6px 6px 14px;
}

.compose-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    padding: 10px 0;
}

.compose-input:disabled {
    opacity: 0.5;
}

.send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--accent-green);
    color: #001a0b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ----- Test Result Feedback ----- */
.test-result {
    margin: -8px 0 0;
    font-size: 12px;
    padding: 0 4px;
}

.test-result.success {
    color: var(--accent-green);
}

.test-result.error {
    color: rgba(255, 96, 96, 0.9);
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar,
.settings-scroll::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track,
.settings-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.settings-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}