/* CallScribe interface design system — graphite & clean accents */
:root {
  color-scheme: dark;
  --bg: #181a1f;
  --topbar: #15171b;
  --panel: #22252a;
  --surface: #2a2d33;
  --surface-hover: #30343b;
  --field: #2a2d33;
  --text: #f2f4f7;
  --secondary: #c0c7d2;
  --muted: #979eaa;
  --subtle: #777f8b;
  --border: #ffffff15;
  --line: #ffffff12;
  --focus: #8fb5ff;
  --blue: #8fb5ff;
  --mint: #91dbc9;
  --lavender: #c7a5ff;
  --amber: #e5bc7d;
  --success: #8fd694;
  --error: #ff8a80;
  --r-card: 15px;
  --r-panel: 13px;
  --r-field: 9px;
  --shadow: 0 14px 44px #05060929;
  font-family: 'Segoe UI', Inter, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; font-weight: 650; }
button:disabled { opacity: .48; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* Topbar */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--topbar);
  border-bottom: 1px solid #ffffff14;
  box-shadow: 0 4px 20px #090a0e25;
}
.app-topbar-inner {
  height: 65px;
  max-width: 1400px;
  padding: 0 35px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.brand-emblem {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(145deg, #a2c4ff, #6b99ef);
  box-shadow: inset 0 1px #ffffff62, 0 5px 12px #0005;
  color: #171d29;
  font-size: 13px;
  font-weight: 850;
  letter-spacing: -.5px;
}
.brand-name strong {
  display: block;
  font-size: 17px;
  letter-spacing: -.4px;
  line-height: 1.15;
  font-weight: 750;
}
.brand-name small {
  display: block;
  margin-top: 4px;
  color: #929aa9;
  letter-spacing: 1.1px;
  font-size: 9px;
  font-weight: 700;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Buttons */
.outline, .primary, .iconbutton {
  border-radius: var(--r-field);
  border: 1px solid #ffffff16;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .14s, border-color .14s, transform .14s;
}
.outline {
  background: var(--surface);
  color: #e9edf5;
  padding: 9px 15px;
  font-size: 12px;
}
.outline:hover {
  background: var(--surface-hover);
  border-color: #ffffff35;
}
.primary {
  background: #f2f4f7;
  border: 1px solid #f2f4f7;
  color: #1b1e24;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 760;
  box-shadow: 0 2px 9px #0002;
}
.primary:hover {
  background: #dce4f2;
  border-color: #dce4f2;
}
.primary:active, .outline:active {
  transform: translateY(1px);
}
.compact {
  padding: 7px 12px;
  font-size: 11.5px;
  flex-shrink: 0;
}
.iconbutton {
  width: 32px;
  height: 32px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 16px;
  border-radius: 8px;
}
.iconbutton:hover {
  background: var(--surface);
  color: var(--text);
}

/* Layout */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 30px 35px 50px;
}
.query-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 22px 26px 20px;
  box-shadow: 0 6px 24px #08090b13;
  margin-bottom: 22px;
}
.query-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.section-kicker, .dialog-kicker {
  font-weight: 750;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: #92a1b8;
  line-height: 1.4;
  text-transform: uppercase;
}
.query-head h1 {
  font-size: 24px;
  letter-spacing: -.5px;
  line-height: 1.2;
  font-weight: 750;
  margin: 6px 0 0;
}
.query-tag {
  padding: 6px 11px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #ffffff13;
  background: #ffffff08;
  color: #afb9c8;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .7px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
.inputrow {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.url-inputrow {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.url-inputrow input {
  height: 46px;
  background: #1c1f25;
  padding-left: 16px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: var(--r-field);
  color: var(--text);
  flex: 1;
}
.url-inputrow input:hover {
  border-color: #ffffff36;
}
.url-inputrow input:focus {
  border-color: #7195d2;
  box-shadow: 0 0 0 3px #8fb5ff19;
}
.url-inputrow button {
  min-width: 210px;
  height: 46px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}
.input-hint {
  font-size: 11.5px;
  color: #858f9e;
  margin: 11px 0 0;
  line-height: 1.6;
}
.webhook-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 10px 16px;
  border-radius: 9px;
  background: #e5bc7d15;
  border: 1px solid #e5bc7d40;
  color: #edd9b9;
  font-size: 12.5px;
}

/* Busy / Progress */
.busy {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 20px;
  margin: 0 0 20px;
  border: 1px solid #90b6ff35;
  background: #8fb5ff0e;
  border-radius: 12px;
  color: #cbd9f5;
  font-size: 13px;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #445167;
  border-top-color: #a6c7ff;
  border-radius: 100%;
  animation: spin .85s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.elapsed {
  margin-left: auto;
  color: #acbfdc;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.error {
  padding: 14px 18px;
  margin: 0 0 20px;
  border: 1px solid #ff8a8050;
  background: #ff8a8011;
  color: #ffb9b4;
  border-radius: 11px;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: 16px 20px;
}
.stat-value {
  font-size: 26px;
  font-weight: 750;
  color: var(--blue);
  line-height: 1.1;
  margin-bottom: 5px;
}
.stat-label {
  font-size: 11.5px;
  color: var(--muted);
}

/* Call items */
.results-section h2 {
  font-size: 18px;
  margin: 0 0 16px;
  font-weight: 700;
}
.calls-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.call-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 20px 24px;
  box-shadow: 0 4px 18px #08090b10;
  transition: border-color .15s;
}
.call-card:hover {
  border-color: #ffffff28;
}
.call-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.call-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.call-title {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: .3px;
  color: #ffffff;
}
.call-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 4px 9px;
  border-radius: 6px;
  text-transform: uppercase;
}
.call-badge.incoming {
  background: #8fd69418;
  color: var(--success);
  border: 1px solid #8fd69430;
}
.call-badge.outgoing {
  background: #8fb5ff18;
  color: var(--blue);
  border: 1px solid #8fb5ff30;
}
.call-badge.unknown {
  background: #ffffff10;
  color: var(--muted);
  border: 1px solid #ffffff15;
}
.call-meta {
  font-size: 12px;
  color: var(--muted);
}
.call-audio-wrap {
  margin: 12px 0 16px;
}
.call-audio-wrap audio {
  width: 100%;
  height: 38px;
  border-radius: 8px;
  outline: none;
}
.transcript-box {
  background: #191b20;
  border: 1px solid #ffffff10;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  position: relative;
}
.transcript-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--subtle);
  letter-spacing: .7px;
  text-transform: uppercase;
}
.copy-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
}
.copy-btn:hover {
  background: var(--surface);
  color: var(--text);
}
.transcript-text {
  font-size: 13px;
  line-height: 1.65;
  color: #dbe0eb;
  white-space: pre-wrap;
  word-break: break-word;
}
.bitrix-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--success);
  background: #8fd69412;
  border: 1px solid #8fd69430;
  padding: 6px 12px;
  border-radius: 8px;
}
.bitrix-badge.error {
  color: var(--error);
  background: #ff8a8012;
  border-color: #ff8a8030;
}

