:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --accent: #58a6ff;
    --accent-hover: #1f6feb;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --border-color: #30363d;
    --user-bubble: #1f6feb;
    --assistant-bubble: #21262d;
    --danger: #f85149;
    --success: #3fb950;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

.app-body {
    justify-content: flex-start;
    align-items: stretch;
}

/* ================= Login Screen ================= */
.login-body {
    align-items: center;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.logo-container .logo-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.logo-container h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-container .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 6px;
    margin-bottom: 30px;
}

.alert {
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 20px;
}

.alert-error {
    background: rgba(248, 81, 73, 0.15);
    border: 1px solid var(--danger);
    color: #ff7b72;
}

.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    margin-bottom: 12px;
}

.btn-oauth:hover {
    background: #30363d;
    border-color: #8b949e;
}

.dev-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
}

.login-footer {
    margin-top: 28px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* ================= Chat App Interface ================= */
.app-container {
    width: 100%;
    min-height: 100vh;
    background: var(--bg-primary);
}

.app-workspace {
    width: 100%;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
}

.chat-sidebar {
    background: linear-gradient(180deg, rgba(22, 27, 34, 0.98), rgba(13, 17, 23, 0.98));
    border-right: 1px solid var(--border-color);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-kicker {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 4px;
}

.sidebar-header h3 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.sidebar-new-btn {
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.sidebar-new-btn:hover {
    border-color: var(--accent);
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-right: 2px;
}

.chat-list-item {
    width: 100%;
    text-align: left;
    border: 1px solid var(--border-color);
    background: rgba(33, 38, 45, 0.85);
    color: var(--text-primary);
    border-radius: 14px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.18s ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-list-item:hover {
    background: rgba(38, 44, 52, 0.95);
    border-color: rgba(88, 166, 255, 0.35);
}

.chat-list-item.active {
    background: rgba(31, 111, 235, 0.15);
    border-color: rgba(88, 166, 255, 0.55);
}

.chat-list-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}

.chat-list-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.chat-list-empty {
    color: var(--text-secondary);
    font-size: 13px;
    padding: 12px 4px;
}

.chat-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg-primary);
}

.agent-status {
    margin: 10px 20px 0;
    padding: 8px 12px;
    align-self: flex-start;
    max-width: calc(100% - 40px);
    border: 1px solid rgba(88, 166, 255, 0.18);
    border-radius: 999px;
    background: rgba(33, 38, 45, 0.78);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.2;
    backdrop-filter: blur(10px);
}

.agent-status strong {
    color: var(--text-primary);
    font-weight: 700;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

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

.brand-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1f6feb, #8957e5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.brand-info h2 {
    font-size: 16px;
    font-weight: 600;
}

.status-badge {
    font-size: 11px;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.header-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.admin-link {
    color: var(--accent);
    border-color: rgba(88, 166, 255, 0.35);
}

.admin-link:hover {
    background: rgba(88, 166, 255, 0.1);
    color: #9fd0ff;
}

.voice-toggle {
    gap: 8px;
    cursor: pointer;
}

.voice-toggle-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--success);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.8);
}

.voice-toggle.voice-off {
    color: var(--text-secondary);
    border-color: rgba(139, 148, 158, 0.35);
}

.voice-toggle.voice-off .voice-toggle-dot {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(248, 81, 73, 0.8);
}

.stop-speaking-btn {
    color: var(--text-primary);
    border-color: rgba(248, 81, 73, 0.35);
    background: rgba(248, 81, 73, 0.08);
}

.stop-speaking-btn:hover {
    background: rgba(248, 81, 73, 0.16);
    border-color: rgba(248, 81, 73, 0.65);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ================= Admin Pages ================= */
.admin-body {
    align-items: flex-start;
    padding: 24px;
}

.admin-shell {
    width: 100%;
    max-width: 960px;
}

.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px;
    margin-bottom: 18px;
    background: linear-gradient(135deg, rgba(22, 27, 34, 0.96), rgba(17, 23, 35, 0.96));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
}

.admin-kicker {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.admin-topbar h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.admin-topbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-topbar-link,
.admin-inline-link {
    color: var(--text-primary);
    text-decoration: none;
}

.admin-topbar-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    font-size: 13px;
    font-weight: 600;
}

.admin-topbar-link:hover {
    background: var(--bg-tertiary);
}

.admin-content {
    padding: 4px 2px 0;
}

.admin-hero {
    margin-bottom: 18px;
}

.admin-intro {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.admin-card {
    display: block;
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.admin-card:hover {
    transform: translateY(-2px);
    border-color: rgba(88, 166, 255, 0.45);
    background: #1b212b;
}

.admin-card-eyebrow {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.admin-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.admin-card p {
    color: var(--text-secondary);
    line-height: 1.55;
}

.admin-form {
    display: grid;
    gap: 12px;
    max-width: 520px;
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.admin-form label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.admin-form select {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
}

.admin-primary-btn {
    margin-top: 6px;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-weight: 700;
    cursor: pointer;
}

.admin-primary-btn:hover {
    background: var(--accent-hover);
}

.admin-status {
    margin-top: 14px;
    color: var(--success);
    font-size: 14px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.2s ease-in-out;
}

.user-message {
    align-self: flex-end;
}

.assistant-message {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14.5px;
    line-height: 1.55;
    word-break: break-word;
}

.user-message .message-bubble {
    background: var(--user-bubble);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.assistant-message .message-bubble {
    background: var(--assistant-bubble);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: flex;
    gap: 8px;
}

.tool-badge {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
}

/* Voice Status Bar */
.voice-status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(31, 111, 235, 0.15);
    border-top: 1px solid var(--accent);
    padding: 10px 16px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
}

.voice-status-copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: min(100%, 560px);
}

.voice-transcript {
    color: #c7d2fe;
    font-size: 13px;
    line-height: 1.4;
    font-style: italic;
    word-break: break-word;
}

.pulse-wave {
    display: flex;
    gap: 4px;
    align-items: center;
}

.pulse-wave span {
    width: 3px;
    height: 12px;
    background: var(--accent);
    border-radius: 2px;
    animation: wave 1s infinite ease-in-out;
}

.pulse-wave span:nth-child(2) { animation-delay: 0.2s; height: 18px; }
.pulse-wave span:nth-child(3) { animation-delay: 0.4s; height: 24px; }
.pulse-wave span:nth-child(4) { animation-delay: 0.2s; height: 18px; }
.pulse-wave span:nth-child(5) { animation-delay: 0s; height: 12px; }

@keyframes wave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1.3); }
}

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

/* Input Container */
.input-container {
    padding: 14px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 6px 10px;
    gap: 8px;
}

.chat-form:focus-within {
    border-color: var(--accent);
}

.chat-form textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14.5px;
    resize: none;
    outline: none;
    max-height: 120px;
    padding: 8px 4px;
    line-height: 1.4;
}

.mic-button, .send-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mic-button:hover, .send-button:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

.mic-button.recording {
    background: var(--danger) !important;
    color: #ffffff !important;
    animation: pulseMic 1.5s infinite;
}

@keyframes pulseMic {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(248, 81, 73, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(248, 81, 73, 0); }
}

.hidden {
    display: none !important;
}

@media (max-width: 900px) {
    .app-workspace {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        min-height: auto;
    }
}
