/* ═══════════════════════════════════════════════════════
   GDef Dashboard – Dark theme, sidebar + viewer + chat
   ═══════════════════════════════════════════════════════ */

:root {
    --bg-0: #0b1120;
    --bg-1: #0f172a;
    --bg-2: #1e293b;
    --bg-3: #334155;
    --bg-4: #475569;
    --text-1: #f1f5f9;
    --text-2: #94a3b8;
    --text-3: #64748b;
    --accent: #3b82f6;
    --accent-h: #2563eb;
    --green: #22c55e;
    --yellow: #f59e0b;
    --red: #ef4444;
    --border: #1e293b;
    --radius: 10px;
    --radius-sm: 6px;
    --sidebar-w: 240px;
    --header-h: 44px;
    --status-h: 28px;
    --chat-w: 360px;
    --chat-h: 480px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-0);
    color: var(--text-1);
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
}

/* ─── Screens ──────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }
#login-screen { height: 100dvh; justify-content: center; align-items: center; background: linear-gradient(135deg, var(--bg-0), var(--bg-2)); }
#dashboard { height: 100dvh; }

/* ─── Login ────────────────────────────────────────── */
.login-box { text-align: center; width: 100%; max-width: 300px; padding: 2rem 1.25rem; }
#login-form { display: flex; flex-direction: column; gap: .625rem; }
#login-form input {
    padding: .75rem 1rem; background: var(--bg-2); border: 1px solid var(--bg-3);
    border-radius: var(--radius); color: var(--text-1); font-size: .875rem; outline: none;
    transition: border-color .2s;
}
#login-form input:focus { border-color: var(--accent); }
#login-form input::placeholder { color: var(--text-3); }
.error { color: var(--red); font-size: .8125rem; margin-top: .5rem; }
.hidden { display: none !important; }
.fp-status { font-size: .6875rem; color: var(--text-3); margin-top: .75rem; letter-spacing: 1px; }
#btn-login:disabled { opacity: .35; cursor: not-allowed; }