/* Live Log Drawer */
.log-card {
  margin-top: 24px;
  background: #191b20;
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: 16px 20px;
}
.log-card summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}
.log-card summary:hover {
  color: var(--text);
}
.log-entries {
  margin-top: 12px;
  font-family: Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.7;
  color: #8c97a8;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 8px;
}

/* Modal Dialog & DeepBrief-style Settings */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0a0c10d9;
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dialog {
  background: var(--panel);
  border: 1px solid #ffffff24;
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  box-shadow: 0 28px 90px #000000bb;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 960px);
}
.settings-dialog {
  max-width: 780px;
}
.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px 18px;
  border-bottom: 1px solid var(--line);
  background: #15171b;
  gap: 16px;
}
.dialog-header h2 {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -.35px;
  margin: 6px 0 4px;
}
.dialog-header p {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}
.dialog-body {
  padding: 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}
.settings-card {
  padding: 17px 19px 18px;
  background: #282b31;
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 0;
}
.settings-section-header {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line);
}
.setting-index {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border-radius: 8px;
  background: #8fb5ff1a;
  color: var(--blue);
  font-size: 10.5px;
  font-weight: 750;
  flex-shrink: 0;
}
.settings-section-header h3 {
  font-size: 13.5px;
  color: #edf1f8;
  font-weight: 750;
  margin: 0;
  line-height: 1.35;
}
.settings-section-content label {
  font-size: 11.5px;
  font-weight: 650;
  color: #d3d9e5;
  margin: 0 0 7px;
  display: block;
}
.settings-section-content input,
.settings-section-content select {
  background: #202328;
  font-size: 12.5px;
  padding: 10px 13px;
  border: 1px solid #ffffff17;
  border-radius: var(--r-field);
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.settings-section-content input:hover {
  border-color: #ffffff36;
}
.settings-section-content input:focus {
  border-color: #7195d2;
  box-shadow: 0 0 0 3px #8fb5ff19;
}
.settings-section-content .inputrow {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.settings-section-content .inputrow input {
  flex: 1;
}
.settings-section-content .inputrow button {
  font-size: 12px;
  padding: 9px 16px;
  white-space: nowrap;
  flex-shrink: 0;
}
.settings-section-content .help {
  font-size: 11px;
  color: #969fad;
  margin: 7px 0 0;
  line-height: 1.6;
}
.admin-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.timeline-depth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.timeline-depth-row label {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  color: #d3d9e5;
}
.timeline-depth-row input {
  width: 130px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 8px 12px;
}
.test-status {
  margin-top: 10px;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 7px 12px;
  border-radius: 8px;
}
.test-status.success {
  color: var(--success);
  background: #8fd69414;
  border: 1px solid #8fd69430;
}
.test-status.error {
  color: var(--error);
  background: #ff8a8014;
  border: 1px solid #ff8a8030;
}
.test-status.checking {
  color: var(--blue);
  background: #8fb5ff10;
  border: 1px solid #8fb5ff26;
}
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  background: #191b20;
}
.dialog-footnote {
  margin-right: auto;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 800px) {
  .layout { padding: 20px 16px 36px; }
  .app-topbar-inner { padding: 0 16px; }
  .url-inputrow { flex-direction: column; }
  .url-inputrow button { width: 100%; min-height: 44px; }
  .admin-form-grid { grid-template-columns: 1fr; gap: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .call-head { flex-direction: column; align-items: flex-start; }
  .dialog-footer { flex-wrap: wrap; }
  .dialog-footnote { width: 100%; margin-bottom: 8px; }
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}
.mode-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  color: var(--secondary);
  font-size: 15px;
  font-weight: 650;
  transition: all .16s ease;
}
.mode-tab:hover {
  background: var(--surface);
  color: var(--text);
  border-color: #ffffff26;
}
.mode-tab.active {
  background: #21293a;
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 4px 18px #4f80e120;
}
.tab-icon {
  font-size: 18px;
}
.tab-count {
  background: var(--blue);
  color: #0b1528;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 12px;
}

/* Daemon Indicator Pill */
.daemon-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: #102619;
  border: 1px solid #23854740;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 650;
  color: #7ce399;
}
.daemon-indicator.paused {
  background: #281d0c;
  border-color: #b3741840;
  color: #e5bc7d;
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #52dc7e;
  box-shadow: 0 0 10px #52dc7e;
  animation: pulse 1.8s infinite;
}
.daemon-indicator.paused .pulse-dot {
  background: #e5bc7d;
  box-shadow: none;
  animation: none;
}
@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(82, 220, 126, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(82, 220, 126, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(82, 220, 126, 0); }
}

