/* Minimal readable styling for the VA local app (no framework). */

:root {
  --vx-navy: #1f3a5f;
  --vx-cyan: #76f9fe;
}

* {
  box-sizing: border-box;
}

/* Visually hidden, still announced by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f6f6f4;
}

header {
  background: var(--vx-navy);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  color: var(--vx-cyan);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Build stamp: lets an operator confirm which build they are running. */
.build-stamp {
  margin-left: auto;
  color: #a8cbf0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.6875rem;
  white-space: nowrap;
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
}

nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  border: 1px solid var(--vx-cyan);
  background: transparent;
  color: var(--vx-cyan);
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(118, 249, 254, 0.14);
}

/* Selection is the fill plus aria-selected; a ring here would imitate focus. */
.nav-btn.active {
  background: var(--vx-cyan);
  color: var(--vx-navy);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

section {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px 14px;
  align-items: center;
  margin-bottom: 14px;
}

fieldset {
  grid-column: 1 / -1;
  border: 1px solid #ccc;
  border-radius: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  max-width: 420px;
  padding: 6px 8px;
  border: 1px solid #999;
  border-radius: 4px;
  font: inherit;
}

/* The state chooser: a scrollable chip list, so 50 states stay one field. */
.state-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #999;
  border-radius: 4px;
  background: #fff;
}

/* Each chip is a whole 44px hit target wrapped around a real checkbox. */
.state-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 4px 12px;
  border: 1px solid #ccc;
  border-radius: 999px;
  cursor: pointer;
}

.state-chip:hover {
  background: #eef2f7;
}

.state-chip input {
  width: auto;
  margin: 0;
}

/* Selection is the navy ring plus weight, never a cyan fill. */
.state-chip.checked {
  border-color: var(--vx-navy);
  background: #eef2f7;
  font-weight: 600;
}

/* The inline-flex above would otherwise defeat the `hidden` attribute the
   search filter sets on non-matching chips. */
.state-chip[hidden] {
  display: none;
}

/* The live count sits under the list and never moves the layout around. */
.state-selected {
  margin: 6px 0 0;
  color: #4a4a4a;
}

/* Neutral chrome: the .btn-* levels below decide what a control means, so the
   generic button rule no longer makes every control look like the main action. */
button {
  min-width: 44px;
  min-height: 44px;
  padding: 7px 16px;
  border: 1px solid var(--vx-navy);
  border-radius: 4px;
  background: #fff;
  color: var(--vx-navy);
  cursor: pointer;
  font: inherit;
}

/* Three levels: one primary action per panel, a safe secondary, a quiet ghost. */
.btn-primary {
  border-color: var(--vx-navy);
  background: var(--vx-navy);
  color: #fff;
}

.btn-primary:hover:not([disabled]) {
  border-color: #16294a;
  background: #16294a;
}

.btn-secondary {
  border-color: var(--vx-navy);
  background: #fff;
  color: var(--vx-navy);
}

.btn-secondary:hover:not([disabled]) {
  background: #eef2f7;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--vx-navy);
}

.btn-ghost:hover:not([disabled]) {
  background: transparent;
  color: #16294a;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* In-flight and unavailable controls. */
button:active:not([disabled]) {
  transform: scale(0.98);
}

button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* A busy control keeps the width it had, so the row of buttons cannot jump. */
button[data-busy] {
  cursor: progress;
}

/* Focus must stay visible on every surface, light or navy. One fixed ring
   colour beats currentColor, which matched white-on-white and navy-on-navy. */
button:focus-visible,
.table-scroll:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--vx-navy);
  outline-offset: 2px;
}

/* Only controls sitting on the navy header need the cyan ring; primary
   buttons are navy-filled but their ring is drawn outside, on a light
   section, where navy is the high-contrast choice. */
header :focus-visible {
  outline-color: var(--vx-cyan);
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

#crawl-status {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
}

/* Replaces the status numbers once the server stops answering. */
#crawl-status .status-lost {
  color: #a4161a;
  font-weight: 600;
}

#crawl-log {
  background: #111;
  color: #d7f0d7;
  padding: 12px;
  border-radius: 4px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
}

#filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: end;
  margin-bottom: 12px;
}

#filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#filter-bar input[type="checkbox"] {
  width: auto;
}

/* The table keeps a column width worth reading and scrolls inside this
   wrapper, so a narrow window never drags the whole page sideways. */
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  margin: 12px 0;
}

/* A long email or URL breaks inside the cell instead of widening the table. */
th,
td {
  border: 1px solid #ccc;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

thead th {
  background: #eef2f7;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f2f7ff;
}

tbody tr.selected {
  background: #d6e4f4;
}

tbody tr.selected:hover {
  background: #cbdcf0;
}

tbody tr.selected td:first-child {
  box-shadow: inset 4px 0 0 0 var(--vx-navy);
}

/* The empty state is not a record, so it must not look clickable. */
tbody tr.empty-row {
  cursor: default;
}

tbody tr.empty-row:hover {
  background: transparent;
}

/* Results table while a new page is in flight. */
.table-loading {
  cursor: progress;
}

.table-loading tbody {
  opacity: 0.55;
}

/* Name cell: a real button that reads as a text link, 44px tall for touch. */
.row-open {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 6px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--vx-navy);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.row-open:hover {
  background: transparent;
  color: #16294a;
  text-decoration-thickness: 2px;
}

/* A field and its hint share one grid cell, so the hint never lands in the
   label column of the next row. */
.field-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-stack small {
  color: #4a4a4a;
}

#detail-drawer {
  border: 1px solid #1f3a5f;
  border-radius: 6px;
  padding: 16px;
  margin-top: 16px;
  background: #fafcff;
}

/* The two links are actions: 44px tall like every other control here. */
#detail-drawer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 7px 16px;
  border: 1px solid #1f3a5f;
  border-radius: 4px;
  text-decoration: none;
  color: #1f3a5f;
  background: #fff;
}

/* The inline-flex above would otherwise defeat the `hidden` attribute, so a
   record without a provider website would keep a dead control. */
#detail-website-link[hidden] {
  display: none;
}

#detail-scores {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
}

#export-filename {
  background: #eef2f7;
  padding: 2px 8px;
  border-radius: 4px;
}

/* The push line: what leaves the app, to which tab, under which scope. */
.sheets-summary {
  margin: 10px 0 0;
  color: var(--vx-navy);
  font-weight: 600;
}

/* The export line: how many rows, which states, whose initials, which mode. */
.export-summary {
  margin: 12px 0;
  color: var(--vx-navy);
}

/* The download is a link so the browser owns the save dialogue, but it is the
   one action on this panel: navy fill, white label, 44px tall. */
.btn-download {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 7px 16px;
  border: 1px solid var(--vx-navy);
  border-radius: 4px;
  font-weight: 600;
  text-decoration: none;
}

.btn-download:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The way out of blank initials: a real target, not a stray word in a line. */
#export-edit-setup {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-left: 10px;
  padding: 0 8px;
  color: var(--vx-navy);
  font-weight: 600;
}

/* The inline-flex above would otherwise defeat the `hidden` attribute. */
#export-edit-setup[hidden] {
  display: none;
}

/* One message line per panel: a confirmation and a failure must not look alike. */
.msg {
  margin: 12px 0;
  padding-left: 10px;
  color: var(--vx-navy);
  font-style: normal;
}

.msg-ok {
  color: var(--vx-navy);
}

.msg-error {
  border-left: 4px solid #a4161a;
  color: #a4161a;
  font-style: normal;
  font-weight: 600;
}

/* ---------- narrow viewports: phone width, down to 320px ---------- */

@media (max-width: 640px) {
  header {
    padding: 12px;
  }

  /* The lockup owns the first line so it is not squeezed by the view menu. */
  .brand {
    width: 100%;
  }

  nav {
    flex-wrap: wrap;
  }

  main {
    padding: 12px;
  }

  section {
    padding: 14px;
  }

  /* One column: a fixed 200px label column leaves no room for the control. */
  .form-grid {
    grid-template-columns: 1fr;
  }

  /* Stacked actions, each at full width and still at least 44px tall. */
  .btn-row {
    flex-direction: column;
    align-items: stretch;
  }
}
