:root {
  --bg: #0e1117;
  --surface: #1a1f2e;
  --surface2: #222840;
  --border: #2d3547;
  --text: #e4e8f0;
  --muted: #8892a4;
  --accent: #25d366;
  --accent-hover: #1aaf54;
  --danger: #e53e3e;
  --warn: #d69e2e;
  --info: #3182ce;
  --you: #005c4b;
  --other: #1f2c34;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.4);
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --border: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --you: #dcf8c6;
  --other: #ffffff;
}

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

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ── */
.navbar { display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 200; }
.nav-brand a { font-weight: 700; font-size: 16px; color: var(--accent); text-decoration: none; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a { padding: 6px 12px; border-radius: var(--radius); color: var(--text); font-size: 14px; }
.nav-links a.active, .nav-links a:hover { background: var(--surface2); color: var(--accent); }
.nav-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.main-content { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--surface2); color: var(--text); transition: background .15s; text-decoration: none; }
.btn:hover { background: var(--border); text-decoration: none; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }
.btn-block { width: 100%; justify-content: center; }
.btn-active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── Alerts ── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.alert-error { background: rgba(229,62,62,.15); border: 1px solid var(--danger); color: #fc8181; }
.alert-info { background: rgba(49,130,206,.15); border: 1px solid var(--info); color: #63b3ed; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea { width: 100%; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface2); color: var(--text); font-size: 14px; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
.form-control { padding: 7px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface2); color: var(--text); font-size: 13px; }
.form-control-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface2); color: var(--text); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-section { margin-bottom: 24px; }
.form-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; font-weight: 500; }