/* Webhook Endpoint Box */
.webhook-endpoint-box {
  background: #191c22;
  border: 1px solid #ffffff1a;
  border-radius: var(--r-panel);
  padding: 18px;
  margin: 18px 0;
}
.endpoint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--secondary);
}
.endpoint-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  background: #19273c;
  color: var(--blue);
  border-radius: 6px;
  border: 1px solid #33598f40;
}
.endpoint-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.endpoint-row input {
  flex: 1;
  background: #101216;
  border: 1px solid #ffffff1e;
  border-radius: var(--r-field);
  padding: 10px 14px;
  color: #a4c9ff;
  font-family: Consolas, monospace;
  font-size: 13px;
}
.endpoint-hint {
  margin: 10px 0 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

/* Daemon Current Processing Card */
.daemon-current-card {
  background: linear-gradient(135deg, #1b263b, #191e2b);
  border: 1px solid #4a77c750;
  border-radius: var(--r-panel);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.daemon-current-card .spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #4f80e130;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.current-info strong {
  display: block;
  font-size: 14px;
  color: #fff;
}
.current-info span {
  font-size: 12px;
  color: var(--secondary);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 0 16px 0;
  flex-wrap: wrap;
}
.filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all .12s ease;
}
.filter-chip:hover {
  background: var(--surface);
  color: var(--text);
}
.filter-chip.active {
  background: #252e3e;
  border-color: var(--blue);
  color: #fff;
}
.search-input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--text);
  font-size: 12px;
  width: 220px;
}
.empty-placeholder {
  text-align: center;
  padding: 48px 20px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--r-card);
  color: var(--muted);
}
.empty-placeholder .icon {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
}
