:root {
  /* Royal Energy brand tokens (matched to royalenergy.co) */
  --navy: #002366;
  --navy-deep: #001a4d;
  --navy-ink: #0a2c70;
  --blue: #2a55c9; /* brighter royal-blue accent, used sparingly */
  --gold: #bf9a3f;
  --gold-deep: #8f6f23;
  --gold-bright: #e3c578;

  --bg: #eef3fc; /* page */
  --bg-grad: #f8fbff;
  --panel: #ffffff; /* cards */
  --panel-2: #f4f8fd; /* insets, inputs, chips */
  --border: #e2e8f3;
  --border-strong: #d2dcec;
  --text: #10203f; /* ink */
  --text-dim: #566583; /* muted */

  --accent: #002366;
  --accent-hover: #2a55c9;
  --accent-tint: rgba(0, 35, 102, 0.07);
  --accent-ring: rgba(0, 35, 102, 0.15);
  --green: #15915f;
  --amber: #8f6f23; /* gold, legible on light */

  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Libre Franklin', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius: 14px;
  --radius-btn: 11px;
  --shadow: 0 1px 2px rgba(16, 32, 63, 0.05), 0 10px 28px -14px rgba(0, 35, 102, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: radial-gradient(1200px 620px at 82% -12%, var(--bg-grad) 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}
.logo-badge {
  width: 46px;
  height: 46px;
  flex: none;
  color: var(--navy);
}
.brand-text {
  display: flex;
  flex-direction: column;
}
h1 {
  font-family: var(--serif);
  font-size: 25px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.05;
  color: var(--navy);
}
h1 .brand-tool {
  color: var(--gold-deep);
  font-style: italic;
  font-weight: 500;
}
.subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.header-user {
  font-size: 12.5px;
  color: var(--text-dim);
  font-weight: 500;
}
.header-admin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-tint);
  color: var(--accent);
  border: 1px solid var(--accent-ring);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.admin-count {
  background: var(--gold);
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  padding: 0 5px;
}
.status-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.status-pending {
  color: var(--gold-deep);
  background: rgba(191, 154, 63, 0.14);
}
.status-approved {
  color: var(--green);
  background: rgba(21, 145, 95, 0.14);
}
.status-admin {
  color: var(--accent);
  background: var(--accent-tint);
}
.status-unverified {
  color: var(--text-dim);
  background: rgba(16, 32, 63, 0.06);
}

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  white-space: nowrap;
}
.badge-muted {
  color: var(--text-dim);
  background: var(--panel);
}
.badge-sandbox {
  color: var(--gold-deep);
  background: rgba(191, 154, 63, 0.12);
  border-color: rgba(191, 154, 63, 0.4);
}
.badge-prod {
  color: var(--green);
  background: rgba(21, 145, 95, 0.1);
  border-color: rgba(21, 145, 95, 0.32);
}

/* Balances bar */
.balances {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.bal-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.bal-chip {
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.bal-chip.bal-good {
  border-color: rgba(21, 145, 95, 0.4);
}
.bal-chip.bal-warn {
  color: var(--gold-deep);
  border-color: rgba(191, 154, 63, 0.45);
  background: rgba(191, 154, 63, 0.1);
}
.bal-chip.bal-bad {
  color: #b4232c;
  border-color: rgba(180, 35, 44, 0.4);
  background: rgba(180, 35, 44, 0.07);
}
.bal-refresh {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.bal-refresh .btn-ico {
  width: 13px;
  height: 13px;
  color: currentColor;
}
.bal-refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

/* Controls */
.controls {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* `display: flex` above overrides the UA [hidden] rule — restore it. */
.field[hidden] {
  display: none;
}
.field-grow {
  flex: 1 1 280px;
}
.field-zip {
  width: 110px;
}
.field-toggle {
  justify-content: flex-end;
}
label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type='text'],
#category,
#zip {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#category:focus,
#zip:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
#zip {
  font-family: var(--mono);
  letter-spacing: 0.1em;
}
.hint {
  font-size: 11px;
  color: var(--text-dim);
}

/* Searchable combobox */
.combo {
  position: relative;
}
.combo > input {
  width: 100%;
}
.combo-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.combo-list[hidden] {
  display: none;
}
.combo-option {
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1.3;
}
.combo-option:hover,
.combo-option.active {
  background: var(--accent-tint);
}
.combo-option mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}
.combo-option .why {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}
.combo-empty {
  padding: 11px;
  font-size: 13px;
  color: var(--text-dim);
}

/* Segmented control (ZIP / State) */
.segmented {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  padding: 3px;
  height: 42px;
}
.seg {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.seg.active {
  background: var(--accent);
  color: #fff;
}
.field-state {
  width: 220px;
}
#state {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  height: 42px;
}
#state:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Progress bar */
.progress-panel {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
#progress-label {
  font-size: 13px;
  font-weight: 600;
}
#progress-stats {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.progress-track {
  height: 8px;
  background: #dde6f4;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--navy), var(--blue));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  padding: 11px 24px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s, transform 0.05s, box-shadow 0.18s;
  height: 42px;
  box-shadow: 0 1px 2px rgba(0, 35, 102, 0.18), 0 8px 22px -10px rgba(0, 35, 102, 0.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--navy-deep);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
}
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn-ico {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--accent);
}
.btn-secondary:hover .btn-ico {
  color: var(--accent);
}
.btn-secondary:hover {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent);
}

