:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel-hi: #1a2540;
  --text: #e8edf7;
  --muted: #8a93a6;
  --accent: #22c55e;
  --accent-hi: #16a34a;
  --danger: #ef4444;
  --border: #1f2a44;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.dialer {
  max-width: 380px;
  margin: 0 auto;
  /* Respect iOS notch/home-indicator when launched as a standalone PWA. */
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(20px + env(safe-area-inset-right))
    calc(40px + env(safe-area-inset-bottom))
    calc(20px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
}

/* Header — 3-col grid: hamburger | centered logo | spacer (same width as hamburger) */
.dialer-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
}
.dialer-header .logo {
  justify-self: center;
  max-width: 180px;
  width: 100%;
  height: auto;
  display: block;
}
.header-spacer { width: 44px; height: 44px; }
.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.icon-btn:hover  { background: var(--panel-hi); color: var(--text); border-color: var(--border); }
.icon-btn:active { transform: scale(0.96); }

/* Toggled views (dialer vs history) inside the same dialer container */
.view {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.view[hidden] { display: none; }
.view-title {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}

/* === Slide-out menu drawer === */
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.menu-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.menu-backdrop[hidden] { display: none; }

.menu-drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: calc(20px + env(safe-area-inset-top)) 12px 20px;
  transform: translateX(-100%);
  transition: transform 200ms ease;
  box-shadow: 8px 0 24px rgba(0,0,0,0.4);
}
.menu-drawer.open      { transform: translateX(0); }
.menu-drawer[hidden]   { display: none; }

.menu-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 12px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.menu-title {
  font-size: 13px;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-transform: uppercase;
}
.menu-user {
  font-size: 14px;
  color: var(--text);
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 14px;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  transition: background 100ms ease;
}
.menu-item:hover  { background: var(--panel-hi); }
.menu-item.active { background: var(--panel-hi); color: var(--accent); }
.menu-logout {
  margin-top: auto;
  color: var(--danger);
}
.menu-logout:hover { background: rgba(239, 68, 68, 0.08); }

/* Cell selector — dropdown above the keypad */
.cell-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.cell-selector label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.cell-selector select {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 18px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%238a93a6' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right center;
}
.cell-selector select option {
  background: var(--panel);
  color: var(--text);
}
/* When the user has only one cell, the select is disabled and styled as a
   read-only label — no chevron, no pointer cursor. */
.cell-selector select.static {
  background-image: none;
  padding-right: 0;
  cursor: default;
  opacity: 1;
  color: var(--text);
}

.display input {
  width: 100%;
  padding: 16px 18px;
  font-size: 26px;
  letter-spacing: 1px;
  text-align: center;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 120ms ease;
}
.display input:focus {
  border-color: var(--accent);
}
/* Make the placeholder a soft hint; typed digits use the full --text color */
.display input::placeholder {
  color: var(--muted);
  opacity: 0.2;
  font-weight: 400;
  letter-spacing: normal;
}
.display input::-webkit-input-placeholder {
  color: var(--muted);
  opacity: 0.2;
}
.display input::-moz-placeholder {
  color: var(--muted);
  opacity: 0.2;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.keypad button {
  padding: 18px 0;
  font-size: 22px;
  font-weight: 500;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 100ms ease, transform 80ms ease;
}
.keypad button:hover  { background: var(--panel-hi); }
.keypad button:active { transform: scale(0.97); }

.actions {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 10px;
  align-items: stretch;
}
.actions button {
  padding: 16px 12px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
}
.actions .ghost {
  background: var(--panel);
  color: var(--muted);
}
.actions .ghost:hover {
  background: var(--panel-hi);
  color: var(--text);
}
.actions .primary {
  background: var(--accent);
  color: #062611;
  border-color: var(--accent-hi);
  letter-spacing: 0.4px;
}
.actions .primary:hover  { background: var(--accent-hi); color: #fff; }
.actions .primary:disabled,
.actions .primary[aria-busy="true"] {
  opacity: 0.7;
  cursor: progress;
}

/* Cancel state — same button, red, for terminating an in-flight call */
.actions .danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  letter-spacing: 0.4px;
}
.actions .danger:hover    { background: #c91f1f; }
.actions .danger:disabled { opacity: 0.7; cursor: progress; }

.status {
  margin: 0;
  min-height: 22px;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}
.status.ok    { color: var(--accent); }
.status.err   { color: var(--danger); }

/* Twilio spend footer */
.spend {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.spend.err { color: var(--danger); }
.spend .separator { opacity: 0.4; }

/* === Call history view === */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 30px 0;
}
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease;
}
.history-item:hover { background: var(--panel-hi); border-color: var(--accent); }
.history-customer {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.4px;
}
.history-meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.history-meta .sep { opacity: 0.4; }
.history-status-completed { color: var(--accent); }
.history-status-failed,
.history-status-busy,
.history-status-no-answer,
.history-status-canceled { color: var(--danger); }
.history-redial-hint {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.history-refresh {
  align-self: center;
  padding: 10px 16px;
  font-size: 14px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.history-refresh:hover { color: var(--text); background: var(--panel-hi); }

/* Login page — same dialer chrome, single form in the middle */
.login-view {
  justify-content: center;
}
.login-view form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-view .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-view .field span {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.login-view .field input {
  padding: 14px 16px;
  font-size: 16px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 120ms ease;
}
.login-view .field input:focus { border-color: var(--accent); }
.login-view button.primary {
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  background: var(--accent);
  color: #062611;
  border: 1px solid var(--accent-hi);
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.4px;
}
.login-view button.primary:hover { background: var(--accent-hi); color: #fff; }
.login-view button.primary:disabled { opacity: 0.7; cursor: progress; }

/* Cloudflare Turnstile widget — adapted from the SwiftPort marketing site's
   .turnstile-card (light theme) for our dark UI. The Turnstile iframe inside
   sizes itself; we just provide the framing card. min-height matches the
   widget's default flexible size so the form doesn't jump as the widget loads. */
.turnstile-card {
  min-height: 65px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

/* === QR-code popup modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}
.modal-tab {
  flex: 1;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}
.modal-tab:hover  { color: var(--text); }
.modal-tab.active { background: var(--panel-hi); color: var(--text); }
.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  color: var(--text);
}
.qr-render {
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-height: 200px;
}
.qr-render img,
.qr-render svg {
  max-width: 100%;
  height: auto;
  display: block;
  /* Pixel art: no blurry interpolation */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
}
.qr-url {
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--muted);
  word-break: break-all;
  user-select: all;
}
.modal-hint {
  margin: 0;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
  opacity: 0.7;
}
