/* ============================================
   Twilio Dashboard — Design System
   Palette: Twilio Red, Dark Navy, Clean Whites
   ============================================ */

:root {
  --red: #F22F46;
  --red-dark: #D42840;
  --red-light: #FDEAEC;
  --navy: #121C2D;
  --navy-mid: #1E2D45;
  --navy-light: #263548;
  --blue: #0263E0;
  --blue-light: #E8F0FD;
  --green: #07A950;
  --green-light: #E6F7EE;
  --yellow: #F7C948;
  --yellow-light: #FEF9E7;
  --orange: #E97118;
  --white: #FFFFFF;
  --gray-50: #F8F9FA;
  --gray-100: #F1F3F4;
  --gray-200: #E2E5E9;
  --gray-300: #C8CDD5;
  --gray-400: #9BA5B4;
  --gray-500: #6B7585;
  --gray-600: #4A5568;
  --gray-700: #2D3748;
  --gray-900: #121C2D;
  --text-primary: #121C2D;
  --text-secondary: #4A5568;
  --text-muted: #6B7585;
  --border: #E2E5E9;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 220px;
  --header-h: 56px;
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'Roboto Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--gray-50);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── SIDEBAR ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: white;
  letter-spacing: -.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 20px;
  background: none;
  border: none;
  color: rgba(255,255,255,.6);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
  position: relative;
}
.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.nav-item:hover {
  color: white;
  background: rgba(255,255,255,.06);
}
.nav-item.active {
  color: white;
  background: rgba(242,47,70,.15);
  border-right: 3px solid var(--red);
}
.nav-item .badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.account-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-500);
  flex-shrink: 0;
}
.status-dot.connected { background: var(--green); }
.status-dot.error { background: var(--red); }
.account-sid {
  font-size: 11px;
  font-family: var(--mono);
  color: rgba(255,255,255,.4);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── MAIN CONTENT ────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.view {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.view.active {
  display: flex;
}

/* ─── PAGE HEADER ─────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}
.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.page-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 1px;
}
.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ─── BUTTONS ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--red); color: white; }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: white; color: var(--text-primary); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--gray-400); background: var(--gray-50); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover { background: var(--red); color: white; }
.btn-success { background: var(--green-light); color: var(--green); }
.btn-success:hover { background: var(--green); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── CARDS ───────────────────────────────── */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.card-body { padding: 20px; }

/* ─── SCROLL AREA ─────────────────────────── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}
.scroll-area::-webkit-scrollbar { width: 5px; }
.scroll-area::-webkit-scrollbar-track { background: transparent; }
.scroll-area::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }

/* ─── TABLE ───────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-50);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13.5px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

/* ─── FORM CONTROLS ───────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--text-primary);
  background: white;
  transition: border-color .15s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(2,99,224,.1);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── TOGGLE ──────────────────────────────── */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input { display: none; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 11px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform .2s;
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--red); }
.toggle input:checked + .toggle-slider::after { transform: translateX(18px); }
.toggle-label { font-size: 13.5px; font-weight: 500; color: var(--text-primary); }

/* ─── BADGE / PILL ────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 600;
}
.pill-green { background: var(--green-light); color: var(--green); }
.pill-red { background: var(--red-light); color: var(--red); }
.pill-blue { background: var(--blue-light); color: var(--blue); }
.pill-gray { background: var(--gray-100); color: var(--gray-600); }
.pill-yellow { background: var(--yellow-light); color: #a16207; }

/* ─── PHONE NUMBER DISPLAY ────────────────── */
.phone-mono {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .3px;
}

/* ─── EMPTY STATE ─────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}
.empty-state svg {
  width: 48px;
  height: 48px;
  opacity: .3;
}
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text-secondary); }
.empty-state p { font-size: 13px; max-width: 280px; }

/* ─── SEARCH BAR ──────────────────────────── */
.search-bar {
  position: relative;
  flex: 1;
  max-width: 280px;
}
.search-bar svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--gray-400);
  pointer-events: none;
}
.search-bar input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.search-bar input:focus { border-color: var(--blue); }

/* ─── MODAL ───────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18,28,45,.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { transform: scale(.95) translateY(-8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; padding: 4px; border-radius: var(--radius-sm); color: var(--gray-500); }
.modal-close:hover { background: var(--gray-100); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ─── TOAST ───────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
  max-width: 340px;
}
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-success { background: white; border-left: 4px solid var(--green); color: var(--text-primary); }
.toast-error { background: white; border-left: 4px solid var(--red); color: var(--text-primary); }
.toast-info { background: white; border-left: 4px solid var(--blue); color: var(--text-primary); }

/* ─── DIAL PAD ────────────────────────────── */
.dialpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 240px;
  margin: 0 auto;
}
.dialpad-btn {
  aspect-ratio: 1;
  background: var(--gray-50);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all .1s;
  user-select: none;
}
.dialpad-btn:hover { background: var(--gray-100); border-color: var(--gray-300); }
.dialpad-btn:active { background: var(--gray-200); transform: scale(.96); }
.dialpad-btn .digit {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
}
.dialpad-btn .sub {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-top: 2px;
}
.dialpad-btn.red { background: var(--red); border-color: var(--red); }
.dialpad-btn.red .digit { color: white; }
.dialpad-btn.red:hover { background: var(--red-dark); }
.dialpad-btn.green { background: var(--green); border-color: var(--green); }
.dialpad-btn.green .digit { color: white; }

