:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --text: #14161a;
  --text-muted: #62666f;
  --border: #e4e6eb;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-contrast: #ffffff;
  --ok: #16794f;
  --ok-bg: #e7f7ef;
  --warn: #92620a;
  --warn-bg: #fdf3dd;
  --bad: #b0231c;
  --bad-bg: #fbe9e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px -12px rgba(16, 24, 40, 0.12);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f13;
    --surface: #16181d;
    --surface-2: #1c1f26;
    --text: #edeef1;
    --text-muted: #94979f;
    --border: #2a2d35;
    --accent: #818cf8;
    --accent-2: #a5b4fc;
    --accent-contrast: #10111a;
    --ok: #4ade9a;
    --ok-bg: #12291f;
    --warn: #f2c14e;
    --warn-bg: #2c2410;
    --bad: #f38b83;
    --bad-bg: #2c1615;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem 0 1.75rem;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast);
  flex-shrink: 0;
}
.brand-mark svg { width: 22px; height: 22px; }

.brand h1 { font-size: 1.15rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.brand-sub { margin: 0; font-size: 0.8rem; color: var(--text-muted); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem 0.4rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status.ok .status-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.status.ok .status-text { color: var(--ok); }
.status.bad .status-dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.status.bad .status-text { color: var(--bad); }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.25rem;
  align-items: start;
}

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

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.panel h2 {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  font-weight: 650;
}

/* ---------- Form ---------- */

.field { display: block; margin-bottom: 1rem; }
.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.field input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
  padding: 1.5rem 1rem;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone svg { width: 22px; height: 22px; opacity: 0.7; }
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-2));
}
.dropzone-text { margin: 0; font-size: 0.82rem; line-height: 1.4; }
.dropzone-text strong { color: var(--text); }
.dropzone-file { margin: 0; font-size: 0.78rem; color: var(--accent); font-weight: 600; word-break: break-all; }
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast);
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.05s ease;
}
.btn-primary svg { width: 16px; height: 16px; }
.btn-primary:hover { opacity: 0.92; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
}
.btn-ghost svg { width: 15px; height: 15px; }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-ghost.spinning svg { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  min-width: 0;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.stat-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }

/* ---------- Activity ---------- */

.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}
.activity-header h2 { margin: 0; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
th, td { text-align: left; padding: 0.65rem 0.5rem; white-space: nowrap; }
th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td { color: var(--text); }
td.muted { color: var(--text-muted); }
td.details { white-space: normal; max-width: 260px; color: var(--text-muted); }

.dir-icon {
  display: inline-flex;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  align-items: center;
  justify-content: center;
}
.dir-icon svg { width: 13px; height: 13px; }
.dir-icon.outbound { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.dir-icon.inbound { background: var(--ok-bg); color: var(--ok); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.sent, .pill.received { color: var(--ok); background: var(--ok-bg); }
.pill.failed { color: var(--bad); background: var(--bad-bg); }
.pill.dialing, .pill.converting, .pill.queued { color: var(--warn); background: var(--warn-bg); }

.pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.8rem;
}
.pdf-link:hover { text-decoration: underline; }

.empty-state[hidden] { display: none; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  text-align: center;
}
.empty-state svg { width: 32px; height: 32px; opacity: 0.5; }
.empty-state p { margin: 0; font-size: 0.85rem; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 50;
}
.toast {
  min-width: 240px;
  max-width: 340px;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.83rem;
  color: var(--text);
  animation: toast-in 0.2s ease;
}
.toast.error { border-color: color-mix(in srgb, var(--bad) 50%, var(--border)); }
.toast.success { border-color: color-mix(in srgb, var(--ok) 50%, var(--border)); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Topbar actions / select ---------- */

.topbar-right { display: flex; align-items: center; gap: 0.6rem; }

.field select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: inherit;
  font-size: 0.9rem;
}
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* ---------- Settings panel ---------- */

.settings-panel { margin-bottom: 1.25rem; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 1rem;
}
@media (max-width: 800px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.settings-message { font-size: 0.83rem; color: var(--text-muted); margin: 0.75rem 0 0; }

/* ---------- Auth (login) page ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card { width: 100%; max-width: 360px; }

.auth-title { text-align: center; margin: 0 0 0.3rem; font-size: 1.2rem; font-weight: 700; }
.auth-sub { text-align: center; margin: 0 0 1.5rem; font-size: 0.85rem; color: var(--text-muted); }
.auth-error { min-height: 1.2em; font-size: 0.83rem; color: var(--bad); text-align: center; margin: 0.75rem 0 0; }
.auth-note { text-align: center; font-size: 0.78rem; color: var(--text-muted); margin: 1rem 0 0; }
