:root {
    color-scheme: dark;
    --bg: #0d0f14;
    --panel: #151821;
    --panel-2: #1b1f2b;
    --border: #2a2f3d;
    --text: #e8ecf4;
    --muted: #8d96a8;
    --accent: #6ea8fe;
    --accent-2: #8b5cf6;
    --success: #34d399;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background:
        radial-gradient(circle at 20% 0%, rgba(110,168,254,.10), transparent 28rem),
        var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, textarea { font: inherit; }

.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 22px 16px;
    background: rgba(15,18,25,.92);
    border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.brand-mark {
    display: grid; place-items: center;
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff; font-weight: 800; letter-spacing: .04em;
}
.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

.nav { display: grid; gap: 8px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    width: 100%; padding: 12px 14px;
    border: 1px solid transparent; border-radius: 12px;
    background: transparent; color: var(--muted);
    cursor: pointer; text-align: left; transition: .18s ease;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
    background: linear-gradient(90deg, rgba(110,168,254,.18), rgba(139,92,246,.10));
    border-color: rgba(110,168,254,.36); color: var(--text);
}
.nav-icon { width: 44px; font-size: 11px; font-weight: 800; color: var(--accent); letter-spacing: .05em; }

.sidebar-footer {
    display: flex; align-items: center; gap: 8px;
    margin-top: auto; padding: 12px 10px;
    color: var(--muted); font-size: 12px;
    border-top: 1px solid var(--border);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; }

.main { min-width: 0; padding: 28px clamp(18px, 4vw, 48px) 48px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 24px; }
.topbar h1 { margin: 0; font-size: 26px; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.badge {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px;
    color: var(--muted); font-size: 12px; background: rgba(21,24,33,.7);
}

.view { display: none; }
.view.active { display: block; animation: fade-in .18s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero {
    display: flex; justify-content: space-between; align-items: center; gap: 24px;
    padding: 26px 28px; margin-bottom: 18px;
    background: linear-gradient(135deg, rgba(110,168,254,.12), rgba(139,92,246,.08));
    border: 1px solid rgba(110,168,254,.24); border-radius: 18px;
}
.hero h2 { margin: 6px 0 8px; font-size: 24px; }
.hero p { margin: 0; color: var(--muted); line-height: 1.7; max-width: 720px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
.hero-state { padding: 8px 12px; border-radius: 10px; background: rgba(245,158,11,.12); color: #fbbf24; font-size: 12px; white-space: nowrap; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.muted { color: var(--muted); }
.chat-panel { min-height: 460px; display: flex; flex-direction: column; }
.chat-messages { flex: 1; padding: 22px; display: flex; align-items: flex-start; }
.message { max-width: 760px; padding: 14px 16px; border-radius: 14px; line-height: 1.75; }
.message.system { background: var(--panel-2); border: 1px solid var(--border); color: #c9d1df; }
.composer { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.composer textarea {
    flex: 1; min-height: 48px; max-height: 140px; resize: vertical;
    padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--panel-2); color: var(--muted); outline: none;
}
.composer button, .button-link {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 18px; border-radius: 12px; border: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff; text-decoration: none; cursor: pointer;
}
.composer button:disabled { opacity: .45; cursor: not-allowed; }

.camera-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 14px; }
.camera-toolbar h2 { margin: 0 0 6px; }
.camera-toolbar p { margin: 0; }
.camera-frame { height: calc(100vh - 180px); min-height: 560px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.camera-frame iframe { width: 100%; height: 100%; border: 0; background: var(--bg); }

.empty-panel { display: grid; place-items: center; text-align: center; padding: 70px 24px; }
.empty-icon { display: grid; place-items: center; width: 82px; height: 82px; border-radius: 24px; background: var(--panel-2); color: var(--accent); font-weight: 800; letter-spacing: .08em; }
.empty-panel h3 { margin: 18px 0 8px; }
.empty-panel p { margin: 0; color: var(--muted); max-width: 580px; line-height: 1.7; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 20; flex-direction: row; align-items: center; gap: 14px; padding: 10px 12px; overflow-x: auto; }
    .brand small { display: none; }
    .nav { display: flex; }
    .nav-item { width: auto; white-space: nowrap; }
    .nav-icon { display: none; }
    .sidebar-footer { display: none; }
    .main { padding: 20px 14px 32px; }
    .topbar { margin-bottom: 16px; }
    .hero { flex-direction: column; align-items: flex-start; }
    .camera-frame { height: 72vh; }
}
/* ---------- Agent chat ---------- */
.agent-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    min-height: calc(100vh - 150px);
}
.conversation-panel,
.chat-panel {
    min-height: 560px;
    display: flex;
    flex-direction: column;
}
.conversation-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.conversation-list { overflow: auto; padding: 8px; display: grid; gap: 6px; }
.conversation-item {
    width: 100%; text-align: left; padding: 12px;
    border: 1px solid transparent; border-radius: 10px;
    background: transparent; color: var(--muted); cursor: pointer;
}
.conversation-item:hover { background: var(--panel-2); color: var(--text); }
.conversation-item.active { background: rgba(110,168,254,.12); border-color: rgba(110,168,254,.32); color: var(--text); }
.conversation-item strong { display: block; font-size: 13px; margin-bottom: 5px; }
.conversation-item small { color: var(--muted); font-size: 11px; }
.chat-messages { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.message-row { display: flex; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant, .message-row.tool, .message-row.system { justify-content: flex-start; }
.message-bubble {
    max-width: min(760px, 88%); padding: 12px 14px; border-radius: 14px;
    line-height: 1.7; white-space: pre-wrap; word-break: break-word;
    background: var(--panel-2); border: 1px solid var(--border);
}
.message-row.user .message-bubble { background: linear-gradient(135deg, rgba(110,168,254,.9), rgba(139,92,246,.85)); color: #fff; border: 0; }
.message-meta { margin-top: 6px; font-size: 10px; opacity: .6; }
.message-row.tool .message-bubble { border-color: rgba(251,146,60,.35); background: rgba(251,146,60,.08); }
.message-row.system .message-bubble { border-color: rgba(245,158,11,.28); background: rgba(245,158,11,.07); color: #e8d9b0; }
.typing { color: var(--muted); font-size: 12px; padding: 0 20px 10px; }
.chat-title-wrap { min-width: 0; }
.chat-title-wrap strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-status { font-size: 11px; color: var(--muted); }

/* ---------- Forms / accounts ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
    width: min(430px, 100%); padding: 30px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
    box-shadow: 0 20px 80px rgba(0,0,0,.35);
}
.login-card h1 { margin: 0 0 8px; }
.login-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }
.form-grid { display: grid; gap: 12px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.form-grid input, .form-grid textarea, .form-grid select {
    width: 100%; padding: 12px 13px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--panel-2);
    color: var(--text); outline: none;
}
.form-grid input:focus, .form-grid textarea:focus { border-color: var(--accent); }
.primary-btn {
    padding: 12px 16px; border: 0; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff; cursor: pointer;
}
.primary-btn:disabled { opacity: .5; cursor: not-allowed; }
.ghost-btn {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 9px;
    background: transparent; color: var(--text); cursor: pointer;
}
.ghost-btn:hover { background: var(--panel-2); }
.form-message { min-height: 20px; margin-top: 12px; color: #fbbf24; font-size: 13px; }
.form-message.error { color: #f87171; }
.hidden { display: none !important; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
.users-table th { color: var(--muted); font-weight: 500; }
.user-actions { display: flex; gap: 6px; }
.small-btn { padding: 6px 9px; border-radius: 7px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; }
.small-btn.danger { color: #f87171; border-color: rgba(248,113,113,.35); }
.account-layout { display: grid; grid-template-columns: 340px minmax(0,1fr); gap: 16px; }
.section-title { margin: 0 0 14px; font-size: 18px; }
.page-section { margin-bottom: 16px; }
.sidebar-user { color: var(--muted); font-size: 12px; line-height: 1.6; }
.sidebar-user strong { color: var(--text); display: block; }
.logout-btn { margin-top: 8px; }
.toast {
    position: fixed; right: 20px; bottom: 20px; z-index: 200;
    max-width: 420px; padding: 12px 16px; border-radius: 12px;
    background: #252a38; border: 1px solid var(--border); color: var(--text);
    box-shadow: 0 10px 40px rgba(0,0,0,.35); font-size: 13px;
}
.toast.error { border-color: rgba(248,113,113,.45); }

@media (max-width: 900px) {
    .agent-layout, .account-layout { grid-template-columns: 1fr; }
    .conversation-panel { min-height: 180px; max-height: 240px; }
    .chat-panel { min-height: 65vh; }
    .message-bubble { max-width: 94%; }
    .users-table { min-width: 620px; }
    .table-scroll { overflow-x: auto; }
}
/* ---------- Agent Desk compact pass ---------- */
body { font-size: 13px; }
.main { padding: 20px clamp(16px, 3vw, 36px) 28px; }
.topbar { margin-bottom: 16px; }
.topbar h1 { font-size: 20px; }
.topbar p { font-size: 12px; }
.badge { font-size: 11px; padding: 5px 9px; }
.brand strong { font-size: 14px; }
.brand small { font-size: 10px; }
.nav-item { padding: 9px 12px; font-size: 12px; border-radius: 9px; }
.nav-icon { width: 34px; font-size: 10px; }
.sidebar { gap: 18px; padding: 16px 12px; }
.sidebar-footer { font-size: 11px; padding: 10px 8px; }
.hero { padding: 18px 20px; margin-bottom: 12px; }
.hero h2 { font-size: 18px; }
.hero p { font-size: 12px; }
.panel-head { padding: 11px 14px; }
.conversation-head { padding: 10px 12px; }
.conversation-item { padding: 9px 10px; }
.conversation-item strong { font-size: 12px; margin-bottom: 3px; }
.conversation-item small { font-size: 10px; }
.agent-layout { grid-template-columns: 240px minmax(0, 1fr); gap: 12px; min-height: calc(100vh - 125px); }
.conversation-panel, .chat-panel { min-height: 500px; }
.chat-messages { padding: 14px; gap: 8px; }
.message-bubble {
    max-width: min(760px, 92%);
    padding: 8px 11px;
    border-radius: 11px;
    font-size: 13px;
    line-height: 1.55;
}
.message-meta { margin-top: 4px; font-size: 9px; }
.typing { font-size: 11px; padding: 0 14px 8px; }
.chat-title-wrap strong { font-size: 13px; }
.chat-status { font-size: 10px; }
.chat-head-actions { display: flex; align-items: center; gap: 12px; font-size: 11px; }
.detail-toggle { display: flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; }
.composer { padding: 10px; align-items: center; }
.composer textarea { min-height: 38px; padding: 9px 11px; font-size: 13px; }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.composer-actions button { height: 38px; padding: 0 16px; border-radius: 9px; }
.approval-toggle { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; white-space: nowrap; cursor: pointer; }
.approval-panel { padding: 8px 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); max-height: 260px; overflow: auto; }
.approval-card { padding: 10px 12px; border: 1px solid rgba(251,146,60,.4); background: rgba(251,146,60,.07); border-radius: 10px; }
.approval-title { color: #fbbf24; font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.approval-detail { white-space: pre-wrap; word-break: break-word; color: var(--text); font-size: 12px; line-height: 1.55; }
.approval-comment { width: 100%; margin-top: 7px; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 12px; }
.approval-actions { display: flex; gap: 8px; margin-top: 8px; }
.approval-actions button { padding: 6px 12px; font-size: 12px; border-radius: 7px; }
.approval-actions .approve { background: linear-gradient(135deg, #22c55e, #16a34a); }
.review-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.08); }
.review-bar .small-btn { padding: 3px 8px; font-size: 10px; }
.review-state { font-size: 10px; padding: 2px 6px; border-radius: 5px; }
.review-state.approved { color: #4ade80; background: rgba(34,197,94,.12); }
.review-state.rejected { color: #f87171; background: rgba(248,113,113,.12); }
.review-comment { color: var(--muted); font-size: 10px; }
.users-table th, .users-table td { padding: 9px; font-size: 12px; }
.form-grid input, .form-grid textarea, .form-grid select { padding: 9px 10px; font-size: 12px; }
.primary-btn, .ghost-btn, .button-link { font-size: 12px; }
.camera-frame { height: calc(100vh - 150px); min-height: 480px; }

@media (max-width: 900px) {
    .main { padding: 14px 10px 22px; }
    .topbar h1 { font-size: 18px; }
    .agent-layout { gap: 9px; }
    .conversation-panel { min-height: 150px; max-height: 210px; }
    .chat-panel { min-height: 62vh; }
    .composer { align-items: stretch; }
    .composer-actions { justify-content: space-between; }
    .message-bubble { max-width: 96%; font-size: 12px; }
    .chat-head-actions { gap: 8px; }
    .approval-panel { max-height: 220px; }
}
.conversation-head-actions { display: flex; gap: 6px; }
.conversation-head-actions .ghost-btn { padding: 5px 8px; font-size: 11px; }
.conversation-group-title {
    padding: 10px 8px 4px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}