/* Radio Channel Admin — UI styles */

*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-border: #2d3148;
  --color-accent: #4f8ef7;
  --color-accent-hover: #3a7ae8;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", ui-monospace, monospace;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────────── */

nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 52px;
}

nav .brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-accent);
  text-decoration: none;
  letter-spacing: -0.02em;
}

nav a {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.15s;
}

nav a:hover, nav a.active {
  color: var(--color-text);
}

nav .spacer {
  flex: 1;
}

nav .nav-user {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

main {
  /* Use most of the viewport width; keep a sane cap on ultra-wide screens. */
  max-width: min(1900px, 97vw);
  margin: 0 auto;
  padding: 1rem 0.75rem;
}

/* ── Typography ──────────────────────────────────────────────── */

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  color: var(--color-text);
}

h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.5rem;
}

h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header p {
  color: var(--color-text-muted);
  margin: 0;
}

/* ── Cards / Surfaces ────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem 1.5rem;
  margin-bottom: 0.5rem;
}

.meta-item label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 0.125rem;
}

.meta-item span {
  font-size: 0.875rem;
  color: var(--color-text);
}

/* ── Tables ──────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  margin-bottom: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead {
  background: rgba(255,255,255,0.03);
}

th {
  text-align: left;
  padding: 0.625rem 0.875rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

td {
  padding: 0.5rem 0.875rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

/* ── Badges / Status ─────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-ok     { background: rgba(34,197,94,.15);  color: var(--color-success); }
.badge-failed { background: rgba(239,68,68,.15);  color: var(--color-error);   }
.badge-stale  { background: rgba(245,158,11,.15); color: var(--color-warning); }
.badge-never  { background: rgba(148,163,184,.12); color: var(--color-text-muted); }
.badge-disabled { background: rgba(148,163,184,.08); color: var(--color-text-muted); }

/* ── Forms ───────────────────────────────────────────────────── */

.form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  margin: 4rem auto;
  box-shadow: var(--shadow);
}

.form-card h1 {
  margin-bottom: 0.25rem;
}

.form-card .subtitle {
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 0.375rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
textarea {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--color-accent);
}

.form-group {
  margin-bottom: 1rem;
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4rem 0.875rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover { background: var(--color-accent-hover); }

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid rgba(239,68,68,.3);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}
.btn-danger:hover { background: rgba(239,68,68,.1); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: rgba(255,255,255,.04); color: var(--color-text); }

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

/* ── Alias cell ──────────────────────────────────────────────── */

.alias-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 200px;
}

.alias-display {
  flex: 1;
  font-size: 0.8125rem;
  color: var(--color-text);
}

.alias-display.empty {
  color: var(--color-text-muted);
  font-style: italic;
}

.alias-form {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1;
}

.alias-form input[type="text"] {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  min-width: 0;
  flex: 1;
}

.alias-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-shrink: 0;
}

/* htmx in-flight indicator */
.htmx-request .alias-cell {
  opacity: 0.6;
}

/* ── Alerts ──────────────────────────────────────────────────── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.alert-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
}

/* ── Links ───────────────────────────────────────────────────── */

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── Empty state ─────────────────────────────────────────────── */

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

/* ── Section divider ─────────────────────────────────────────── */

.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  padding: 0.5rem 0.875rem;
  background: rgba(255,255,255,.02);
  border-bottom: 1px solid var(--color-border);
}

/* ── Tight table for talkgroup lists ──────────────────────────── */
.tight-table th,
.tight-table td {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  line-height: 1.25;
  vertical-align: middle;
}
.tight-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Inline auto-saving alias input ───────────────────────────── */
.alias-input {
  width: 100%;
  min-width: 10.4rem; /* 8rem + 30% */
  padding: 0.2rem 0.4rem;
  font: inherit;
  font-size: 1.1rem; /* 0.85rem + ~30% */
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  color: var(--color-text-muted);
}
.alias-input:hover {
  border-color: var(--color-border);
}
.alias-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: rgba(255,255,255,.03);
  color: var(--color-text);
}
.alias-input.alias-set {
  color: var(--color-text);
  font-weight: 500;
}
.alias-input.htmx-request {
  opacity: 0.5;
}