/* ─── Buttons ──────────────────────────────────────── */
.btn {
    padding: .625rem 1.25rem; border: none; border-radius: var(--radius);
    font-size: .875rem; font-weight: 600; cursor: pointer; transition: all .15s;
    touch-action: manipulation;
}
.btn-full { width: 100%; }
.btn-sm { padding: .375rem .75rem; font-size: .75rem; border-radius: var(--radius-sm); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-success { background: var(--green); color: #fff; }
.btn-warning { background: var(--yellow); color: var(--bg-0); }
.btn-danger { background: var(--red); color: #fff; }
.btn-icon { background: none; border: none; font-size: 1.125rem; cursor: pointer; padding: .375rem; border-radius: 50%; transition: background .15s; color: var(--text-2); }
.btn-icon:hover { background: var(--bg-3); }
.btn-icon-sm { background: none; border: none; font-size: 1rem; cursor: pointer; padding: .25rem; border-radius: 50%; color: var(--text-2); }
.btn-icon-sm:hover { background: var(--bg-3); }
.badge { font-size: .6875rem; padding: .125rem .5rem; border-radius: 10px; background: var(--bg-3); color: var(--text-2); }

/* ─── Status dot ───────────────────────────────────── */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.connecting { background: var(--yellow); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ═══════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════ */

#sidebar {
    width: var(--sidebar-w); min-width: var(--sidebar-w);
    background: var(--bg-1); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; flex-shrink: 0;
    transition: margin-left .25s ease, opacity .25s;
    z-index: 30;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); opacity: 0; pointer-events: none; }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .625rem .75rem; border-bottom: 1px solid var(--border);
    height: var(--header-h); flex-shrink: 0;
}
.brand { font-weight: 800; font-size: .9375rem; }

.sidebar-body { flex: 1; overflow-y: auto; padding: .5rem 0; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: .5rem .75rem; display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.status-row { display: flex; align-items: center; gap: .375rem; font-size: .75rem; color: var(--text-2); }
.sidebar-actions { display: flex; gap: .125rem; }

/* Agents tree */
.agents-tree { font-size: .8125rem; }
.tree-placeholder { padding: 1.5rem; text-align: center; color: var(--text-3); font-size: .8125rem; }

.machine-group { margin-bottom: .25rem; }
.machine-header {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .75rem; cursor: pointer; user-select: none;
    color: var(--text-2); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .5px;
    transition: background .1s;
}
.machine-header:hover { background: var(--bg-2); }
.machine-header .status-dot { width: 6px; height: 6px; }

.agent-item {
    display: flex; align-items: center; gap: .5rem;
    padding: .4375rem .75rem .4375rem 1.5rem;
    cursor: pointer; transition: background .1s; border-left: 2px solid transparent;
    font-size: .8125rem; color: var(--text-1);
}
.agent-item:hover { background: var(--bg-2); }
.agent-item.active { background: var(--bg-2); border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.agent-item .agent-port { font-size: .6875rem; color: var(--text-3); margin-left: auto; }

.btn-sidebar-toggle {
    position: fixed; top: .5rem; left: .5rem; z-index: 35;
    background: var(--bg-2); border: 1px solid var(--border); color: var(--text-1);
    font-size: 1.125rem; padding: .5rem .625rem; border-radius: var(--radius-sm);
    cursor: pointer;
}

/* ═══════════════════════════════════════════════════════
   MAIN VIEWER
   ═══════════════════════════════════════════════════════ */

#main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Viewer header */
#viewer-header {
    display: flex; align-items: center; gap: .75rem;
    padding: 0 .75rem; height: var(--header-h); flex-shrink: 0;
    background: var(--bg-1); border-bottom: 1px solid var(--border);
}
.viewer-agent-info { display: flex; align-items: center; gap: .375rem; min-width: 0; }
#viewer-agent-icon { font-size: 1rem; }
#viewer-agent-name { font-weight: 600; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.viewer-tabs { display: flex; gap: 2px; margin-left: auto; flex-shrink: 0; }
.tab {
    padding: .375rem .625rem; font-size: .75rem; background: none; border: none;
    color: var(--text-3); cursor: pointer; border-radius: var(--radius-sm);
    transition: all .15s; white-space: nowrap;
}
.tab:hover { color: var(--text-1); background: var(--bg-2); }
.tab.active { color: var(--accent); background: var(--bg-2); font-weight: 600; }

.viewer-actions { display: flex; align-items: center; gap: .375rem; flex-shrink: 0; }
.auto-refresh-toggle {
    display: flex; align-items: center; gap: .25rem; font-size: .75rem; color: var(--text-3); cursor: pointer;
}
.auto-refresh-toggle input { width: 14px; height: 14px; accent-color: var(--accent); }
.auto-refresh-toggle select {
    background: var(--bg-3); border: none; color: var(--text-2);
    font-size: .6875rem; border-radius: 4px; padding: 1px 4px;
}

/* Viewer body */
#viewer-body { flex: 1; position: relative; overflow: hidden; background: var(--bg-0); }
.view-panel { display: none; position: absolute; inset: 0; }
.view-panel.active { display: flex; flex-direction: column; }

/* Placeholder */
.placeholder { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; color: var(--text-3); text-align: center; padding: 2rem; }
.placeholder-icon { font-size: 3rem; margin-bottom: .75rem; opacity: .5; }
.placeholder p { margin-bottom: .25rem; }
.placeholder .hint { font-size: .75rem; color: var(--text-3); }

/* Preview iframe */
#preview-iframe { width: 100%; height: 100%; border: none; background: #fff; }

/* Log */
.log-list { flex: 1; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .375rem; }
.log-entry {
    padding: .5rem .75rem; background: var(--bg-2); border-radius: var(--radius-sm);
    font-size: .8125rem; border-left: 3px solid var(--accent);
}
.log-entry .log-time { font-size: .6875rem; color: var(--text-3); }
.log-entry .log-text { margin-top: .25rem; line-height: 1.4; }
.log-entry .log-meta { font-size: .6875rem; color: var(--text-3); margin-top: .25rem; }

/* Log load more */
.log-load-more {
    display: flex; align-items: center; justify-content: center; gap: .75rem;
    padding: .5rem; border-top: 1px solid var(--border); flex-shrink: 0;
}
.log-count-info { font-size: .6875rem; color: var(--text-3); }

/* Screenshot */
.screenshot-container { flex: 1; display: flex; justify-content: center; align-items: center; overflow: auto; padding: .5rem; }
.screenshot-container img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); }