/* ── Page header ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 22px; font-weight: 700; }

/* ── Login ── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 36px; width: 360px; }
.login-logo { font-size: 48px; text-align: center; margin-bottom: 8px; }
.login-title { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 24px; }
.login-form { display: flex; flex-direction: column; gap: 0; }

/* ── Chat grid ── */
.chat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.chat-card { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: border-color .15s; text-decoration: none; color: var(--text); }
.chat-card:hover { border-color: var(--accent); text-decoration: none; }
.chat-card-icon { font-size: 28px; }
.chat-card-body { flex: 1; }
.chat-card-name { font-weight: 600; font-size: 15px; }
.chat-card-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chat-card-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* ── Chat viewer ── */
.participants-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chip { background: var(--surface2); border-radius: 12px; padding: 3px 10px; font-size: 12px; }
.chip-sm { background: var(--surface2); border-radius: 8px; padding: 2px 6px; font-size: 11px; }
.badge { display: inline-flex; align-items: center; border-radius: 10px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.badge-enc { background: rgba(214,158,46,.2); color: #d69e2e; }
.badge-completed { background: rgba(37,211,102,.2); color: var(--accent); }
.badge-running { background: rgba(49,130,206,.2); color: #63b3ed; }
.badge-pending { background: rgba(113,128,150,.2); color: #a0aec0; }
.badge-failed { background: rgba(229,62,62,.2); color: #fc8181; }
.role-administrator { background: rgba(214,158,46,.2); color: #d69e2e; border-radius: 8px; padding: 2px 6px; font-size: 11px; }
.role-agent { background: rgba(49,130,206,.2); color: #63b3ed; border-radius: 8px; padding: 2px 6px; font-size: 11px; }
.role-viewer { background: rgba(113,128,150,.2); color: #a0aec0; border-radius: 8px; padding: 2px 6px; font-size: 11px; }

.date-sep { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0; margin: 6px 0; }
.date-sep span { background: var(--surface); padding: 3px 12px; border-radius: 10px; border: 1px solid var(--border); }
.system-msg { text-align: center; color: var(--muted); font-size: 12px; padding: 3px 0; }
.bubble-row { display: flex; padding: 1px 0; }
.bubble-row.you { justify-content: flex-end; }
.bubble-row.other { justify-content: flex-start; }
.bubble { max-width: 65%; padding: 7px 12px 4px; border-radius: 8px; word-break: break-word; }
.bubble-row.you .bubble { background: var(--you); border-bottom-right-radius: 2px; }
.bubble-row.other .bubble { background: var(--other); border-bottom-left-radius: 2px; }
.bubble-row.no-tail.you .bubble { border-bottom-right-radius: 8px; }
.bubble-row.no-tail.other .bubble { border-bottom-left-radius: 8px; }
.sender-name { font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; font-size: 14px; }
.msg-time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.pagination-bar { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 10px; background: var(--surface); border-top: 1px solid var(--border); }

/* ── Import ── */
.import-container { max-width: 700px; }
.import-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.drop-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 36px; text-align: center; transition: border-color .15s; cursor: pointer; }
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); }
.drop-zone-icon { font-size: 36px; margin-bottom: 8px; }

/* ── Job card ── */
.job-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 600px; }
.job-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-top: 16px; font-size: 13px; }
.job-meta dt { color: var(--muted); font-weight: 500; }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* ── Attachments ── */
.attachment { margin-bottom: 4px; }
.attachment-image a, .attachment-video a { display: inline-block; }
.media-thumb { max-width: 240px; max-height: 240px; border-radius: 6px; display: block; object-fit: cover; cursor: pointer; transition: opacity .15s; }
.media-thumb:hover { opacity: .85; }
.video-thumb-wrap { position: relative; display: inline-block; }
.play-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 28px; color: #fff; text-shadow: 0 0 8px rgba(0,0,0,.7); pointer-events: none; }
.audio-player { max-width: 260px; height: 36px; border-radius: 18px; margin: 2px 0; }
.attachment-name { font-size: 11px; color: var(--muted); margin-top: 2px; }
.attachment-file a { display: flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13px; }
.file-icon { font-size: 18px; }
.file-size { font-size: 11px; color: var(--muted); }
.attachment-caption { font-size: 13px; color: var(--muted); margin-top: 3px; font-style: italic; }
.attachment-missing { font-size: 13px; color: var(--muted); }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stats-section { margin-top: 28px; }
.stats-section h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.chart-container { background: var(--surface); border-radius: var(--radius); padding: 12px; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; display: flex; align-items: center; gap: 6px; }
.emoji-char { font-size: 20px; }
.emoji-count { font-size: 12px; color: var(--muted); }
.word-cloud { display: flex; flex-wrap: wrap; gap: 6px; line-height: 1; }
.word-tag { color: var(--accent); opacity: .8; }

/* ── Search ── */
.search-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-input { flex: 1; min-width: 200px; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface2); color: var(--text); font-size: 14px; }
.search-meta { margin-bottom: 12px; }
.search-result-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.result-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.result-date { font-size: 12px; }
.result-text { white-space: pre-wrap; word-break: break-word; font-size: 13px; }

/* ── Admin ── */
.admin-nav { display: flex; gap: 6px; margin-bottom: 16px; }
.admin-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
.admin-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.admin-col h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.admin-actions { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.admin-actions h3 { font-size: 14px; margin-bottom: 10px; }

/* ── Tables ── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); color: var(--muted); font-weight: 600; }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: var(--surface2); }

/* ── Unlock ── */
.unlock-card { max-width: 420px; margin: 80px auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 36px; text-align: center; }
.unlock-icon { font-size: 48px; margin-bottom: 12px; }
.unlock-card h2 { font-size: 20px; margin-bottom: 4px; }
.unlock-subtitle { font-size: 15px; color: var(--accent); margin-bottom: 8px; }
.unlock-hint { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.unlock-form { text-align: left; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .btn { margin-top: 16px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px 0; }
.collapsible summary { cursor: pointer; list-style: none; }
details[open] summary { margin-bottom: 12px; }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { display: none; position: absolute; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 160px; z-index: 100; box-shadow: var(--shadow); }
.dropdown:hover .dropdown-menu, .dropdown:focus-within .dropdown-menu { display: block; }
.dropdown-menu a { display: block; padding: 8px 14px; font-size: 13px; color: var(--text); }
.dropdown-menu a:hover { background: var(--surface2); text-decoration: none; }
code { font-family: 'Courier New', monospace; font-size: 12px; background: var(--surface2); padding: 1px 4px; border-radius: 3px; }
