@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #FFFFFF;
  --surface: #F3F7FF;
  --surface-2: #EAF0FF;
  --border: #E3E8F5;
  --ink: #10182B;
  --muted: #5B6479;
  --primary: #2454FF;
  --primary-dark: #14328C;
  --primary-tint: #E7EDFF;
  --success: #1FAE6B;
  --success-tint: #E4F7ED;
  --danger: #E5484D;
  --danger-tint: #FDEBEC;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 43, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 43, 0.08);
  --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------- Layout shell ---------- */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  padding: 4px 8px 22px;
}

.sidebar .brand img { height: 26px; }

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 14px;
}
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 8px 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-tint); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; flex: none;
}
.user-chip .who { line-height: 1.2; overflow: hidden; }
.user-chip .who .name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .who .role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.logout-btn {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  font-weight: 700; font-size: 13px;
}
.logout-btn:hover { color: var(--danger); border-color: var(--danger-tint); background: var(--danger-tint); }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 36px;
  overflow-y: auto;
}

.page-header { margin-bottom: 22px; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

/* ---------- Dialer ---------- */
.dialer-wrap {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.dialer-card {
  width: 320px;
  flex: none;
  text-align: center;
  padding: 26px 24px 30px;
}

.call-status {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px; height: 16px;
}
.call-status.connected { color: var(--success); }
.call-status.ringing { color: var(--primary); }

.number-display {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  min-height: 36px;
  margin-bottom: 18px;
  word-break: break-all;
  color: var(--ink);
}
.number-display:empty::before { content: 'Enter a number'; color: var(--muted); font-weight: 600; font-size: 16px; }

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

.key {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, transform 0.08s;
}
.key .sub { font-size: 9px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; margin-top: 1px; }
.key:hover { background: var(--surface-2); }
.key:active { transform: scale(0.94); background: var(--primary-tint); }

.dial-actions { display: flex; gap: 10px; align-items: center; justify-content: center; }

.call-btn, .hangup-btn {
  width: 62px; height: 62px; border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
}
.call-btn { background: var(--success); }
.call-btn:hover { background: #189259; }
.call-btn:disabled { background: #B7BFCF; cursor: not-allowed; }
.hangup-btn { background: var(--danger); }
.hangup-btn:hover { background: #C93337; }
.backspace-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.backspace-btn:hover { background: var(--surface); }

.dialer-hint {
  margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.5;
}

.setup-warning {
  background: var(--danger-tint); color: #8A1F22; border: 1px solid #F4C7C9;
  border-radius: var(--radius-md); padding: 12px 14px; font-size: 13px; margin-bottom: 18px;
}

/* ---------- Tables (recent calls / sms) ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 700; padding: 0 12px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.completed, .badge.delivered, .badge.sent, .badge.received { background: var(--success-tint); color: #17784E; }
.badge.busy, .badge.failed, .badge.no-answer, .badge.undelivered { background: var(--danger-tint); color: #B4373A; }
.badge.queued, .badge.ringing, .badge.in-progress { background: var(--primary-tint); color: var(--primary-dark); }
.badge.outbound { background: var(--surface-2); color: var(--muted); }
.badge.inbound { background: #FFF3DE; color: #8A5A00; }

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

/* ---------- SMS composer ---------- */
.sms-layout { display: flex; gap: 24px; flex-wrap: wrap; }
.sms-compose { width: 340px; flex: none; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; color: var(--ink); background: #fff;
}
.field textarea { resize: vertical; min-height: 90px; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--primary-tint); border-color: var(--primary); }
.char-count { font-size: 11px; color: var(--muted); text-align: right; margin-top: 4px; }

.btn-primary {
  padding: 11px 18px; border-radius: var(--radius-sm); border: none;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 14px;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #B7BFCF; cursor: not-allowed; }

.btn-secondary {
  padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: #fff; color: var(--ink); font-weight: 700; font-size: 13px;
}
.btn-secondary:hover { background: var(--surface); }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff;
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-md); opacity: 0; transform: translateY(8px); transition: all 0.2s;
  pointer-events: none; max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- Login page ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--surface);
}
.login-card {
  width: 380px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); padding: 34px 30px;
}
.login-card .brand { display: flex; justify-content: center; margin-bottom: 26px; }
.login-card h1 { font-size: 18px; font-weight: 800; margin: 0 0 4px; text-align: center; }
.login-card p.sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.login-error {
  background: var(--danger-tint); color: #8A1F22; border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; margin-bottom: 16px; display: none;
}

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab-btn {
  padding: 10px 16px; border: none; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.row-actions { display: flex; gap: 8px; }
.row-actions button { padding: 6px 10px; font-size: 12px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 43, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  width: 420px; background: #fff; border-radius: var(--radius-lg); padding: 24px;
  box-shadow: var(--shadow-md);
}
.modal h2 { margin: 0 0 18px; font-size: 17px; font-weight: 800; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 640px; }
.settings-grid .field.full { grid-column: 1 / -1; }
.help-text { font-size: 12px; color: var(--muted); margin-top: 2px; }

.temp-password-box {
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; margin-top: 12px; font-family: monospace;
}

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; }
  .nav { flex-direction: row; overflow-x: auto; }
  .sidebar-footer { display: none; }
  .main { padding: 20px; }
}