/* Status bar */
#status-bar {
    display: flex; align-items: center; gap: 1rem;
    padding: 0 .75rem; height: var(--status-h); flex-shrink: 0;
    background: var(--bg-1); border-top: 1px solid var(--border);
    font-size: .6875rem; color: var(--text-3);
}

/* ═══════════════════════════════════════════════════════
   FLOATING CHAT POPUP
   ═══════════════════════════════════════════════════════ */

.chat-popup {
    position: fixed;
    bottom: calc(1rem + var(--safe-b));
    right: 1rem;
    z-index: 50;
    transition: none; /* drag shouldn't animate */
}

/* Minimized: just the bubble */
.chat-popup.minimized .chat-expanded { display: none; }
.chat-popup:not(.minimized) .chat-toggle-btn { display: none; }

.chat-toggle-btn {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--accent); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; box-shadow: 0 4px 20px rgba(0,0,0,.4);
    transition: transform .15s;
    position: relative;
}
.chat-toggle-btn:hover { transform: scale(1.08); }
.chat-toggle-btn:active { transform: scale(.95); }

.unread-badge {
    position: absolute; top: -4px; right: -4px;
    background: var(--red); color: #fff;
    font-size: .625rem; font-weight: 700;
    min-width: 18px; height: 18px; line-height: 18px;
    border-radius: 9px; text-align: center;
}

/* Expanded */
.chat-expanded {
    width: var(--chat-w);
    max-height: var(--chat-h);
    background: rgba(15, 23, 42, 0.70);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .5rem .75rem; cursor: grab; user-select: none;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}
.chat-header:active { cursor: grabbing; }
.chat-title { font-weight: 600; font-size: .8125rem; }

.chat-target-bar {
    display: flex; gap: .375rem; padding: .375rem .5rem;
    border-bottom: 1px solid rgba(255,255,255,.04); flex-shrink: 0;
}
.chat-target-bar select {
    flex: 1; padding: .3125rem .375rem; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius-sm); color: var(--text-1); font-size: .75rem; outline: none;
}

/* Messages */
.chat-messages {
    flex: 1; overflow-y: auto; padding: .5rem;
    display: flex; flex-direction: column; gap: .375rem;
    min-height: 120px; max-height: 260px;
}
.chat-welcome { text-align: center; color: var(--text-3); font-size: .75rem; padding: 1rem .5rem; }
.chat-welcome .hint { margin-top: .25rem; font-size: .6875rem; }

.chat-msg {
    max-width: 88%; padding: .4375rem .625rem;
    border-radius: var(--radius-sm); font-size: .8125rem; line-height: 1.4;
    word-break: break-word;
}
.chat-msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 2px; }
.chat-msg.in { align-self: flex-start; background: rgba(255,255,255,.08); border-bottom-left-radius: 2px; }
.chat-msg.sys { align-self: center; background: transparent; color: var(--text-3); font-size: .6875rem; }
.chat-msg .msg-time { font-size: .5625rem; opacity: .6; margin-top: .125rem; }

/* Confirmation */
.chat-confirm {
    padding: .5rem; border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(0,0,0,.15); flex-shrink: 0;
}
.confirm-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .375rem; }
.confidence-badge { font-size: .6875rem; font-weight: 600; padding: .125rem .5rem; background: rgba(255,255,255,.08); border-radius: 10px; }
.toggle-info { font-size: .6875rem; color: var(--text-3); }
.confirm-text { font-size: .8125rem; line-height: 1.4; padding: .375rem .5rem; background: rgba(255,255,255,.06); border-radius: var(--radius-sm); margin-bottom: .375rem; }
.confirm-edit {
    width: 100%; padding: .375rem .5rem; background: rgba(255,255,255,.06); border: 1px solid var(--accent);
    border-radius: var(--radius-sm); color: var(--text-1); font-size: .8125rem; resize: none; outline: none;
    margin-bottom: .375rem;
}
.confirm-actions { display: flex; gap: .375rem; }
.confirm-actions .btn { flex: 1; }

