/* —— Agent Studio theme (gradient xanh) —— */
:root {
  --studio-gradient: linear-gradient(135deg, #1e3a5f 0%, #2d6a9f 48%, #3d8fd6 100%);
  --studio-gradient-sidebar: linear-gradient(180deg, #1a3352 0%, #234a73 55%, #2d6a9f 100%);
  --studio-bg: #eef2f7;
  --studio-surface: #ffffff;
  --studio-border: #e2e8f0;
  --studio-primary: #2d6a9f;
  --studio-primary-hover: #1e3a5f;
  --studio-accent: #3d8fd6;
  --studio-radius: 14px;
  --studio-radius-lg: 16px;
  --bs-primary: #2d6a9f;
  --bs-primary-rgb: 45, 106, 159;
}

body.studio-body {
  background: var(--studio-bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.btn-primary {
  --bs-btn-bg: var(--studio-primary);
  --bs-btn-border-color: var(--studio-primary);
  --bs-btn-hover-bg: var(--studio-primary-hover);
  --bs-btn-hover-border-color: var(--studio-primary-hover);
}

.studio-shell {
  background: var(--studio-bg);
}

.studio-sidebar {
  width: 248px;
  min-width: 248px;
  background: var(--studio-gradient-sidebar);
  box-shadow: 2px 0 12px rgba(30, 58, 95, 0.12);
}

.studio-sidebar .nav-link {
  color: rgba(255, 255, 255, 0.88);
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.15rem;
  border-radius: 10px;
  transition: background 0.15s;
}

.studio-sidebar .nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.studio-sidebar .nav-link.active {
  font-weight: 600;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.studio-hero,
.zns-hero {
  background: var(--studio-gradient);
  flex-shrink: 0;
}

.studio-hero-sub,
.zns-hero-sub {
  color: rgba(255, 255, 255, 0.88);
  max-width: 40rem;
}

.studio-hero-sub a,
.zns-hero-link {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.studio-btn-pill {
  border-radius: 999px !important;
  padding-left: 1rem !important;
  padding-right: 1rem !important;
  font-weight: 500;
}

.studio-btn-light {
  background: #fff;
  border: none;
  color: #1e3a5f;
}

.studio-btn-light:hover {
  background: #f8fafc;
  color: #1e3a5f;
}

.studio-btn-outline-light {
  border: 1px solid rgba(255, 255, 255, 0.65);
  color: #fff;
  background: transparent;
}

.studio-btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: #fff;
}

.studio-badge-hero {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-weight: 500;
}

.studio-content {
  padding: 1.25rem 1.5rem 1.5rem;
}

.studio-card {
  border: none;
  border-radius: var(--studio-radius-lg);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.studio-card .card-header {
  background: var(--studio-surface);
  border-bottom: 1px solid var(--studio-border);
  border-radius: var(--studio-radius-lg) var(--studio-radius-lg) 0 0 !important;
  font-weight: 600;
}

.studio-card-accent {
  border: 1px solid rgba(61, 143, 214, 0.35) !important;
  box-shadow: 0 4px 14px rgba(45, 106, 159, 0.08);
}

.pron-dict-help code {
  font-size: 0.85em;
  color: var(--studio-primary, #2d6a9f);
}

.pron-dict-head {
  padding-left: 0.25rem;
}

.studio-sticky-footer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--studio-border);
}

.studio-login-page {
  min-height: 100vh;
  background: var(--studio-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.studio-login-card {
  width: 100%;
  max-width: 420px;
  border: none;
  border-radius: var(--studio-radius-lg);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.studio-login-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #2d6a9f, #3d8fd6);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.form-control,
.form-select {
  border-radius: 10px;
  border-color: var(--studio-border);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--studio-accent);
  box-shadow: 0 0 0 0.2rem rgba(61, 143, 214, 0.2);
}

.voice-call-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 7.5rem;
}

.voice-call-btn {
  position: relative;
  z-index: 2;
  background: var(--studio-gradient);
  border: none;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
}

.voice-call-btn:hover,
.voice-call-btn:focus {
  background: linear-gradient(135deg, #1e3a5f 0%, #2d6a9f 100%);
  border: none;
  filter: brightness(1.05);
}

.voice-call-stage.is-active .voice-call-btn {
  background: linear-gradient(135deg, #c0392b 0%, #e74c3c 100%);
}

.voice-ripple {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4.5rem;
  height: 4.5rem;
  margin-left: -2.25rem;
  margin-top: -2.25rem;
  border-radius: 50%;
  border: 2px solid rgba(45, 106, 159, 0.45);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.voice-call-stage.is-active .voice-ripple {
  animation: voice-ripple-pulse 2.4s ease-out infinite;
}

.voice-call-stage.is-active .voice-ripple-2 {
  animation-delay: 0.8s;
}

.voice-call-stage.is-active .voice-ripple-3 {
  animation-delay: 1.6s;
}

@keyframes voice-ripple-pulse {
  0% {
    transform: scale(1);
    opacity: 0.55;
  }
  100% {
    transform: scale(2.35);
    opacity: 0;
  }
}

.voice-transcript {
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.voice-transcript--inline {
  min-height: 9rem;
  max-height: min(22rem, 48vh);
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.voice-transcript-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 7rem;
  text-align: center;
  color: #94a3b8;
  line-height: 1.45;
  padding: 0.25rem 0.35rem;
  font-size: 0.75rem;
}

.voice-transcript-turn {
  display: flex;
  margin-bottom: 0.5rem;
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.voice-transcript-turn--visible {
  opacity: 1;
  transform: translateY(0);
}

.voice-transcript-turn--bot {
  justify-content: flex-start;
}

.voice-transcript-turn--user {
  justify-content: flex-end;
}

.voice-transcript-turn--system {
  justify-content: center;
}

.voice-transcript-bubble {
  max-width: 100%;
  min-width: 0;
  padding: 0.5rem 0.65rem 0.55rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.voice-transcript-turn--bot .voice-transcript-bubble {
  background: linear-gradient(135deg, #ffffff 0%, #f8fbff 100%);
}

.voice-transcript-turn--user .voice-transcript-bubble {
  background: linear-gradient(135deg, #fafbfc 0%, #f4f6f8 100%);
}

.voice-transcript-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.voice-transcript-turn--user .voice-transcript-meta {
  flex-direction: row-reverse;
}

.voice-transcript-avatar {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
}

.voice-transcript-avatar--agent {
  color: #fff;
  background: linear-gradient(145deg, #2d6a9f, #3d8fd6);
  box-shadow: 0 1px 4px rgba(45, 106, 159, 0.35);
}

.voice-transcript-avatar--user {
  color: #475569;
  background: #e2e8f0;
}

.voice-transcript-avatar--system {
  color: #64748b;
  background: #f1f5f9;
  font-size: 0.65rem;
}

.voice-transcript-turn--system .voice-transcript-bubble {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0.2rem 0.35rem;
  text-align: center;
}

.voice-transcript-live .voice-transcript-bubble {
  box-shadow: 0 2px 10px rgba(45, 106, 159, 0.1);
}

.voice-transcript-role {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #64748b;
}

.voice-transcript-turn--bot .voice-transcript-role {
  color: #2d6a9f;
}

.voice-transcript-turn--user .voice-transcript-role {
  color: #64748b;
}

.voice-transcript-text {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.52;
  color: #334155;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: color 0.2s ease;
}

.voice-transcript-live .voice-transcript-text {
  color: #1e3a5f;
}

.voice-transcript-turn--user .voice-transcript-text {
  color: #475569;
}

.voice-transcript-turn--system .voice-transcript-text {
  font-size: 0.7rem;
  color: #94a3b8;
}

.voice-transcript-live .voice-transcript-text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.85em;
  margin-left: 2px;
  vertical-align: -0.08em;
  background: var(--studio-accent, #3d8fd6);
  opacity: 0.65;
  animation: voice-caret-blink 1s step-end infinite;
}

.voice-transcript-turn:not(.voice-transcript-live) .voice-transcript-text::after {
  display: none;
}

@keyframes voice-caret-blink {
  50% {
    opacity: 0;
  }
}

.voice-transcript-fade-out {
  animation: voice-transcript-out 0.4s ease forwards;
}

@keyframes voice-transcript-out {
  to {
    opacity: 0;
    max-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
}

.font-monospace {
  font-size: 0.85rem;
}

/* —— Lịch sử cuộc gọi —— */
.call-history-page,
.zns-page {
  background: var(--studio-bg);
}

.call-history-list-panel {
  width: 400px;
  min-width: 340px;
  max-width: 42%;
  background: var(--studio-surface);
  border-right: 1px solid var(--studio-border);
}

.call-history-search {
  border-radius: 999px;
  padding-left: 2.25rem;
  font-size: 0.875rem;
}

.call-history-search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  pointer-events: none;
}

.call-history-agent-toggle {
  border: 1px solid var(--studio-accent);
  border-radius: 999px;
  overflow: hidden;
  padding: 2px;
}

.call-history-agent-toggle .btn {
  border: none;
  border-radius: 999px !important;
  color: var(--studio-primary);
  font-weight: 500;
  flex: 1;
}

.call-history-agent-toggle .btn.active {
  box-shadow: inset 0 0 0 1px var(--studio-accent);
  color: var(--studio-primary);
}

.call-history-select {
  border-radius: 12px;
  font-size: 0.875rem;
}

.call-history-cards {
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}

.call-history-card {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-radius);
  background: #fff;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.call-history-card:hover {
  border-color: #93c5fd;
}

.call-history-card.is-selected {
  border-color: var(--studio-accent);
  box-shadow: 0 0 0 1px var(--studio-accent);
}

.call-card-time {
  font-size: 0.8rem;
  color: #64748b;
}

.call-card-duration {
  font-size: 0.8rem;
  font-weight: 600;
}

.call-badge-end {
  background: #f1f5f9;
  color: #475569;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 6px;
}

.call-badge-transfer {
  background: var(--studio-accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 6px;
}

.call-badge-error {
  background: #dc3545;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 6px;
}

.call-card-meta {
  font-size: 0.8rem;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.call-card-slug {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 0.35rem;
  font-family: ui-monospace, monospace;
}

.call-history-detail {
  background: #f8fafc;
}

.call-transcript-box {
  min-height: 12rem;
  max-height: min(28rem, 55vh);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.85rem 0.9rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  scroll-behavior: smooth;
}

.call-transcript-box .voice-transcript-turn {
  opacity: 1;
  transform: none;
}

.call-transcript-box .voice-transcript-turn--bot .voice-transcript-bubble {
  max-width: 92%;
}

.call-transcript-box .voice-transcript-turn--user .voice-transcript-bubble {
  max-width: 92%;
}

.call-recording-wrap {
  background: #fff;
  border: 1px solid var(--studio-border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem 0.75rem;
}

.call-recording-audio {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.call-waveform-toolbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.call-waveform-play {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.call-waveform-time {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: #64748b;
}

.call-waveform-stage {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}

.call-waveform-canvas {
  display: block;
  width: 100%;
  height: 56px;
  cursor: pointer;
}

.call-waveform-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.92);
  pointer-events: none;
}

.call-transcript-time {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--studio-primary, #2d6a9f);
  background: rgba(45, 106, 159, 0.08);
  border: none;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
}

.call-transcript-time:hover {
  background: rgba(45, 106, 159, 0.16);
}

.voice-transcript-turn.is-sync-active .voice-transcript-bubble {
  box-shadow: 0 0 0 2px rgba(61, 143, 214, 0.45);
}

/* —— Lịch sử ZNS —— */
.zns-status-card {
  border-radius: var(--studio-radius);
  padding: 1rem 1.15rem;
  border: 1px solid transparent;
}

.zns-status-ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.zns-status-warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.zns-status-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.zns-status-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.zns-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  pointer-events: none;
  font-size: 0.85rem;
}

.zns-search-input {
  padding-left: 2.1rem;
  border-radius: 10px;
}

.zns-filter-select {
  border-radius: 10px;
}

.zns-panel {
  border-radius: var(--studio-radius-lg) !important;
  min-height: 280px;
}

.zns-list-body {
  max-height: calc(100vh - 320px);
}

.zns-log-item {
  border: 1px solid var(--studio-border);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.5rem;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.zns-log-item:hover {
  border-color: #93c5fd;
}

.zns-log-item.is-active {
  border-color: var(--studio-accent);
  box-shadow: 0 0 0 1px var(--studio-accent);
}

.zns-log-time {
  font-size: 0.75rem;
  color: #64748b;
}

.zns-log-phone {
  font-weight: 600;
  font-size: 0.95rem;
}

.zns-log-meta {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.15rem;
}

.zns-empty-icon {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: #94a3b8;
}

.zns-code {
  background: #f8fafc;
  border: 1px solid var(--studio-border);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.75rem;
  max-height: 200px;
  overflow: auto;
}

/* —— Cấu hình cố vấn: thứ tự khối mobile vs desktop —— */
.agent-config-row {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.agent-config-main,
.agent-config-aside {
  display: contents;
}

.agent-order-customer-zns {
  order: 1;
}

.agent-order-call {
  order: 2;
}

.agent-order-advisor {
  order: 3;
}

.agent-order-greeting {
  order: 4;
}

.agent-order-pronunciation {
  order: 5;
}

.agent-order-voice {
  order: 6;
}

@media (min-width: 992px) {
  .agent-config-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
    gap: 1.5rem;
    align-items: start;
  }

  .agent-config-main,
  .agent-config-aside {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
  }

  .agent-config-main {
    grid-column: 1;
  }

  .agent-config-aside {
    grid-column: 2;
  }

  .agent-order-customer-zns,
  .agent-order-call,
  .agent-order-advisor,
  .agent-order-greeting,
  .agent-order-pronunciation,
  .agent-order-voice {
    order: unset;
  }
}

/* —— Responsive: menu thu gọn + bố cục mobile —— */
.studio-nav-toggle {
  display: none;
}

.studio-sidebar-backdrop {
  display: none;
}

body.studio-nav-locked {
  overflow: hidden;
}

@media (max-width: 991.98px) {
  .studio-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0.65rem;
    left: 0.65rem;
    z-index: 1050;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.95);
    color: #1e3a5f;
    box-shadow: 0 2px 12px rgba(30, 58, 95, 0.18);
  }

  .studio-nav-toggle:hover {
    background: #fff;
    color: var(--studio-primary);
  }

  .studio-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .studio-shell.studio-sidebar-open .studio-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .studio-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1045;
    width: min(280px, 88vw);
    min-width: 0;
    height: 100%;
    max-height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
  }

  .studio-shell.studio-sidebar-open .studio-sidebar {
    transform: translateX(0);
  }

  .studio-hero,
  .zns-hero {
    padding-left: 3.5rem !important;
  }

  .studio-content {
    padding: 1rem;
  }

  .call-history-split {
    flex-direction: column;
  }

  .call-history-list-panel {
    width: 100%;
    min-width: 0;
    max-width: none;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--studio-border);
    max-height: min(48vh, 420px);
  }

  .call-history-cards {
    max-height: min(32vh, 280px);
  }

  .call-history-detail {
    flex: 1 1 auto;
    min-height: 0;
  }

  .call-history-page .studio-hero .d-flex.gap-2 {
    width: 100%;
    justify-content: flex-start;
  }

  .zns-list-body {
    max-height: min(40vh, 360px);
  }

  .studio-sticky-footer {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
}

@media (max-width: 575.98px) {
  .studio-hero h1,
  .zns-hero h1 {
    font-size: 1.1rem;
  }

  .call-history-list-panel {
    max-height: none;
  }

  .call-history-cards {
    max-height: min(38vh, 240px);
  }
}
