:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #151b23;
  --surface-alt: #111820;
  --ink: #e6edf3;
  --muted: #8b9cb3;
  --line: #2d3748;
  --line-strong: #374151;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-soft: rgba(59, 130, 246, 0.16);
  --mint: #14b8a6;
  --yellow: #eab308;
  --red: #ef4444;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.36);
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

button,
input,
.button-link {
  font: inherit;
}

button,
.button-link {
  min-height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #1f2937;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  padding: 0 10px;
  text-decoration: none;
}

button:hover,
.button-link:hover {
  background: #243244;
  border-color: #4b5563;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  padding: 7px 9px;
}

input:focus,
button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
  outline: 0;
  outline-offset: 1px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 66px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 250px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
}

.workspace {
  display: grid;
  grid-template-columns: 316px minmax(460px, 1fr);
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.list-panel {
  background: var(--surface);
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
  padding: 10px;
  border-right: 1px solid var(--line);
}

.auth-panel,
.caller-id-panel {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
}

.auth-state {
  display: grid;
  gap: 8px;
}

.auth-state p,
.auth-state span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.auth-state strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-message {
  border: 1px solid rgba(239, 68, 68, 0.42);
  border-radius: 6px;
  background: rgba(127, 29, 29, 0.36);
  color: #fecaca;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  padding: 8px 9px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-row button,
.primary {
  background: #1e3a5f;
  border-color: var(--blue-dark);
  color: #dbeafe;
}

.input-row button:hover,
.primary:hover {
  background: #244a78;
}

.compact-link {
  min-height: 28px;
  font-size: 12px;
}

.panel-header,
.list-toolbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.ghost {
  background: #1f2937;
  border-color: var(--line-strong);
  color: var(--ink);
}

.ghost:hover {
  background: #243244;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  padding: 0;
}

.refresh-icon {
  display: block;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: url("/icons/refresh-cw.svg") center / 16px 16px no-repeat;
  mask: url("/icons/refresh-cw.svg") center / 16px 16px no-repeat;
}

.details {
  display: grid;
  gap: 9px;
  margin: 0;
}

.details div {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.current-summary {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.current-summary strong {
  overflow: hidden;
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-summary span:last-child {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
  text-transform: uppercase;
}

.source-options {
  display: grid;
  gap: 8px;
}

.source-card {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 9px;
  text-align: left;
  background: var(--bg);
  border-color: var(--line);
  color: var(--ink);
}

.source-card:hover {
  background: #1a222c;
}

.source-card.active {
  background: #1e3a5f;
  border-color: var(--blue-dark);
  color: #dbeafe;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.14);
}

.source-radio {
  display: inline-grid;
  place-content: center;
  width: 18px;
  height: 18px;
  border: 2px solid #64748b;
  border-radius: 50%;
}

.source-radio::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
  content: "";
  transform: scale(0);
  transition: transform 120ms ease;
}

.source-card.active .source-radio::before {
  transform: scale(1);
}

.source-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
  overflow: hidden;
}

.source-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.source-title {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-number,
.source-subtitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-number {
  color: var(--ink);
  font-weight: 800;
}

.source-card.active .source-number,
.source-card.active .source-subtitle {
  color: #bfdbfe;
}

.current-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border: 1px solid rgba(20, 184, 166, 0.42);
  border-radius: 999px;
  background: #052e2b;
  color: #99f6e4;
  font-size: 11px;
  font-weight: 900;
  visibility: hidden;
}

.source-card.current .current-badge {
  visibility: visible;
}

.list-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.list-toolbar {
  min-height: 58px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-alt);
  padding: 10px;
}

.list-toolbar p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.toolbar-actions {
  display: grid;
  grid-template-columns: minmax(180px, 260px) auto auto;
  align-items: center;
  gap: 8px;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  white-space: nowrap;
}

.toggle-row input {
  accent-color: var(--blue);
  height: 16px;
  min-height: 16px;
  min-width: 16px;
  width: 16px;
}

.table-wrap {
  height: calc(100vh - 125px);
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 720px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #111820;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

tbody tr:hover {
  background: #1a222c;
}

tbody tr.selected {
  background: #102f4f;
}

tbody tr.unavailable {
  color: var(--muted);
  cursor: not-allowed;
}

.select-col {
  width: 72px;
}

.radio-cell {
  text-align: center;
}

.radio-dot {
  -webkit-appearance: none;
  appearance: none;
  border: 2px solid #64748b;
  border-radius: 50%;
  display: inline-grid;
  height: 18px;
  margin: 0;
  min-height: 18px;
  min-width: 18px;
  padding: 0;
  place-content: center;
  width: 18px;
}

.radio-dot::before {
  background: var(--blue);
  border-radius: 50%;
  content: "";
  height: 8px;
  transform: scale(0);
  transition: transform 120ms ease;
  width: 8px;
}

.radio-dot:checked::before {
  transform: scale(1);
}

.name-cell {
  font-weight: 800;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  background: #422006;
  border: 1px solid rgba(234, 179, 8, 0.42);
  border-radius: 999px;
  color: #fde68a;
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  min-height: 22px;
  padding: 2px 7px;
}

.empty {
  color: var(--muted);
  padding: 30px 18px;
  text-align: center;
}

.toast {
  background: #1f2937;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  bottom: 16px;
  color: var(--ink);
  left: 50%;
  max-width: min(560px, calc(100vw - 32px));
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 18px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: #7f1d1d;
  border-color: rgba(239, 68, 68, 0.52);
  color: #fecaca;
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .topbar,
  .list-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar-actions {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 17px;
  }

  .table-wrap {
    height: auto;
    max-height: none;
  }
}