/* ─── CALL STATE BAR ──────────────────────── */
.call-bar {
  background: var(--navy);
  color: white;
  padding: 14px 20px;
  display: none;
  align-items: center;
  gap: 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.call-bar.active { display: flex; }
.call-timer {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  flex: 1;
}
.call-info { font-size: 13px; color: rgba(255,255,255,.7); }
.call-controls { display: flex; gap: 8px; }
.call-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.call-btn svg { width: 17px; height: 17px; }
.call-btn.mute { background: rgba(255,255,255,.15); color: white; }
.call-btn.mute:hover, .call-btn.mute.active { background: var(--yellow); color: var(--navy); }
.call-btn.hold { background: rgba(255,255,255,.15); color: white; }
.call-btn.hold:hover, .call-btn.hold.active { background: var(--blue); color: white; }
.call-btn.hangup { background: var(--red); color: white; }
.call-btn.hangup:hover { background: var(--red-dark); }

/* ─── MESSAGES LAYOUT ─────────────────────── */
.msg-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.thread-list {
  width: 280px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  background: white;
}
.thread-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.thread-item:hover { background: var(--gray-50); }
.thread-item.active { background: var(--blue-light); }
.thread-name { font-weight: 600; font-size: 13.5px; }
.thread-preview { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.thread-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.thread-time { font-size: 11.5px; color: var(--text-muted); }
.thread-unread { background: var(--blue); color: white; font-size: 10.5px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; display: flex; align-items: center; justify-content: center; }
.msg-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.msg-pane-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}
.msg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg-bubble {
  max-width: 68%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
}
.msg-bubble.out {
  background: var(--blue);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg-bubble.in {
  background: var(--gray-100);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg-time { font-size: 11px; opacity: .6; margin-top: 4px; text-align: right; }
.msg-compose {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: white;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
.msg-compose textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}
.msg-compose textarea:focus { border-color: var(--blue); }

/* ─── SCREENER FLOW DIAGRAM ───────────────── */
.flow-diagram {
  background: var(--gray-50);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow-x: auto;
  min-height: 160px;
}

/* ─── VOICEMAIL PLAYER ────────────────────── */
.vm-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.vm-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.vm-meta h4 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.vm-meta span { font-size: 12.5px; color: var(--text-muted); }
.vm-transcript {
  background: var(--gray-50);
  border-left: 3px solid var(--blue);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
  font-style: italic;
}
audio { width: 100%; height: 36px; margin-top: 10px; }

/* ─── FORWARDING ──────────────────────────── */
.fwd-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  margin-bottom: 10px;
}
.fwd-row:hover { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(2,99,224,.05); }
.fwd-number { flex: 1; }
.fwd-number .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.fwd-number .num { font-family: var(--mono); font-size: 13.5px; font-weight: 500; margin-top: 1px; }
.fwd-arrow { color: var(--gray-400); }
.fwd-input { width: 180px; }

/* ─── CONTACTS TABLE ACTION ───────────────── */
.contact-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.contact-avatar.blocked { background: var(--red-light); color: var(--red); }

/* ─── SCREENER RADIO GROUP ────────────────── */
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
}
.radio-option:hover { border-color: var(--blue); background: var(--blue-light); }
.radio-option.selected { border-color: var(--blue); background: var(--blue-light); }
.radio-option input[type=radio] { accent-color: var(--blue); }
.radio-option .radio-label { font-size: 13.5px; font-weight: 500; }
.radio-option .radio-desc { font-size: 12px; color: var(--text-muted); }

/* ─── GRID LAYOUT ─────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ─── LOADING SPINNER ─────────────────────── */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── DIALER LAYOUT ───────────────────────── */
.dialer-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  height: 100%;
  overflow: hidden;
}
.dialer-left {
  overflow-y: auto;
  padding: 24px 0 24px 28px;
}
.dialer-right {
  overflow-y: auto;
  padding: 24px 28px 24px 0;
}
.dialpad-display {
  text-align: center;
  margin-bottom: 16px;
}
.dialpad-input {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 500;
  color: var(--text-primary);
  border: none;
  border-bottom: 2px solid var(--border);
  text-align: center;
  width: 100%;
  padding: 8px;
  background: transparent;
  outline: none;
  letter-spacing: 2px;
}
.from-selector {
  margin-bottom: 20px;
}
.from-selector label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); margin-bottom: 6px; }

/* ─── INFO STRIP ──────────────────────────── */
.info-strip {
  background: var(--blue-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--blue);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.info-strip svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 1px; }
