/* Jampp Gong Explorer — UI styles
 * Visual refresh only. All selectors used by app.js are preserved verbatim. */

:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-soft: #f8fafc;
  --border: #e3e6ee;
  --border-soft: #eef0f6;
  --text: #1a1d29;
  --text-muted: #6b7180;
  --text-faint: #9aa0ad;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8f0fe;
  --primary-soft-strong: #d6e4fd;
  --primary-text: #1e40af;
  --success: #16a34a;
  --success-hover: #15803d;
  --success-soft: #dcfce7;
  --success-text: #166534;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn-soft: #fff5e6;
  --warn-text: #8a5a1a;
  --warn-border: #f5dcb5;
  --topbar-bg: #1b1f2c;
  --topbar-bg-2: #252a3a;
  --topbar-text: #f5f7fb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.06);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.22);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--topbar-bg) 0%, var(--topbar-bg-2) 100%);
  color: var(--topbar-text);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #0f1320;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 2px 8px rgba(0, 0, 0, 0.18);
}
.title { display: flex; align-items: center; gap: 14px; }
.title h1 {
  font-size: 19px; margin: 0; font-weight: 600;
  letter-spacing: -0.01em;
}
.badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #2a3142;
  color: #cfd6e2;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.badge.ok {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
  box-shadow: inset 0 0 0 1px rgba(134, 239, 172, 0.25);
}
.config { font-size: 12px; color: #aab2c0; }
.config code {
  background: #2a3142;
  padding: 2px 8px;
  border-radius: 4px;
  color: #d8dde8;
  font-size: 12px;
}

/* ---------- Tabs ---------- */
.tabs {
  background: var(--bg-elev);
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 2px;
}
.tab, .subtab {
  background: none; border: 0;
  padding: 13px 18px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  font-weight: 500;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
  border-radius: 0;
}
.tab.active, .subtab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tab:hover:not(.active), .subtab:hover:not(.active) {
  color: var(--primary);
  background: var(--bg-soft);
}
.tab:focus-visible, .subtab:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring) inset;
  border-radius: 4px;
}
.subtab { padding: 7px 14px; font-size: 12px; }

/* ---------- Main ---------- */
main { padding: 20px 28px 40px; }
.panel.hidden { display: none; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.toolbar input[type="number"] { width: 70px; }

/* ---------- Inputs ---------- */
input, button, select {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 11px;
  border: 1px solid #d1d5dd;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
input[type="search"] {
  flex: 0 0 280px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7180' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3e%3ccircle cx='11' cy='11' r='7'/%3e%3cpath d='m21 21-4.3-4.3'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: 10px center;
  padding-left: 32px;
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7180' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

/* ---------- Buttons ---------- */
button {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease,
              transform 80ms ease, box-shadow 120ms ease;
  box-shadow: var(--shadow-sm);
}
button:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: white;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}
button.secondary {
  background: var(--bg-elev);
  color: var(--text);
  border-color: #d1d5dd;
}
button.secondary:hover:not(:disabled) {
  background: var(--bg-soft);
  border-color: #b8bdca;
  color: var(--text);
}
.counter {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
/* Calls counter is long — drop it to its own row, left-aligned. */
#call-count {
  margin-left: 0;
  flex-basis: 100%;
  order: 99;
}

/* Drive-backfill status: full-width row above the counter. */
.backfill-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-basis: 100%;
  order: 98;
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-top: 4px;
}
.backfill-status.hidden { display: none; }
.backfill-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 240px;
  flex-shrink: 0;
  font-size: 12px;
}
#backfill-summary { font-weight: 600; color: var(--primary-text); }
#backfill-current {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
}
.backfill-status .progress-track { flex: 1; }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 60vh;
  box-shadow: var(--shadow-md);
}
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
th {
  background: var(--bg-soft);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
tbody tr { transition: background 100ms ease; }
tr:hover td { background: #f6f9ff; }
tr.selected td {
  background: var(--primary-soft) !important;
  box-shadow: inset 3px 0 0 var(--primary);
}
tr.clickable { cursor: pointer; }
code {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: #475569;
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 3px;
}
td code { background: transparent; padding: 0; }

/* ---------- Split layout (calls list + detail) ---------- */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}
.split .left .table-wrap { max-height: 75vh; }
.split .right {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: 75vh;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.detail-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fbfcfe 0%, var(--bg-elev) 100%);
}
.detail-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.detail-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  letter-spacing: -0.005em;
  color: var(--text);
}

/* ---------- Download button + progress ---------- */
#download-btn {
  background: var(--success);
  border-color: var(--success);
  flex-shrink: 0;
}
#download-btn:hover:not(:disabled) {
  background: var(--success-hover);
  border-color: var(--success-hover);
}
.download-area.hidden { display: none; }
.download-progress.hidden { display: none; }
#download-btn.hidden { display: none; }
.download-area {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.download-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 280px;
}
.progress-info {
  display: flex;
  gap: 12px;
  align-items: baseline;
  min-width: 140px;
  font-size: 11px;
}
#progress-stage { color: var(--text-muted); }
#progress-pct {
  font-weight: 700;
  color: var(--primary);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.progress-track {
  flex: 1;
  height: 6px;
  background: #dde2ec;
  border-radius: 999px;
  overflow: hidden;
  min-width: 80px;
  box-shadow: inset 0 1px 1px rgba(15, 23, 42, 0.08);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, #5a8df0 100%);
  background-size: 200% 100%;
  transition: width 220ms ease-out;
  animation: progress-shimmer 1.6s linear infinite;
}
@keyframes progress-shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}
.cancel-btn {
  background: var(--bg-elev);
  color: var(--danger);
  border: 1px solid #e2bcbc;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  box-shadow: none;
}
.cancel-btn:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: #d4a3a3;
  color: var(--danger);
}

