/* SDK Agent — Supervisor Dashboard */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242836;
    --border: #2e3347;
    --text: #e4e6f0;
    --text-dim: #8b8fa3;
    --accent: #6c7cff;
    --accent-dim: #4a56b5;
    --green: #34d399;
    --red: #f87171;
    --orange: #fbbf24;
    --radius: 8px;
}

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

body {
    font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Auth Overlay */
.auth-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(15, 17, 23, 0.95);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
}
.auth-overlay.visible { opacity: 1; pointer-events: auto; }

.auth-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 36px;
    width: 100%; max-width: 380px;
    display: flex; flex-direction: column; gap: 16px;
    text-align: center;
}
.auth-logo {
    font-size: 20px; font-weight: 700; color: var(--accent);
    letter-spacing: -0.5px;
}
.auth-subtitle {
    font-size: 13px; color: var(--text-dim); margin-bottom: 8px;
}
.auth-input {
    width: 100%; padding: 10px 14px;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px;
    font-family: inherit; font-size: 14px; text-align: center;
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-btn {
    width: 100%; padding: 10px;
    background: var(--accent); color: #fff; border: none;
    border-radius: 6px; font-family: inherit; font-size: 14px;
    font-weight: 600; cursor: pointer;
}
.auth-btn:hover { background: var(--accent-dim); }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-btn-link {
    background: none; border: none; color: var(--text-dim);
    font-family: inherit; font-size: 12px; cursor: pointer;
    padding: 4px; width: 100%;
}
.auth-btn-link:hover { color: var(--text); }
.auth-otp-hint {
    font-size: 12px; color: var(--text-dim);
}
.auth-error {
    font-size: 12px; color: var(--red); min-height: 16px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 16px;
}
.header-left h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }
.header-left .subtitle { font-size: 12px; color: var(--text-dim); margin-left: 12px; }
.header-center { flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 12px; }

/* Nav Tabs */
.nav-tabs { display: flex; gap: 4px; }
.nav-tab {
    padding: 6px 14px; border-radius: 6px;
    background: transparent; border: 1px solid transparent;
    color: var(--text-dim); font-family: inherit;
    font-size: 12px; font-weight: 600; cursor: pointer;
    transition: all 0.2s;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active {
    color: var(--accent); background: var(--surface-2);
    border-color: var(--accent-dim);
}

/* User Badge */
.user-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px; border-radius: 6px;
    background: var(--surface-2);
}
.user-info { display: flex; flex-direction: column; align-items: flex-end; }
.user-name { font-size: 12px; font-weight: 600; color: var(--text); }
.user-email { font-size: 10px; color: var(--text-dim); }

/* History separator */
.msg.history-sep {
    border-top: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    padding: 4px 8px; margin: 4px 0;
}

.status-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 20px; font-size: 12px;
    background: var(--surface-2);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-badge.online .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-badge.offline .status-dot { background: var(--red); }

.mode-badge {
    padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 600;
    background: var(--accent-dim); color: #fff; letter-spacing: 1px;
}

/* Main layout */
main { padding: 20px 24px; display: flex; flex-direction: column; gap: 20px; }

.top-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.main-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; height: calc(100vh - 260px); min-height: 400px; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 13px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.card-body { padding: 16px; display: flex; gap: 24px; }

