* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f4f6fa; color: #1f2937; font-size: 14px; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

html, body { overflow-x: hidden; }
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; max-width: 100vw; }
.main { min-width: 0; }
.panel { max-width: 100%; overflow-x: auto; }
.sidebar { background: #111827; color: #e5e7eb; padding: 20px 14px; display: flex; flex-direction: column; }
.sidebar .brand { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; margin-bottom: 20px; color: #fff; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a { color: #cbd5e1; padding: 8px 10px; border-radius: 6px; }
.sidebar nav a.active, .sidebar nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.sidebar .me { margin-top: auto; border-top: 1px solid #1f2937; padding-top: 14px; color: #9ca3af; }
.sidebar .me-name { color: #e5e7eb; font-weight: 600; }
.sidebar .me-role { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.sidebar .logout { background: transparent; color: #f87171; border: 1px solid #374151; padding: 6px 10px; border-radius: 6px; cursor: pointer; width: 100%; }
.sidebar .logout:hover { background: #1f2937; }

.main { padding: 24px 28px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 22px; }
.muted { color: #6b7280; }

.btn { display: inline-block; padding: 8px 12px; background: #fff; border: 1px solid #d1d5db; border-radius: 6px; color: #1f2937; cursor: pointer; font-size: 14px; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.primary:hover { background: #1d4ed8; }

.flash { padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 14px 16px; }
.card-label { color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 26px; font-weight: 700; margin-top: 4px; }

.panel { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px 18px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 12px 0; font-size: 16px; }
.panel h3 { margin: 12px 0 6px; font-size: 14px; color: #374151; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2, .cards { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .sidebar { position: static; } }

/* sidebar tree (under Users) */
.sb-tree-wrap { margin: 4px 0 6px 6px; }
.sb-tree, .sb-tree ul { list-style: none; margin: 0; padding: 0; }
.sb-tree ul { padding-left: 12px; border-left: 1px dashed #374151; margin-left: 6px; }
.sb-tree li { padding: 1px 0; }
.sb-tree-node { display: flex; align-items: center; gap: 6px; padding: 2px 6px 2px 4px; border-radius: 4px; font-size: 13px; }
.sb-tree-node:hover { background: #1f2937; }
.sb-tree-link { color: #cbd5e1; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.sb-tree-link:hover { color: #fff; text-decoration: none; }
.sb-count { background: #1f2937; color: #cbd5e1; font-size: 11px; padding: 1px 7px; border-radius: 999px; min-width: 20px; text-align: center; }
a.sb-count:hover { background: #2563eb; color: #fff; text-decoration: none; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
table.data th { background: #f9fafb; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #6b7280; }
table.data th a.sort-link { color: inherit; text-decoration: none; display: inline-block; }
table.data th a.sort-link:hover { color: #111827; text-decoration: none; }
table.data tr:hover td { background: #fafbfc; }
.empty { color: #6b7280; padding: 14px; text-align: center; font-style: italic; }

.pagination { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid #f1f5f9; font-size: 13px; color: #374151; }
.pagination .per-page { display: flex; align-items: center; gap: 6px; }
.pagination .per-page a { padding: 3px 9px; border: 1px solid #d1d5db; border-radius: 4px; color: #2563eb; background: #fff; }
.pagination .per-page a:hover { background: #f3f4f6; text-decoration: none; }
.pagination .per-page strong { padding: 3px 9px; border: 1px solid #2563eb; background: #2563eb; color: #fff; border-radius: 4px; font-weight: 600; }
.pagination .page-info { color: #6b7280; margin-left: auto; }
.pagination .page-nav { display: flex; gap: 4px; align-items: center; }
.pagination .page-nav .btn { padding: 5px 10px; font-size: 13px; }
.pagination .page-nav .btn.disabled { color: #9ca3af; background: #f9fafb; cursor: not-allowed; pointer-events: none; }
.pagination .page-num { padding: 0 8px; color: #374151; }

.scope-banner { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.scope-banner a { color: #1e40af; font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.bulk-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; padding: 8px 10px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; flex-wrap: wrap; }
.bulk-bar .bulk-label { font-size: 13px; color: #374151; }
.bulk-bar #sel-count { font-weight: 700; color: #111827; }
.bulk-bar label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; }
.bulk-bar select { padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }

.export-panel summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.export-panel[open] summary { margin-bottom: 8px; }
.export-form { display: flex; flex-direction: column; gap: 10px; }
.export-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 12px; padding: 8px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; }
.export-fields label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; }
.export-form .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.token-box { display: block; background: #f9fafb; border: 1px solid #e5e7eb; padding: 10px 12px; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; user-select: all; }

.board-grid.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.lead-card { background: #fff; border: 1px solid #e5e7eb; border-left: 4px solid #2563eb; border-radius: 8px; padding: 12px 14px; box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04); }
.lead-card h3 { margin: 0 0 6px; font-size: 15px; }
.lead-card .meta { font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.lead-card .row-meta { font-size: 13px; color: #374151; margin-bottom: 4px; }
.lead-card .since { font-size: 11px; }
.lead-card .assign-me { margin-top: 8px; font-size: 12px; padding: 5px 10px; }
.lead-card .assign-me:disabled { opacity: 0.6; cursor: default; }

.status-badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; background: #e5e7eb; color: #374151; }
.status-badge.status-in-call { background: #dbeafe; color: #1e40af; }
.status-badge.status-transfer { background: #fee2e2; color: #991b1b; }
.status-badge.status-calling { background: #fef3c7; color: #92400e; }

.lead-card.status-transfer { border-left-color: #dc2626; background: #fff7f7; }

@keyframes card-blink {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); background: #fff7f7; }
  50%      { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.35); background: #fee2e2; }
}
.lead-card.blink { animation: card-blink 1.1s ease-in-out infinite; }

.today-stats h2 { margin: 0 0 10px; font-size: 16px; }
.today-stats h3 { margin: 16px 0 8px; font-size: 13px; color: #374151; }
.stats-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stats-header h2 { margin: 0; }
.range-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range-form select, .range-form input[type=date] { padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; background: #fff; }
.range-form .custom-dates { display: inline-flex; gap: 4px; }
.today-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.today-card { border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 14px; background: #fff; }
.today-card .today-label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; }
.today-card .today-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.today-calling { border-left: 4px solid #d97706; }
.today-in-call { border-left: 4px solid #2563eb; }
.today-transfer { border-left: 4px solid #dc2626; }

.country-stats { width: 100%; margin-top: 4px; }
.country-stats .bar-col { width: 30%; min-width: 160px; }
.stacked-bar { display: flex; height: 14px; background: #f3f4f6; border-radius: 7px; overflow: hidden; }
.stacked-bar .seg { display: block; height: 100%; }
.seg-calling { background: #f59e0b; }
.seg-in-call { background: #3b82f6; }
.seg-transfer { background: #ef4444; }
.legend { margin-top: 8px; display: flex; gap: 14px; font-size: 12px; color: #6b7280; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.board-table .since { color: #6b7280; font-size: 12px; }
.hidden { display: none !important; }

.status-cell .status-value { font-weight: 500; }
.status-cell .status-time { color: #9ca3af; font-size: 11px; margin-top: 2px; }
.status-cell.status-flash { animation: statusFlash 1.2s ease-out; }
@keyframes statusFlash {
  0% { background: #fef3c7; }
  100% { background: transparent; }
}

.status-history { list-style: none; padding: 0; margin: 0; }
.status-history li { padding: 6px 0; border-top: 1px solid #f1f5f9; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.status-history li:first-child { border-top: none; }
.status-history .change { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.status-history .from { color: #6b7280; }
.status-history .arrow { color: #9ca3af; }
.status-history .to { font-weight: 600; color: #111827; }
.status-history .meta { color: #6b7280; font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: span 2; }
.form-grid label { display: flex; flex-direction: column; font-size: 12px; color: #374151; text-transform: uppercase; letter-spacing: 0.4px; gap: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; font-family: inherit; color: #111827; }
.form-grid input[readonly] { background: #f3f4f6; color: #6b7280; cursor: not-allowed; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 6px; text-transform: none; font-size: 14px; color: #1f2937; }
.form-grid .actions { grid-column: span 2; display: flex; gap: 8px; }

.stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.stack .row { display: flex; gap: 8px; }
.stack textarea, .stack input, .stack select { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; font-family: inherit; }
.stack button { align-self: flex-start; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0; border-top: 1px solid #f1f5f9; }
.timeline li:first-child { border-top: none; }
.timeline-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.timeline-head .meta { color: #6b7280; font-size: 12px; }
.timeline-body { white-space: pre-wrap; color: #1f2937; margin-bottom: 6px; }
.timeline .summary { background: #f9fafb; border-left: 3px solid #6366f1; padding: 6px 10px; margin-bottom: 6px; font-size: 13px; color: #374151; border-radius: 4px; }
.timeline audio { display: block; margin-top: 4px; width: 100%; max-width: 480px; }

.badge { display: inline-block; padding: 2px 7px; background: #eef2ff; color: #3730a3; border-radius: 999px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.badge-incoming { background: #ecfeff; color: #155e75; }
.badge-outgoing { background: #f0fdf4; color: #166534; }
.badge-internal { background: #fef3c7; color: #92400e; }

.feed { list-style: none; padding: 0; margin: 0; }
.feed li { padding: 8px 0; border-top: 1px solid #f1f5f9; }
.feed li:first-child { border-top: none; }
.feed .meta { display: block; color: #6b7280; font-size: 12px; margin-top: 2px; }
.feed .snippet { color: #374151; margin: 2px 0; }
.feed audio { display: block; margin-top: 4px; width: 100%; max-width: 420px; }

.mini { list-style: none; padding: 0; margin: 6px 0 0 0; }
.mini li { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.mini li.muted { color: #9ca3af; justify-content: flex-start; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.kv dd { margin: 0; }

.notes { background: #f9fafb; padding: 10px; border-radius: 6px; white-space: pre-wrap; font-family: inherit; font-size: 14px; color: #1f2937; border: 1px solid #e5e7eb; }

.link { background: none; border: 0; color: #2563eb; cursor: pointer; padding: 0; font-size: 12px; }
.link:hover { text-decoration: underline; }
.link.danger { color: #dc2626; }
form.inline { display: inline; }

/* login */
body.auth { background: linear-gradient(180deg, #eef2ff, #f4f6fa); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border: 1px solid #e5e7eb; padding: 28px; border-radius: 10px; width: 320px; box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06); }
.login-card h1 { margin: 0 0 16px; font-size: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card label { display: flex; flex-direction: column; font-size: 12px; color: #374151; text-transform: uppercase; letter-spacing: 0.4px; gap: 4px; }
.login-card input { padding: 9px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.login-card button { margin-top: 6px; padding: 10px; }