/* Messages */
.message {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  line-height: 1.5;
}
.message.error {
  background: rgba(180, 35, 44, 0.07);
  border: 1px solid rgba(180, 35, 44, 0.28);
  color: #b4232c;
}
.message.info {
  background: var(--accent-tint);
  border: 1px solid var(--accent-ring);
  color: var(--text-dim);
}
.message.loading {
  display: flex;
  align-items: center;
  gap: 10px;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Results */
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.results-count {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  color: var(--navy);
}
.results-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 10px;
}
/* Related categories */
.related {
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.related-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.related-title {
  font-size: 13px;
  font-weight: 700;
}
.related-sub {
  font-size: 11.5px;
  color: var(--text-dim);
}
.related-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s, background 0.12s;
  /* These render as <label>; cancel the global uppercase so category names
     read in their natural sentence case (e.g. "Air conditioning contractor"). */
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.chip:hover {
  border-color: var(--accent);
}
.chip input {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
.chip.checked {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.chip .chip-count {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.related-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.related-cost {
  font-size: 12px;
  color: var(--text-dim);
}
.expand-confirm {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 10px;
  background: rgba(191, 154, 63, 0.1);
  border: 1px solid rgba(191, 154, 63, 0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.expand-confirm[hidden] {
  display: none;
}
#expand-confirm-text {
  font-size: 13px;
  color: var(--text);
}
.expand-confirm-btns {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.expand-confirm-btns .btn-primary {
  height: auto;
  padding: 8px 16px;
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.loc-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-tint);
  border-radius: 999px;
  vertical-align: middle;
}

td .email {
  font-family: var(--mono);
  font-size: 12px;
}
.conf-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 999px;
  vertical-align: middle;
  color: var(--text-dim);
  background: rgba(16, 32, 63, 0.06);
}
.conf-guessed {
  color: var(--gold-deep);
  background: rgba(191, 154, 63, 0.16);
}
.sms-ok {
  color: var(--green) !important;
  background: rgba(21, 145, 95, 0.14) !important;
}
.email-pending {
  color: var(--text-dim);
  font-size: 11px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 11px 14px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
th.num,
td.num {
  text-align: right;
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: rgba(0, 35, 102, 0.025);
}
td .name {
  font-weight: 600;
}
.cat {
  color: var(--text);
  font-size: 12.5px;
}
.cat-more {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-tint);
  border-radius: 999px;
  cursor: help;
  vertical-align: middle;
}
.company-clean {
  font-weight: 600;
  outline: none;
  border-radius: 4px;
  padding: 1px 3px;
  cursor: text;
}
.company-clean:hover {
  background: rgba(0, 35, 102, 0.05);
}
.company-clean:focus {
  background: var(--accent-tint);
  box-shadow: 0 0 0 1px var(--accent);
}
.company-raw {
  display: block;
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.name-low {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: 5px;
  vertical-align: middle;
}
td a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
td a:hover {
  text-decoration: underline;
}
.muted {
  color: var(--text-dim);
}
.phone {
  font-family: var(--mono);
  font-size: 12.5px;
}

.footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
}

@media (max-width: 640px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .field-zip {
    width: 100%;
  }
  .btn-primary {
    width: 100%;
  }
}
