/* ===== CSS Custom Properties ===== */
:root {
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --secondary: #EC4899;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --danger-hover: #DC2626;

  --bg-start: #0F172A;
  --bg-end: #1E293B;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-hover: rgba(255, 255, 255, 0.1);

  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-muted: #64748B;

  --radius: 16px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo-accent {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background var(--transition);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.disconnected {
  background: var(--danger);
}

.user-badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 20px;
  color: var(--primary);
  font-family: monospace;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Main Layout ===== */
.main-layout {
  display: grid;
  grid-template-columns: 30% 40% 30%;
  gap: 0;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.panel {
  padding: 20px;
  overflow-y: auto;
  border-right: 1px solid var(--card-border);
}

.panel:last-child {
  border-right: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header h2,
.panel-header h3 {
  margin-bottom: 0;
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: border-color var(--transition);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type="tel"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
}

select {
  cursor: pointer;
  resize: none;
}

select option,
select optgroup {
  background: var(--bg-end);
  color: var(--text-primary);
}

input[type="tel"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.help-text {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Toggle Switch ===== */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: white;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--primary);
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.75rem;
  border-radius: var(--radius-xs);
  gap: 4px;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-xs);
  transition: all var(--transition);
  display: flex;
  align-items: center;
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--card-hover);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.tab.active {
  background: var(--primary);
  color: white;
}

.tab:hover:not(.active) {
  color: var(--text-secondary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--card-border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  transition: all var(--transition);
  cursor: pointer;
  color: var(--text-muted);
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.05);
  color: var(--text-secondary);
}

.drop-zone svg {
  margin-bottom: 8px;
  opacity: 0.5;
}

.drop-zone p {
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.drop-zone small {
  font-size: 0.75rem;
}

.drop-zone .link {
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
}

/* ===== Number Preview ===== */
.number-preview {
  margin-top: 12px;
  padding: 12px;
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-sm);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--success);
}

.preview-list {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: monospace;
  line-height: 1.8;
}

/* ===== Campaign Controls ===== */
.campaign-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

/* ===== Progress ===== */
.progress-bar-container {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 4px;
  transition: width 0.4s ease;
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===== Activity Log ===== */
.log-container {
  height: calc(100vh - 160px);
  overflow-y: auto;
  padding-right: 4px;
}

.log-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 40px 20px;
}

.log-entry {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  transition: background var(--transition);
  animation: slideIn 0.2s ease;
}

.log-entry:hover {
  background: var(--card-hover);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 52px;
  padding-top: 2px;
  font-family: monospace;
}

.log-body {
  flex: 1;
  min-width: 0;
}

.log-phone {
  font-size: 0.82rem;
  font-weight: 600;
  font-family: monospace;
  margin-bottom: 2px;
}

.log-message {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* --- Status Badges --- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-initiated   { background: rgba(59,130,246,0.15); color: #60A5FA; }
.badge-ringing     { background: rgba(245,158,11,0.15); color: #FBBF24; animation: pulse 1.5s infinite; }
.badge-answered    { background: rgba(16,185,129,0.15); color: #34D399; }
.badge-amd         { background: rgba(139,92,246,0.15); color: #A78BFA; }
.badge-dtmf        { background: rgba(249,115,22,0.15); color: #FB923C; }
.badge-bridged     { background: rgba(99,102,241,0.15); color: #818CF8; }
.badge-completed   { background: rgba(100,116,139,0.15); color: #94A3B8; }
.badge-error       { background: rgba(239,68,68,0.15); color: #F87171; }
.badge-transfer    { background: rgba(99,102,241,0.15); color: #818CF8; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* ===== Current Call Card ===== */
.current-call-card {
  border-color: rgba(99, 102, 241, 0.3);
  background: rgba(99, 102, 241, 0.06);
}

.current-call-number {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: monospace;
  text-align: center;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.current-call-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  font-weight: 500;
}

.state-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}

.state-indicator.ringing {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.state-indicator.answered,
.state-indicator.active {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.state-indicator.completed {
  background: var(--text-muted);
}

.call-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-item {
  text-align: center;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-xs);
}

.detail-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-value {
  font-size: 0.95rem;
  font-weight: 600;
  font-family: monospace;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.stat-card {
  text-align: center;
  padding: 14px 8px;
  border-radius: var(--radius-sm);
  transition: transform var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: monospace;
}

.stat-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

.stat-blue   { background: rgba(59,130,246,0.1); color: #60A5FA; }
.stat-blue   .stat-label { color: rgba(96,165,250,0.7); }
.stat-green  { background: rgba(16,185,129,0.1); color: #34D399; }
.stat-green  .stat-label { color: rgba(52,211,153,0.7); }
.stat-indigo { background: rgba(99,102,241,0.1); color: #818CF8; }
.stat-indigo .stat-label { color: rgba(129,140,248,0.7); }
.stat-red    { background: rgba(239,68,68,0.1); color: #F87171; }
.stat-red    .stat-label { color: rgba(248,113,113,0.7); }
.stat-amber  { background: rgba(245,158,11,0.1); color: #FBBF24; }
.stat-amber  .stat-label { color: rgba(251,191,36,0.7); }
.stat-slate  { background: rgba(100,116,139,0.1); color: #94A3B8; }
.stat-slate  .stat-label { color: rgba(148,163,184,0.7); }

/* ===== History List ===== */
.history-list {
  max-height: 250px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  margin-bottom: 4px;
  font-size: 0.82rem;
  transition: background var(--transition);
  cursor: pointer;
}

.history-item:hover {
  background: var(--card-hover);
}

.history-status {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
}

.history-status.completed { background: rgba(16,185,129,0.15); color: #34D399; }
.history-status.stopped   { background: rgba(239,68,68,0.15); color: #F87171; }
.history-status.active    { background: rgba(59,130,246,0.15); color: #60A5FA; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 360px;
}

.toast-success { background: rgba(16,185,129,0.9); color: white; }
.toast-error   { background: rgba(239,68,68,0.9); color: white; }
.toast-info    { background: rgba(99,102,241,0.9); color: white; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(-10px); }
}

/* ===== Confirm Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: var(--bg-end);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow);
}

.modal p {
  margin-bottom: 20px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: calc(100vh - 60px);
  }

  .panel-left {
    grid-column: 1 / -1;
    max-height: 300px;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
  }

  .log-container {
    height: 240px;
  }
}

@media (max-width: 768px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--card-border);
  }

  .panel-left {
    order: 3;
    max-height: 400px;
  }

  .panel-center {
    order: 2;
  }

  .panel-right {
    order: 1;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .campaign-buttons {
    grid-template-columns: 1fr;
  }

  .header {
    padding: 12px 16px;
  }

  .logo {
    font-size: 1.1rem;
  }
}

/* ===== IVR Key Rows ===== */
.ivr-key-row {
  display: grid;
  grid-template-columns: 65px 150px 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--surface-2, #1e2030);
  border: 1px solid var(--border, #2a2d3e);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.ivr-key-row select,
.ivr-key-row input {
  width: 100%;
}

.ivr-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted, #6b7280);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  font-size: 18px;
  transition: color 0.15s;
  align-self: center;
}

.ivr-remove-btn:hover {
  color: var(--danger, #ef4444);
}