/* Input bar */
.chat-input-bar {
    display: flex; align-items: center; gap: .375rem;
    padding: .5rem; border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0;
}
#chat-text-input {
    flex: 1; padding: .4375rem .625rem; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius); color: var(--text-1); font-size: .8125rem; outline: none;
    transition: border-color .15s;
}
#chat-text-input:focus { border-color: var(--accent); }

.btn-record-sm {
    width: 36px; height: 36px; border-radius: 50%;
    border: 2px solid var(--accent); background: rgba(255,255,255,.04);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 1rem; transition: all .15s; touch-action: manipulation;
    -webkit-user-select: none; user-select: none; flex-shrink: 0;
}
.btn-record-sm:active, .btn-record-sm.recording {
    background: var(--red); border-color: var(--red); transform: scale(1.1);
}
.rec-timer { font-size: .6875rem; color: var(--red); font-variant-numeric: tabular-nums; }

/* ═══════════════════════════════════════════════════════
   SETTINGS PANEL
   ═══════════════════════════════════════════════════════ */

.panel {
    position: fixed; inset: 0; background: var(--bg-0); z-index: 200;
    display: flex; flex-direction: column;
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-body { padding: 1rem; overflow-y: auto; }
.setting-group { margin-bottom: 1.25rem; }
.setting-group label { display: block; margin-bottom: .375rem; font-weight: 600; font-size: .8125rem; }
.setting-group select, .setting-group input[type="number"] {
    width: 100%; padding: .5rem; background: var(--bg-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-1); font-size: .8125rem; outline: none;
}
.setting-group small { display: block; margin-top: .25rem; color: var(--text-3); font-size: .75rem; }

/* ─── Toast ────────────────────────────────────────── */
#toast-container { position: fixed; top: .75rem; right: .75rem; z-index: 999; display: flex; flex-direction: column; gap: .375rem; pointer-events: none; }
.toast {
    padding: .5rem .875rem; border-radius: var(--radius-sm); font-size: .8125rem;
    animation: slideIn .25s ease-out; max-width: 300px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
    pointer-events: auto;
}
.toast.info { background: var(--accent); color: #fff; }
.toast.success { background: var(--green); color: #fff; }
.toast.error { background: var(--red); color: #fff; }
.toast.warning { background: var(--yellow); color: var(--bg-0); }
@keyframes slideIn { from{transform:translateX(100%);opacity:0} to{transform:translateX(0);opacity:1} }

/* ─── Loading state ────────────────────────────────── */
.loading {
    position: relative;
    pointer-events: none;
    opacity: .6;
}
.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px; height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#btn-chat-send.loading {
    color: transparent;
}

.chat-input:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ─── Timeline / Audit viewer ─────────────────────── */
.timeline-container {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    height: 100%;
    overflow-y: auto;
}
.timeline-toolbar {
    display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
    padding: .5rem; background: var(--bg-1); border-radius: var(--radius-sm);
}
.timeline-toolbar select,
.timeline-toolbar input {
    background: var(--bg-2); color: var(--text-1); border: 1px solid var(--bg-3);
    border-radius: var(--radius-sm); padding: .25rem .5rem; font-size: .75rem;
}
.timeline-toolbar button {
    background: var(--accent); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: .25rem .75rem; font-size: .75rem;
    cursor: pointer;
}
.tl-event {
    display: flex; gap: .5rem; align-items: flex-start;
    padding: .5rem .625rem; border-radius: var(--radius-sm);
    background: var(--bg-1); border-left: 3px solid var(--accent);
    font-size: .8125rem; line-height: 1.4;
    transition: background .15s;
}
.tl-event:hover { background: var(--bg-2); }
.tl-event .tl-time { color: var(--text-3); font-size: .75rem; min-width: 5em; flex-shrink: 0; }
.tl-event .tl-type { color: var(--accent); font-weight: 600; min-width: 7em; flex-shrink: 0; font-size: .75rem; }
.tl-event .tl-content { color: var(--text-2); flex: 1; overflow-wrap: anywhere; }
.tl-event.type-copilot_response { border-left-color: var(--green); }
.tl-event.type-command_voice { border-left-color: var(--yellow); }
.tl-event.type-login { border-left-color: var(--blue); }
.tl-event.type-login_failed { border-left-color: var(--red); }
.tl-event.type-transcription { border-left-color: var(--purple, #a78bfa); }
.tl-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .5rem; }
.tl-stat-card {
    background: var(--bg-1); border-radius: var(--radius-sm);
    padding: .75rem; text-align: center;
}
.tl-stat-card .tl-stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.tl-stat-card .tl-stat-label { font-size: .75rem; color: var(--text-3); }

/* ─── Device manager ──────────────────────────────── */
.device-list {
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: .375rem;
}
.device-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: .5rem .75rem; background: var(--bg-2); border-radius: var(--radius-sm);
    font-size: .8125rem;
}
.device-item .device-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.device-item .device-name { color: var(--text-1); font-weight: 500; }
.device-item .device-id { color: var(--text-3); font-size: .6875rem; font-family: monospace; }
.device-item .device-ip { color: var(--text-3); font-size: .6875rem; }
.device-item .device-current { color: var(--green); font-size: .6875rem; }
.device-item .device-expiry { font-size: .6875rem; color: var(--accent); }
.device-item .device-expiry.warning { color: var(--orange, #f59e0b); }
.device-item .device-expiry.expired { color: var(--red); }
.device-item .device-expiry.permanent { color: var(--text-3); font-size: .6rem; }
.device-item .btn-device-remove {
    background: var(--red); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: .2rem .5rem; font-size: .6875rem;
    cursor: pointer; opacity: .8; flex-shrink: 0;
}
.device-item .btn-device-remove:hover { opacity: 1; }

/* Pending devices */
.pending-header {
    display: flex; align-items: center; gap: .5rem;
    margin-bottom: .375rem;
}
.pending-label { font-size: .8rem; color: var(--orange, #f59e0b); font-weight: 600; }
.badge-pending {
    background: var(--orange, #f59e0b); color: #000; font-size: .65rem;
    padding: .1rem .4rem; border-radius: 10px; font-weight: 700;
    animation: pulse-pending 2s ease-in-out infinite;
}
@keyframes pulse-pending {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}
.device-pending-item {
    border-left: 3px solid var(--orange, #f59e0b);
}
.device-approve-actions {
    display: flex; align-items: center; gap: .25rem; flex-shrink: 0;
}
.device-approve-actions select.approve-duration {
    background: var(--bg-1); color: var(--text-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .15rem .25rem; font-size: .65rem;
    max-width: 70px;
}
.btn-device-approve, .btn-device-reject {
    background: none; border: none; cursor: pointer; font-size: .8rem;
    padding: .15rem .3rem; border-radius: var(--radius-sm);
    transition: background .15s;
}
.btn-device-approve:hover { background: rgba(34,197,94,.2); }
.btn-device-reject:hover { background: rgba(239,68,68,.2); }

/* Login pending state */
.login-pending {
    text-align: center; padding: 1rem; margin-top: .5rem;
    background: var(--bg-2); border-radius: var(--radius-sm);
    border: 1px solid var(--orange, #f59e0b);
}
.login-pending .pending-spinner {
    font-size: 2rem; animation: spin 2s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.login-pending p { color: var(--text-2); font-size: .8rem; margin: .5rem 0 0; }

/* Settings alert flash */
@keyframes settings-flash {
    0%, 100% { filter: none; }
    50% { filter: drop-shadow(0 0 8px var(--orange, #f59e0b)); }
}
.settings-alert { animation: settings-flash 1s ease-in-out infinite; }

/* ─── TTS button ──────────────────────────────────── */
.btn-tts {
    background: none; border: none; cursor: pointer; font-size: .6875rem;
    padding: 0 .25rem; opacity: .6; transition: opacity .15s;
    margin-left: .375rem; vertical-align: middle;
}
.btn-tts:hover { opacity: 1; }

/* ─── Reminder items ──────────────────────────────── */
.reminder-form input,
.reminder-form select {
    padding: .4375rem .5rem; background: var(--bg-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-1); font-size: .8125rem; outline: none;
}
.reminder-form input:focus { border-color: var(--accent); }
.reminder-item {
    display: flex; align-items: flex-start; justify-content: space-between;
    padding: .5rem .75rem; background: var(--bg-2); border-radius: var(--radius-sm);
    margin-bottom: .375rem; border-left: 3px solid var(--yellow);
}
.reminder-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.reminder-title { color: var(--text-1); font-weight: 500; font-size: .8125rem; }
.reminder-meta { color: var(--text-3); font-size: .6875rem; display: flex; gap: .375rem; align-items: center; flex-wrap: wrap; }
.reminder-desc { color: var(--text-2); font-size: .75rem; }
.reminder-actions { display: flex; gap: .25rem; flex-shrink: 0; }
.reminder-actions button {
    background: none; border: none; cursor: pointer; font-size: .875rem;
    padding: .125rem .25rem; border-radius: var(--radius-sm); opacity: .7;
}
.reminder-actions button:hover { opacity: 1; background: var(--bg-3); }

/* ─── Scrollbar ────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 2px; }

/* ═══════════════════════════════════════════════════════
   KNOWLEDGE BASE DASHBOARD
   ═══════════════════════════════════════════════════════ */

.kb-dashboard {
    padding: 1rem; overflow-y: auto; height: 100%;
    display: flex; flex-direction: column; gap: 1rem;
}

.kb-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: .75rem;
}

.kb-stat-card {
    background: var(--bg-1); border-radius: var(--radius);
    padding: 1rem; text-align: center;
    border: 1px solid var(--border);
    transition: transform .15s;
}
.kb-stat-card:hover { transform: translateY(-2px); }
.kb-stat-card .stat-icon { font-size: 1.5rem; margin-bottom: .25rem; }
.kb-stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--accent); }
.kb-stat-card .stat-label { font-size: .6875rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; }

.kb-chart-section {
    background: var(--bg-1); border-radius: var(--radius);
    padding: 1rem; border: 1px solid var(--border);
}
.kb-chart-title { font-size: .8125rem; font-weight: 600; margin-bottom: .75rem; color: var(--text-2); }

.kb-bar-chart {
    display: flex; align-items: flex-end; gap: 4px; height: 100px; padding-top: .5rem;
}
.kb-bar {
    flex: 1; background: var(--accent); border-radius: 3px 3px 0 0;
    min-height: 4px; position: relative; transition: height .3s ease;
}
.kb-bar:hover { opacity: .8; }
.kb-bar .bar-label {
    position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%);
    font-size: .5625rem; color: var(--text-3); white-space: nowrap;
}
.kb-bar .bar-value {
    position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
    font-size: .5625rem; color: var(--text-2); font-weight: 600;
}

.kb-top-convs { display: flex; flex-direction: column; gap: .375rem; }
.kb-conv-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .5rem .75rem; background: var(--bg-2); border-radius: var(--radius-sm);
    cursor: pointer; transition: background .15s;
}
.kb-conv-item:hover { background: var(--bg-3); }
.kb-conv-item .conv-name { flex: 1; font-size: .8125rem; font-weight: 500; }
.kb-conv-item .conv-meta { font-size: .6875rem; color: var(--text-3); }
.kb-conv-item .conv-count { font-size: .75rem; color: var(--accent); font-weight: 600; }

.kb-source-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: .5rem;
}
.kb-source-item {
    background: var(--bg-2); border-radius: var(--radius-sm); padding: .5rem;
    text-align: center; font-size: .75rem;
}
.kb-source-item .source-count { font-size: 1.125rem; font-weight: 700; color: var(--accent); }
.kb-source-item .source-name { font-size: .625rem; color: var(--text-3); margin-top: .125rem; }

/* ═══════════════════════════════════════════════════════
   HISTORIQUE CONVERSATIONS
   ═══════════════════════════════════════════════════════ */

.history-container {
    display: flex; flex-direction: column; height: 100%; overflow: hidden;
}
.history-toolbar {
    display: flex; gap: .5rem; padding: .75rem; border-bottom: 1px solid var(--border);
    flex-shrink: 0; align-items: center;
}
.history-toolbar select {
    background: var(--bg-2); color: var(--text-1); border: 1px solid var(--bg-3);
    border-radius: var(--radius-sm); padding: .375rem .5rem; font-size: .75rem;
}

.hist-projects {
    flex: 1; overflow-y: auto; padding: .75rem;
    display: flex; flex-direction: column; gap: .5rem;
}

.hist-project-card {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.hist-project-header {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; cursor: pointer;
    transition: background .15s;
}
.hist-project-header:hover { background: var(--bg-2); }
.hist-project-name { font-weight: 600; font-size: .875rem; flex: 1; }
.hist-project-stats { font-size: .6875rem; color: var(--text-3); }
.hist-project-toggle { color: var(--text-3); transition: transform .15s; }
.hist-project-card.open .hist-project-toggle { transform: rotate(90deg); }

.hist-conv-list {
    display: none; padding: 0 .75rem .75rem;
    flex-direction: column; gap: .375rem;
}
.hist-project-card.open .hist-conv-list { display: flex; }

.hist-conv-item {
    display: flex; align-items: center; gap: .625rem;
    padding: .5rem .75rem; background: var(--bg-2); border-radius: var(--radius-sm);
    cursor: pointer; transition: background .15s; border-left: 3px solid transparent;
}
.hist-conv-item:hover { background: var(--bg-3); }
.hist-conv-item.active { border-left-color: var(--accent); }
.hist-conv-item .conv-status-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.hist-conv-item .conv-status-dot.active { background: var(--green); }
.hist-conv-item .conv-status-dot.saved { background: var(--yellow); }
.hist-conv-item .conv-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.hist-conv-item .conv-name-text { font-size: .8125rem; font-weight: 500; }
.hist-conv-item .conv-details { font-size: .6875rem; color: var(--text-3); }

/* Conversation detail */
.hist-conv-detail { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.hist-conv-header {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.hist-conv-title { flex: 1; font-weight: 600; font-size: .875rem; }
.hist-conv-actions { display: flex; gap: .25rem; }

.hist-messages {
    flex: 1; overflow-y: auto; padding: .75rem;
    display: flex; flex-direction: column; gap: .5rem;
}
.hist-msg {
    max-width: 85%; padding: .5rem .75rem; border-radius: var(--radius);
    font-size: .8125rem; line-height: 1.5; position: relative;
}
.hist-msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.hist-msg.copilot { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--border); }
.hist-msg.system { align-self: center; background: transparent; color: var(--text-3); font-size: .75rem; font-style: italic; }
.hist-msg .msg-header {
    display: flex; justify-content: space-between; gap: .5rem;
    font-size: .625rem; opacity: .7; margin-bottom: .25rem;
}
.hist-msg .msg-source { font-size: .5625rem; opacity: .6; margin-top: .125rem; }

/* Card overlay */
.card-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.6);
    z-index: 300; display: flex; justify-content: center; align-items: center;
    padding: 1rem;
}
.card-content {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius); max-width: 600px; width: 100%;
    max-height: 80vh; overflow-y: auto; padding: 1.5rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.card-header h2 { font-size: 1rem; }
.card-section { margin-bottom: 1rem; }
.card-section h3 { font-size: .8125rem; color: var(--accent); margin-bottom: .5rem; }
.card-stat-row {
    display: flex; gap: 1rem; flex-wrap: wrap;
}
.card-stat {
    text-align: center; padding: .5rem; background: var(--bg-2);
    border-radius: var(--radius-sm); min-width: 80px;
}
.card-stat .cs-value { font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.card-stat .cs-label { font-size: .625rem; color: var(--text-3); }

/* ═══════════════════════════════════════════════════════
   RECHERCHE
   ═══════════════════════════════════════════════════════ */

.search-container {
    display: flex; flex-direction: column; height: 100%; overflow: hidden;
}
.search-toolbar {
    display: flex; gap: .5rem; padding: .75rem; border-bottom: 1px solid var(--border);
    flex-shrink: 0; align-items: center;
}
.search-input {
    flex: 1; padding: .5rem .75rem; background: var(--bg-2); border: 1px solid var(--bg-3);
    border-radius: var(--radius); color: var(--text-1); font-size: .8125rem; outline: none;
}
.search-input:focus { border-color: var(--accent); }
.search-toolbar select {
    background: var(--bg-2); color: var(--text-1); border: 1px solid var(--bg-3);
    border-radius: var(--radius-sm); padding: .375rem .5rem; font-size: .75rem;
}

.search-results {
    flex: 1; overflow-y: auto; padding: .75rem;
    display: flex; flex-direction: column; gap: .5rem;
}
.search-project-group {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: .5rem;
}
.search-project-header {
    padding: .5rem .75rem; font-weight: 600; font-size: .8125rem;
    border-bottom: 1px solid var(--border); color: var(--accent);
}
.search-conv-group { padding: .375rem .75rem; }
.search-conv-header { font-size: .75rem; color: var(--text-3); margin-bottom: .375rem; font-weight: 500; }
.search-result-item {
    padding: .375rem .5rem; background: var(--bg-2); border-radius: var(--radius-sm);
    font-size: .8125rem; margin-bottom: .25rem; border-left: 3px solid var(--bg-3);
}
.search-result-item .sr-meta { font-size: .625rem; color: var(--text-3); }
.search-result-item .sr-content { line-height: 1.4; }
.search-result-item mark { background: rgba(59, 130, 246, .3); color: var(--text-1); padding: 0 2px; border-radius: 2px; }

/* ═══════════════════════════════════════════════════════
   GIT DIFF
   ═══════════════════════════════════════════════════════ */

.diff-container { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.diff-toolbar {
    display: flex; gap: .5rem; padding: .75rem; border-bottom: 1px solid var(--border);
    flex-shrink: 0; align-items: center;
}
.diff-toolbar select {
    background: var(--bg-2); color: var(--text-1); border: 1px solid var(--bg-3);
    border-radius: var(--radius-sm); padding: .375rem .5rem; font-size: .75rem;
}
.diff-output {
    flex: 1; overflow: auto; padding: .5rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: .75rem; line-height: 1.5;
    white-space: pre-wrap; word-break: break-all;
}
.diff-line { padding: 0 .5rem; }
.diff-line.add { background: rgba(34, 197, 94, .12); color: var(--green); }
.diff-line.del { background: rgba(239, 68, 68, .12); color: var(--red); }
.diff-line.header { color: var(--accent); font-weight: 600; }
.diff-line.hunk { color: var(--yellow); background: rgba(245, 158, 11, .08); }
.diff-file-header {
    padding: .5rem .75rem; background: var(--bg-2); border-radius: var(--radius-sm);
    margin: .5rem 0 .25rem; font-weight: 600; font-size: .8125rem; color: var(--text-1);
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */

/* ─── Mobile top bar ───────────────────────────────── */
.mobile-top-bar {
    display: none; /* shown via media query */
    position: fixed; top: 0; left: 0; right: 0; z-index: 35;
    height: 44px; background: var(--bg-1); border-bottom: 1px solid var(--border);
    align-items: center; padding: 0 .5rem; gap: .375rem;
}
.mobile-top-bar .btn-sidebar-toggle {
    position: static; background: none; border: none; color: var(--text-1);
    font-size: 1.25rem; padding: .375rem; cursor: pointer;
}
.mobile-brand { font-weight: 700; font-size: .8rem; flex: 1; }
.mobile-actions { display: flex; gap: .125rem; }

@media (max-width: 768px) {
    :root { --sidebar-w: 260px; --chat-w: calc(100vw - 2rem); --chat-h: 420px; }

    /* Mobile top bar */
    .mobile-top-bar { display: flex !important; }
    #dashboard { padding-top: 44px; }

    #sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        z-index: 40; box-shadow: 4px 0 20px rgba(0,0,0,.5);
    }
    #sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

    /* Viewer header: scrollable tabs */
    #viewer-header { flex-wrap: nowrap; height: auto; padding: .375rem .5rem; gap: .25rem; overflow: hidden; }
    .viewer-agent-info { display: none; } /* hide on mobile to save space */
    .viewer-tabs {
        margin-left: 0; flex-shrink: 1; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none; gap: 1px;
    }
    .viewer-tabs::-webkit-scrollbar { display: none; }
    .tab { padding: .3rem .4rem; font-size: .7rem; flex-shrink: 0; }
    .viewer-actions { margin-left: auto; flex-shrink: 0; }

    /* Chat: draggable on mobile too */
    .chat-popup { bottom: .5rem; right: .5rem; }
    .chat-popup:not(.minimized) { left: .5rem; width: auto; }
    .chat-expanded { width: 100%; }
    /* When being dragged, remove left constraint */
    .chat-popup.dragged { left: auto !important; right: auto !important; width: var(--chat-w); }
}