/* ── Alias cell: input + quick-fill buttons in one row ────────── */
.alias-cell {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.alias-copy-btn {
  flex-shrink: 0;
  padding: 0.1rem 0.35rem;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 0.2rem;
  user-select: none;
}
.alias-copy-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.alias-input.alias-no-source {
  animation: alias-flash 0.6s ease-out;
}
@keyframes alias-flash {
  0%   { background: rgba(220,80,80,.18); }
  100% { background: transparent; }
}

/* ── Tight TG table column widths + Hex toggle ────────────────── */
.tight-table th,
.tight-table td {
  padding: 0.2rem 0.3rem;     /* tighter than the 0.25/0.5 default */
}
.tg-table .col-hex { display: none; }
.tg-table.show-hex .col-hex { display: table-cell; }

.tg-table .col-alias {
  /* Widest text column — bumped 30% to give aliases more room. */
  min-width: 23.4rem; /* 18rem + 30% */
  width: 39%; /* 30% + 30% */
}
.tg-table .col-alias .alias-input {
  min-width: 18.2rem; /* 14rem + 30% */
}

/* ── Right-click context menu ─────────────────────────────────── */
.ctx-menu {
  position: absolute;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.3rem;
  padding: 0.25rem 0;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
  z-index: 1000;
  min-width: 240px;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.85rem;
  background: transparent;
  border: 0;
  color: var(--color-text);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.ctx-menu button:hover {
  background: rgba(255,255,255,.05);
  color: var(--color-accent);
}

/* ── Fill-down success flash (green) ──────────────────────────── */
.alias-input.alias-fill-ok {
  animation: alias-fill-ok 1.2s ease-out;
}
@keyframes alias-fill-ok {
  0%   { background: rgba(80,200,120,.22); }
  100% { background: transparent; }
}

/* ── Pending alias prefix (stamped by Fill Down, not yet saved) ─ */
.alias-input.alias-pending {
  font-style: italic;
  color: var(--color-text-muted);
  border-style: dashed;
  border-color: var(--color-border);
}
.alias-input.alias-pending:focus {
  font-style: normal;
}

/* ── Multi-select tag filter (HTML <details> dropdown) ────────── */
.multi-filter {
  position: relative;
  font-size: 0.85rem;
}
.multi-filter > summary {
  cursor: pointer;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  list-style: none;
  user-select: none;
}
.multi-filter > summary::-webkit-details-marker { display: none; }
.multi-filter[open] > summary {
  background: rgba(255,255,255,.05);
  border-color: var(--color-accent);
}
.multi-filter-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.3rem;
  padding: 0.5rem;
  min-width: 220px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
.multi-filter-menu label {
  display: block;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.85rem;
}
.multi-filter-menu label:hover {
  background: rgba(255,255,255,.05);
}
.multi-filter-menu input[type=checkbox] {
  margin-right: 0.4rem;
}
.multi-filter-menu hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: 0.4rem 0;
}
.multi-filter-menu button {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 0.2rem;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-right: 0.3rem;
}
.multi-filter-menu button:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ── Machine assignment cell ────────────────────────────────── */

.col-machines {
  min-width: 120px;
  max-width: 200px;
}

.machine-assign-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.machine-assign-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.machine-assign-label:hover {
  border-color: var(--color-border);
  background: var(--color-surface);
}

.machine-assign-label.machine-assigned {
  color: var(--color-text);
  border-color: var(--color-accent);
  background: rgba(79, 142, 247, 0.08);
}

.machine-assign-label input[type="checkbox"] {
  accent-color: var(--color-accent);
  cursor: pointer;
}

.machine-rendered-name {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-accent);
  margin-left: 0.2rem;
}

/* ── Machine management table additions ─────────────────────── */

.btn-success {
  background: var(--color-success);
  color: #000;
  border-color: var(--color-success);
}

.btn-success:hover {
  background: #16a34a;
  border-color: #16a34a;
}

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #fff;
}

.form-input {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--color-accent);
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0 0 0.25rem;
}

/* ── Authoring UI (Sprint 4) ─────────────────────────────────── */

.authoring-step {
  margin-bottom: 1.5rem;
}

.authoring-county-form {
  margin-top: 0.75rem;
}

.authoring-county-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.authoring-county-select {
  min-width: 280px;
  flex: 1;
  max-width: 400px;
}

.authoring-spinner {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  display: none;
}

.authoring-spinner.htmx-request {
  display: inline;
}

.authoring-tg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.authoring-tg-header h2 {
  margin: 0;
  border: none;
  padding: 0;
}

.authoring-tg-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.authoring-hidden-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.authoring-tg-table .col-name {
  min-width: 14rem;
}

.authoring-name-cell {
  min-width: 180px;
}

.authoring-name-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.authoring-name-row .alias-input {
  flex: 1;
  min-width: 10rem;
}

.authoring-name-error {
  font-size: 0.75rem;
  color: var(--color-danger);
  margin-top: 0.2rem;
}

.authoring-current-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-success);
}

.authoring-primary-select {
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
  min-width: 5rem;
}

/* htmx loading indicator for rows */
tr.htmx-request td {
  opacity: 0.6;
}


.alias-error { color: #b00020; font-size: 0.8em; margin-left: 0.4em; }

/* ── Shorten affordance — Sprint 3 naming-phase2 ─────────────── */
.shorten-hint {
  margin-top: 0.4rem;
}

.shorten-label {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.2rem;
}

.shorten-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.shorten-input {
  width: 6em;
  font-size: 0.8rem;
  padding: 0.2rem 0.3rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.shorten-input:focus {
  outline: none;
  border-color: var(--color-warning);
}

.shorten-error {
  color: var(--color-error);
  font-size: 0.75rem;
  margin-top: 0.2rem;
}

/* ── Authoring search ────────────────────────────────────────────── */

.search-input {
  width: 100%;
  max-width: 480px;
  display: block;
}

.search-results-container {
  margin-top: 0.75rem;
}

.search-section {
  margin-bottom: 1rem;
}

.search-section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 0 0 0.4rem 0;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.search-item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.search-item:last-child {
  border-bottom: none;
}

.search-item-name {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.search-item-name:hover {
  text-decoration: underline;
}

.search-item-meta {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.search-empty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin: 0.5rem 0;
}