/* ---------- Subtabs + detail body ---------- */
.subtabs {
  margin-top: 10px;
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: -14px;
  padding-bottom: 0;
}
.detail-body {
  padding: 14px 18px;
  overflow: auto;
  flex: 1;
}
.sub-pane.hidden { display: none; }

/* ---------- Transcript ---------- */
.transcript-segment {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  border-left: 3px solid var(--primary-soft-strong);
}
.transcript-segment .speaker {
  font-weight: 600;
  color: var(--primary);
  font-size: 12px;
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.transcript-segment .sentence {
  color: #2a2f3d;
  margin: 3px 0;
  line-height: 1.55;
}
.transcript-segment .timestamp {
  font-size: 11px;
  color: var(--text-faint);
  margin-right: 8px;
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  display: inline-block;
  min-width: 36px;
}

/* ---------- Key/value blocks ---------- */
.kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 6px 14px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
}
.kv .k {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}
.kv .v { font-size: 13px; }

/* ---------- Chips ---------- */
.chip {
  display: inline-block;
  padding: 3px 10px;
  margin: 2px 4px 2px 0;
  background: var(--primary-soft);
  color: var(--primary-text);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--primary-soft-strong);
}

.party-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 360px;
}
.party-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  background: #eef0f6;
  color: #475569;
  border: 1px solid var(--border);
  cursor: default;
  white-space: nowrap;
  font-weight: 500;
  transition: transform 100ms ease;
}
.party-chip:hover { transform: translateY(-1px); }
.party-chip.internal {
  background: var(--primary-soft);
  color: var(--primary-text);
  border-color: var(--primary-soft-strong);
  font-weight: 600;
}
.party-chip.external {
  background: var(--warn-soft);
  color: var(--warn-text);
  border-color: var(--warn-border);
}
.party-more {
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 6px;
  font-weight: 500;
}

/* ---------- Sections (scorecards) ---------- */
.section { margin-bottom: 32px; }
.section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  letter-spacing: -0.005em;
}
.hint {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 400;
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  background: var(--bg-soft);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
}
.muted { color: var(--text-muted); font-size: 12px; }

.forbid-domains { padding-left: 18px; }
.forbid-domains li { margin: 4px 0; }
.forbid-domains code {
  background: var(--danger-soft);
  color: #a31818;
  padding: 2px 6px;
  border-radius: 3px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--topbar-bg);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: toast-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  border-left: 3px solid var(--primary);
}
.toast.hidden { display: none; }
.toast.error {
  background: #7f1d1d;
  border-left-color: #fecaca;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Empty / loading states ---------- */
.empty {
  color: var(--text-faint);
  font-style: italic;
  padding: 28px;
  text-align: center;
}
.loading {
  color: var(--text-muted);
  padding: 28px;
  text-align: center;
  position: relative;
}
.loading::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 10px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Custom scrollbars (WebKit) ---------- */
.table-wrap::-webkit-scrollbar,
.detail-body::-webkit-scrollbar,
.split .right::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-track,
.detail-body::-webkit-scrollbar-track,
.split .right::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb,
.detail-body::-webkit-scrollbar-thumb,
.split .right::-webkit-scrollbar-thumb {
  background: #cdd2dd;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.table-wrap::-webkit-scrollbar-thumb:hover,
.detail-body::-webkit-scrollbar-thumb:hover,
.split .right::-webkit-scrollbar-thumb:hover {
  background: #aab1c0;
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .split .right { max-height: none; }
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .tabs { padding: 0 16px; }
  input[type="search"] { flex: 1 1 200px; }
}

/* ---------- Auth: topbar user chip ---------- */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: var(--topbar-text);
}
.user-chip.hidden { display: none; }
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.12);
}
.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.user-name {
  font-weight: 600;
  font-size: 13px;
}
.user-email {
  font-size: 11px;
  color: rgba(245, 247, 251, 0.65);
}
.logout-link {
  margin-left: 8px;
  color: rgba(245, 247, 251, 0.85);
  font-size: 12px;
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
}
.logout-link:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Auth: login page ---------- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(37, 99, 235, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(22, 163, 74, 0.10) 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}
.login-card .muted {
  margin: 0 0 24px;
  color: var(--text-muted);
}
.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 11px 22px;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, background 0.15s;
}
.google-btn:hover {
  background: #f8f9fa;
  box-shadow: var(--shadow-md);
}
.alert {
  text-align: left;
  padding: 12px 14px;
  margin: 0 0 18px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
}
.alert.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f5c6c6;
}
.alert.warn {
  background: var(--warn-soft);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}
.footnote {
  margin-top: 28px;
  font-size: 12px;
}

/* ---------- Admin tab ---------- */
#tab-admin .section { padding: 4px 0 24px; }
#tab-admin input[type="email"] {
  flex: 1 1 280px;
  max-width: 360px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
#tab-admin input[type="email"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.remove-user {
  font-size: 12px;
  padding: 4px 10px;
}

/* Visually separate duplicate-recording groups so it's obvious which rows
 * belong to the same callId. */
#dupes-table tr.dupe-group-start td {
  border-top: 2px solid var(--border);
}
#dupes-table tr.dupe-group-start:first-child td {
  border-top: none;
}
#dupes-table td.dupe-callid {
  vertical-align: top;
  background: var(--bg-soft);
}
#dupes-table code {
  font-size: 11px;
  color: var(--text-muted);
}
