:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #102033;
  --text-soft: #384b64;
  --muted: #6d7b8d;
  --line: #e5eaf1;
  --line-soft: #eef1f6;
  --navy: #0d2440;
  --blue: #286be6;
  --blue2: #eaf2ff;
  --teal: #0fa3a8;
  --success: #14865b;
  --successbg: #eaf8f2;
  --warn: #a96800;
  --warnbg: #fff5df;
  --danger: #bd4040;
  --dangerbg: #fff0f0;
  --agent-bubble: #f3f4f6;
  --customer-bubble: #e0e7ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.full-width { width: 100%; }

/* ========== APP SHELL ========== */

.app-shell { display: flex; min-height: 100vh; }

/* ========== SIDEBAR ========== */

.sidebar {
  width: 260px;
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 8px 24px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 16px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2f7df6, #16b3b5);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.brand-name .brand-accent { color: var(--blue); font-weight: 700; }

.brand-tagline {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

#nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  padding: 11px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

.nav-item:hover { background: var(--line-soft); }

.nav-item.active {
  background: #eef2f7;
  color: var(--text);
  font-weight: 600;
  position: relative;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--blue);
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.nav-item.active .nav-icon { color: var(--blue); }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 10px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.user-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-email {
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn.small {
  padding: 7px 10px;
  font-size: 12px;
}

.mini-label { color: var(--muted); margin-bottom: 2px; }

.status-row { display: flex; align-items: center; gap: 7px; }

.lang-block { display: flex; flex-direction: column; gap: 6px; }

.lang-select {
  width: 100%;
  padding: 7px 28px 7px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background-color: #fff;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%236d7b8d' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  transition: border-color 0.15s;
}

.lang-select:focus {
  outline: 2px solid var(--blue2);
  border-color: var(--blue);
}

.lang-select:hover { border-color: #c0c9d4; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c7d0dc;
}

.status-dot.ok { background: #3ad391; }
.status-dot.down { background: #d53b3b; }

/* ========== MAIN ========== */

.main {
  margin-left: 260px;
  width: calc(100% - 260px);
  padding: 26px 30px 50px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.topbar h1 { margin: 0; font-size: 24px; font-weight: 700; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.top-actions,
.inline-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ========== BUTTONS ========== */

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: opacity 0.15s, transform 0.05s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(1px); }

.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1f57c4; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--muted); }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.text-btn:hover { text-decoration: underline; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  font-size: 15px;
}

.icon-btn:hover { background: var(--line-soft); color: var(--text); }

/* ========== VIEWS ========== */

.view { display: none; }
.active-view { display: block; }

/* ========== PANEL ========== */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(21, 47, 76, 0.03);
}

.panel + .panel { margin-top: 14px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.panel h3 { margin: 0; font-size: 16px; font-weight: 700; }
.panel-head h3 { margin: 0; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--blue2);
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
}

.pill.success { background: var(--successbg); color: var(--success); }
.pill.warn { background: var(--warnbg); color: var(--warn); }
.pill.danger { background: var(--dangerbg); color: var(--danger); }

/* ========== INPUTS ========== */

.input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: #fff;
  min-width: 220px;
  color: var(--text);
}

.input:focus {
  outline: 2px solid var(--blue2);
  border-color: var(--blue);
}

.empty-state {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ========== UPLOAD VIEW ========== */

.dropzone {
  border: 1.5px dashed #b9c6d6;
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.dropzone.drag-over {
  background: var(--blue2);
  border-color: var(--blue);
  color: var(--blue);
}

.dropzone-icon {
  font-size: 30px;
  margin-bottom: 10px;
  color: var(--blue);
}

.dropzone-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.dropzone-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
}

.dropzone-actions { margin-top: 10px; }

.job-list { display: flex; flex-direction: column; gap: 10px; }

.job-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  background: #fff;
}

.job-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--blue2);
  color: var(--blue);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.job-info { min-width: 0; }
.job-name {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.job-progress {
  height: 6px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.job-progress i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--teal));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.job-state {
  font-size: 12px;
  color: var(--muted);
  min-width: 110px;
  text-align: right;
}

.job-state .pill { padding: 4px 9px; }

.job-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========== CONVERSATIONS VIEW ========== */

.conversations-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}

.conversations-list-panel { position: sticky; top: 20px; }
.conversations-list-panel .input { margin-bottom: 10px; width: 100%; min-width: 0; }

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 9px;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-soft);
  font-size: 13px;
  transition: background 0.15s;
}

.conv-item:hover { background: var(--line-soft); }
.conv-item.active {
  background: #eef2f7;
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
}

.conv-item-icon {
  width: 20px;
  height: 20px;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  font-size: 13px;
}

.conv-item .conv-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Detail --- */

.conversation-detail { min-width: 0; }

.empty-detail {
  padding: 60px 20px;
  text-align: center;
}

.meta-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.meta-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(21, 47, 76, 0.03);
}

.meta-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.meta-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Collected data */

.collected-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.collected-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  background: #fff;
}

.collected-card.wide { grid-column: span 2; }

.collected-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.collected-value {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.collected-value.big { font-size: 22px; font-weight: 700; }
.collected-value .muted { color: var(--muted); }

/* Summary */

.summary-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-soft);
  margin: 0;
}

/* Transcript */

.audio-player {
  width: 100%;
  margin-bottom: 14px;
  border-radius: 8px;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 6px;
}

.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.msg.agent {
  background: var(--agent-bubble);
  align-self: flex-start;
  border-top-left-radius: 4px;
}

.msg.customer {
  background: var(--customer-bubble);
  align-self: flex-end;
  border-top-right-radius: 4px;
}

.msg.unknown {
  background: #f8f8f8;
  align-self: flex-start;
  border: 1px dashed var(--line);
}

.msg .msg-time {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}

.toggle-pill {
  display: inline-block;
  width: 34px;
  height: 20px;
  background: var(--line-soft);
  border-radius: 999px;
  position: relative;
  border: 1px solid var(--line);
}

.toggle-pill span {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  transition: left 0.2s;
}

.toggle-pill.active { background: var(--blue); border-color: var(--blue); }
.toggle-pill.active span { left: 16px; border-color: var(--blue); }

/* ========== RESPONSIVE ========== */

@media (max-width: 1100px) {
  .conversations-grid { grid-template-columns: 260px 1fr; }
  .meta-cards { grid-template-columns: repeat(2, 1fr); }
  .collected-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .sidebar { position: static; width: 100%; height: auto; }
  .app-shell { display: block; }
  .main { margin-left: 0; width: 100%; padding: 18px; }
  .conversations-grid { grid-template-columns: 1fr; }
  .conversations-list-panel { position: static; }
  .meta-cards, .collected-grid { grid-template-columns: 1fr; }
}
