:root {
    --page: #f7f7f5;
    --surface: #ffffff;
    --muted: #f3f3f0;
    --border: #e6e5e0;
    --ink: #0f1419;
    --muted-text: #6b6f78;
    --success: #2f7a4d;
    --warn: #a76a14;
    --danger: #b54a3b;
    --info: #2a5d8f;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --shadow-subtle: 0 1px 2px rgba(15, 20, 25, 0.04);
    --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    background: var(--page);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.55;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled,
select:disabled,
textarea:disabled {
    cursor: not-allowed;
}

.app-page {
    padding: 24px;
}

.app-shell {
    width: min(1160px, 100%);
    margin: 0 auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 14px;
}

.brand-mark,
.login-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-subtle);
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
}

.brand-mark img,
.login-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.eyebrow {
    color: var(--muted-text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

.main-title {
    color: var(--ink);
    font-size: clamp(28px, 4vw, 44px);
    font-weight: 600;
    line-height: 1.08;
}

.provider-panel {
    display: grid;
    grid-template-columns: auto minmax(180px, 260px);
    align-items: center;
    gap: 8px 12px;
    min-width: min(100%, 380px);
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-subtle);
}

.provider-label {
    color: var(--muted-text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
}

.provider-select {
    width: 100%;
    min-height: 40px;
    padding: 0 34px 0 12px;
    border: 1px solid #d4d2ca;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    appearance: none;
}

.provider-select:focus {
    outline: none;
    border-color: var(--success);
    box-shadow: 0 0 0 3px rgba(47, 122, 77, 0.14);
}

.provider-select:disabled {
    background: var(--muted);
    color: var(--muted-text);
}

.provider-status {
    grid-column: 1 / -1;
    color: var(--muted-text);
    font-size: 12px;
}

.provider-status.ready {
    color: var(--success);
}

.provider-status.error {
    color: var(--danger);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.chat-section,
.input-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-subtle);
}

.chat-section {
    min-height: min(680px, calc(100vh - 210px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
}

.chat-title {
    color: var(--ink);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.2;
}

.counter-chip,
.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--muted);
    color: var(--muted-text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

#progress-anchor {
    display: contents;
}

.progress-container {
    display: none;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--muted);
}

.progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    color: var(--muted-text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
}

.progress-track {
    width: 100%;
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #dfded8;
}

.progress-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--success);
    transition: width 0.35s ease;
}

.chat-container {
    flex: 1;
    min-height: 380px;
    max-height: calc(100vh - 320px);
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 10px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    border: 3px solid var(--surface);
    border-radius: 999px;
    background: #d6d5cf;
}

.message {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    margin-bottom: 12px;
    animation: message-in 0.18s ease-out;
}

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

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

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

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--muted-text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    width: fit-content;
    max-width: min(720px, 100%);
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.assistant-message .message-content {
    background: var(--muted);
}

.user-message .message-content {
    border-color: rgba(47, 122, 77, 0.26);
    background: #e7f2ea;
}

.message-content p {
    margin-bottom: 10px;
}

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

.loading-message {
    opacity: 0.9;
}

.loading-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted-text);
}

.loading-text::after {
    width: 18px;
    color: var(--success);
    content: "...";
    animation: loading-dots 1.2s steps(4, end) infinite;
}

@keyframes loading-dots {
    0%, 20% {
        content: ".";
    }
    40% {
        content: "..";
    }
    60%, 100% {
        content: "...";
    }
}

.input-section {
    padding: 14px;
}

.input-container {
    margin-bottom: 10px;
}

#message-input {
    display: block;
    width: 100%;
    min-height: 96px;
    max-height: 220px;
    resize: vertical;
    padding: 13px 14px;
    border: 1px solid #d4d2ca;
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
}

#message-input:focus {
    outline: none;
    border-color: var(--success);
    box-shadow: 0 0 0 3px rgba(47, 122, 77, 0.14);
}

#message-input::placeholder {
    color: #8b8f88;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink);
    font-size: 18px;
    font-weight: 600;
    line-height: 1;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn-primary {
    background: #34cf8b;
    color: var(--ink);
}

.btn-primary:hover {
    background: #2fc07f;
}

.btn-icon,
.btn-ghost {
    border-color: #d4d2ca;
    background: var(--surface);
}

.btn-icon:hover,
.btn-ghost:hover {
    border-color: var(--success);
    background: #edf6f0;
}

.btn-icon.recording {
    border-color: rgba(181, 74, 59, 0.36);
    background: #f5e5e2;
    color: var(--danger);
}

.btn:disabled {
    opacity: 0.46;
}

.recording-status {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    margin-left: auto;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    background: #f9ead9;
    color: var(--warn);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
}

.recording-status.hidden {
    display: none;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-box {
    width: min(380px, 100%);
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-subtle);
}

.login-mark {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    border-radius: var(--radius-lg);
}

.login-box h1 {
    margin: 4px 0 20px;
    color: var(--ink);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.2;
}

.login-box label {
    display: block;
    margin: 14px 0 6px;
    color: var(--muted-text);
    font-size: 12px;
    font-weight: 500;
}

.login-box input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid #d4d2ca;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
}

.login-box input:focus {
    outline: none;
    border-color: var(--success);
    box-shadow: 0 0 0 3px rgba(47, 122, 77, 0.14);
}

.login-submit {
    width: 100%;
    height: 42px;
    margin-top: 20px;
    border: 0;
    border-radius: var(--radius-sm);
    background: #34cf8b;
    color: var(--ink);
    font-weight: 600;
}

.login-submit:hover {
    background: #2fc07f;
}

.error {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: #f5e5e2;
    color: var(--danger);
    font-size: 13px;
}

@media (max-width: 760px) {
    .app-page,
    .login-page {
        padding: 12px;
    }

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

    .provider-panel {
        grid-template-columns: 1fr;
        min-width: 0;
    }

    .main-title {
        font-size: 30px;
    }

    .chat-title {
        font-size: 22px;
    }

    .section-header {
        padding: 14px;
    }

    .chat-container {
        min-height: 360px;
        max-height: calc(100vh - 360px);
        padding: 14px;
    }

    .message-content {
        max-width: 100%;
    }

    .counter-chip {
        min-height: 28px;
        padding: 0 10px;
    }
}

@media (max-width: 480px) {
    .brand-mark {
        width: 42px;
        height: 42px;
    }

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

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

    .user-message .message-content {
        grid-column: 2;
        justify-self: start;
    }

    .message-avatar {
        width: 30px;
        height: 30px;
    }

    .controls-row {
        flex-wrap: wrap;
    }

    .recording-status {
        width: 100%;
        margin-left: 0;
    }
}