.metric { display: flex; flex-direction: column; align-items: center; }
.metric-value { font-size: 28px; font-weight: 700; color: var(--text); }
.metric-label { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

.external-link {
    font-size: 11px; color: var(--accent); text-decoration: none;
    padding: 2px 8px; border: 1px solid var(--accent-dim); border-radius: 4px;
}
.external-link:hover { background: var(--accent-dim); color: #fff; }

/* Project card metrics */
.metric-group { flex: 1; }
.metric-group-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.metric-row { display: flex; gap: 20px; }
.metric-divider { width: 1px; background: var(--border); margin: 0 4px; }

.card-footer {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px; border-top: 1px solid var(--border);
}
.conversion-label { font-size: 10px; color: var(--text-dim); white-space: nowrap; }
.conversion-bar {
    flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden;
}
.conversion-fill {
    height: 100%; background: var(--green); border-radius: 3px;
    transition: width 0.6s ease;
}
.conversion-pct { font-size: 12px; font-weight: 700; color: var(--green); min-width: 40px; text-align: right; }

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

.msg { max-width: 85%; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-dim); color: #fff; }
.msg.agent { align-self: flex-start; background: var(--surface-2); }
.msg.system { align-self: center; color: var(--text-dim); font-size: 11px; font-style: italic; }
.msg.streaming { border-left: 2px solid var(--accent); }

.chat-input-row { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
#chat-input {
    flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 6px; padding: 8px 12px; font-family: inherit; font-size: 13px; resize: none;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
.btn-send {
    padding: 8px 20px; background: var(--accent); color: #fff; border: none;
    border-radius: 6px; font-family: inherit; font-weight: 600; cursor: pointer;
    font-size: 13px;
}
.btn-send:hover { background: var(--accent-dim); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small {
    font-size: 11px; padding: 2px 8px; background: transparent; color: var(--text-dim);
    border: 1px solid var(--border); border-radius: 4px; cursor: pointer; font-family: inherit;
}
.btn-small:hover { color: var(--text); border-color: var(--text-dim); }

/* Activity Log */
.log-card { display: flex; flex-direction: column; }
.activity-log { flex: 1; overflow-y: auto; padding: 12px 16px; font-size: 12px; }

.log-entry { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: baseline; }
.log-time { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.log-type { font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 600; }
.log-type.tool { background: #1e3a5f; color: #60a5fa; }
.log-type.mode { background: #3b2f5e; color: #a78bfa; }
.log-type.error { background: #5f1e1e; color: var(--red); }
.log-type.info { background: #1e4d3a; color: var(--green); }
.log-msg { color: var(--text); }

#log-filter {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 4px; padding: 2px 8px; font-family: inherit; font-size: 11px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Tool Call Messages */
.msg.tool-call {
    align-self: flex-start;
    background: #1a2332;
    border: 1px solid #2a3a5a;
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 90%;
}
.msg.tool-call.tool-ok { border-left-color: var(--green); }
.msg.tool-call.tool-err { border-left-color: var(--red); }

.tool-icon { font-size: 16px; flex-shrink: 0; }
.tool-name { color: var(--accent); font-weight: 600; white-space: nowrap; }
.tool-args { color: var(--text-dim); font-size: 11px; margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.tool-args::before { content: '('; }
.tool-args::after { content: ')'; }

.tool-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: tool-spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes tool-spin { to { transform: rotate(360deg); } }

.tool-badge {
    font-size: 10px; padding: 1px 8px; border-radius: 3px;
    font-weight: 600; white-space: nowrap; margin-left: auto;
}
.tool-badge.ok { background: #1e4d3a; color: var(--green); }
.tool-badge.err { background: #5f1e1e; color: var(--red); }

/* Thinking indicator */
.msg.thinking {
    align-self: flex-start;
    background: var(--surface-2);
    border-left: 2px solid var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
}
.thinking-dots {
    display: flex;
    gap: 4px;
}
.thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: thinking-bounce 1.4s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinking-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}
.thinking-label {
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
}

/* Mic button */
.btn-mic {
    width: 44px; height: 44px; flex-shrink: 0;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 6px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    color: var(--text-dim); transition: all 0.2s;
}
.btn-mic:hover { border-color: var(--accent); color: var(--text); }
.btn-mic.recording {
    background: rgba(248, 113, 113, 0.2);
    border-color: var(--red);
    color: var(--red);
    animation: pulse-recording 1.5s infinite;
}
.btn-mic svg { pointer-events: none; }
@keyframes pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}

/* Auto-grow textarea */
#chat-input {
    min-height: 40px; max-height: 120px;
    overflow-y: auto;
}

/* Focus visible */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Prevent horizontal scroll */
body { overflow-x: hidden; }
.chat-messages { -webkit-overflow-scrolling: touch; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Responsive */
@media (max-width: 900px) {
    .top-row { grid-template-columns: 1fr; }
    .main-row { grid-template-columns: 1fr; height: auto; }
    .chat-card, .log-card { min-height: 400px; }
}

/* Tablet portrait */
@media (max-width: 768px) {
    .top-row { grid-template-columns: 1fr; }
    .main-row { grid-template-columns: 1fr; height: auto; }
    .chat-card, .log-card { min-height: 400px; }
    .log-card { max-height: 300px; }
}

/* Phone landscape */
@media (max-width: 640px) {
    header {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }
    .header-left { width: 100%; }
    .header-left h1 { font-size: 15px; }
    .header-left .subtitle { display: none; }
    .header-center { width: 100%; order: 3; }
    .header-right { margin-left: auto; }
    .nav-tabs { width: 100%; justify-content: center; }
    .user-email { display: none; }
    .mode-badge { display: none; }
}

/* Phone portrait */
@media (max-width: 480px) {
    main { padding: 12px; gap: 12px; }

    .top-row { gap: 10px; }
    .card-body { flex-direction: column; gap: 12px; }
    .metric-divider { width: 100%; height: 1px; margin: 0; }
    .metric-value { font-size: 22px; }
    .metric-row { justify-content: center; }

    .main-row { gap: 10px; }
    .chat-card { min-height: calc(100vh - 280px); }
    .log-card { max-height: 250px; }

    .chat-input-row { padding: 8px; gap: 6px; }
    #chat-input { font-size: 16px; padding: 10px; min-height: 44px; }
    .btn-send { min-width: 44px; min-height: 44px; padding: 10px 14px; font-size: 14px; }
    .btn-small { min-height: 36px; padding: 6px 10px; }

    .card-header { padding: 10px 12px; }
    .card-header h3 { font-size: 12px; }

    .msg { font-size: 14px; max-width: 92%; }
    .msg.tool-call { font-size: 12px; }
    .tool-args { max-width: 150px; }
}

/* Touch targets for coarse pointer devices */
@media (pointer: coarse) {
    .btn-send, .btn-small, .nav-tab, .external-link, #log-filter {
        min-height: 44px;
    }
    .nav-tab { padding: 10px 16px; }
    .external-link { padding: 8px 12px; }
    .auth-btn { min-height: 48px; font-size: 16px; }
    .auth-input { min-height: 48px; font-size: 16px; }
}
