:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #162033;
  --muted: #667085;
  --line: #dfe5ee;
  --line-strong: #c6cfdd;
  --nav: #151a24;
  --nav-soft: #202838;
  --teal: #147d7e;
  --violet: #635bff;
  --amber: #b7791f;
  --red: #c24130;
  --green: #26734d;
  --shadow: 0 12px 30px rgba(22, 32, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
a.primary,
a.secondary {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(99, 91, 255, 0.25);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--nav);
  color: #f8fafc;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #e7fff7;
  color: var(--teal);
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 19px;
}

.brand span:last-child {
  display: block;
  margin-top: 2px;
  color: #a8b3c7;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  color: #cbd5e1;
  background: transparent;
  border-color: transparent;
  justify-content: flex-start;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-soft);
  color: #ffffff;
}

.nav-item.active {
  box-shadow: inset 3px 0 0 var(--violet);
}

.connection-card {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 14px;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--amber);
  flex: 0 0 auto;
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.error {
  background: var(--red);
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
  margin-bottom: 0;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.primary {
  background: var(--violet);
  color: #ffffff;
  font-weight: 800;
}

.primary:hover {
  background: #5148e8;
}

.secondary {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
  font-weight: 800;
}

.secondary:hover {
  border-color: var(--line-strong);
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(160px, 220px) 150px 150px minmax(200px, 1fr) auto;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: #475467;
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

.notice {
  border: 1px solid #f4c7b8;
  background: #fff7ed;
  color: #8a3a1d;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 112px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 14px;
}

.metric strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.metric small {
  display: block;
  color: var(--muted);
  margin-top: 8px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

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

.panel.wide {
  grid-column: 1 / -1;
}

.panel-header {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.bar-list {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 3fr auto;
  gap: 12px;
  align-items: center;
  color: #475467;
  font-weight: 700;
}

.bar-track,
.trend-track {
  height: 10px;
  border-radius: 999px;
  background: #edf1f7;
  overflow: hidden;
}

.bar-fill,
.trend-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: var(--teal);
}

.bar-row:nth-child(2n) .bar-fill {
  background: var(--violet);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--amber);
}

.trend {
  padding: 18px;
  min-height: 160px;
  display: grid;
  gap: 10px;
}

.trend-row {
  display: grid;
  grid-template-columns: 110px minmax(100px, 1fr) 64px;
  gap: 12px;
  align-items: center;
  color: #475467;
  font-weight: 700;
}

.table-panel {
  overflow: hidden;
}

.table-actions {
  min-width: 120px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  max-height: calc(100vh - 280px);
}

.compact-table {
  max-height: 360px;
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: #667085;
  font-size: 12px;
  text-transform: uppercase;
}

tr[data-row] {
  cursor: pointer;
}

tr[data-row]:hover td {
  background: #f8fbff;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #edf1f7;
  color: #475467;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.sent-to-dialer,
.badge.billable,
.badge.sale,
.badge.app {
  background: #e7f7ed;
  color: var(--green);
}

.badge.queued-for-dialer {
  background: #eef7ff;
  color: var(--teal);
}

.badge.duplicate,
.badge.recycle-loss,
.badge.ni,
.badge.dec {
  background: #fff7ed;
  color: var(--amber);
}

.badge.dialer-failed,
.badge.rejected {
  background: #fff0ed;
  color: var(--red);
}

.settings-list {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  margin: 0;
  padding: 18px;
  gap: 12px 18px;
}

.settings-list dt {
  color: var(--muted);
  font-weight: 800;
}

.settings-list dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

dialog {
  width: min(860px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(22, 32, 51, 0.26);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

#recordJson {
  margin: 0;
  padding: 16px;
  max-height: 70vh;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 13px;
}

.empty {
  color: var(--muted);
  padding: 18px;
  font-weight: 700;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 18px;
  }

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

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

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters,
  .analytics-grid,
  .ops-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .bar-row,
  .trend-row {
    grid-template-columns: 1fr;
  }

  .settings-list {
    grid-template-columns: 1fr;
  }
}
