/* ============================================================
   FMCSA Monitor — Telegram Mini App
   Industrial / compliance aesthetic.
   Geist + Geist Mono. Amber accent. Telegram theme aware.
   ============================================================ */

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

:root {
  /* Telegram theme tokens (with sensible light fallbacks) */
  --tg-bg:                var(--tg-theme-bg-color, #ffffff);
  --tg-text:              var(--tg-theme-text-color, #0a0a0a);
  --tg-hint:              var(--tg-theme-hint-color, #707579);
  --tg-link:              var(--tg-theme-link-color, #2481cc);
  --tg-button:            var(--tg-theme-button-color, #2481cc);
  --tg-button-text:       var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg:      var(--tg-theme-secondary-bg-color, #f4f4f5);
  --tg-section-bg:        var(--tg-theme-section-bg-color, #ffffff);
  --tg-header-text:       var(--tg-theme-section-header-text-color, #6b7280);
  --tg-subtitle:          var(--tg-theme-subtitle-text-color, #6b7280);
  --tg-destructive:       var(--tg-theme-destructive-text-color, #dc2626);
  --tg-accent:            var(--tg-theme-accent-text-color, #2481cc);

  /* App identity — amber for compliance / risk */
  --app-accent:           #d97706;
  --app-accent-soft:      #fef3c7;
  --app-accent-fg:        #78350f;

  /* Status palette */
  --status-active:        #15803d;
  --status-active-bg:     #dcfce7;
  --status-inactive:      #57534e;
  --status-inactive-bg:   #f5f5f4;
  --status-revoked:       #b91c1c;
  --status-revoked-bg:    #fee2e2;
  --status-pending:       #b45309;
  --status-pending-bg:    #fef3c7;

  /* Borders use a tint of the foreground so they adapt to dark theme */
  --border:               color-mix(in srgb, var(--tg-text) 12%, transparent);
  --border-strong:        color-mix(in srgb, var(--tg-text) 22%, transparent);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --header-h: 52px;
  --bottomnav-h: 64px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--tg-link); text-decoration: none; }
a:active { opacity: 0.6; }

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--tg-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.brand-name { color: var(--tg-text); }
.brand-sep { color: var(--app-accent); margin: 0 1px; }
.brand-meta {
  margin-left: 6px;
  color: var(--tg-hint);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--app-accent);
  box-shadow: 0 0 0 0 currentColor;
}
.brand-dot[data-state="connecting"] { background: #a3a3a3; animation: pulse 1.4s ease-in-out infinite; }
.brand-dot[data-state="ok"]         { background: var(--status-active); }
.brand-dot[data-state="error"]      { background: var(--status-revoked); }

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0;
  color: var(--tg-text);
  border-radius: var(--radius-sm);
}
.icon-btn:active { background: var(--tg-secondary-bg); }

/* ---------- main view ---------- */
.view {
  min-height: calc(100vh - var(--header-h) - var(--bottomnav-h) - var(--safe-top) - var(--safe-bottom));
  padding: 16px 16px calc(24px + var(--bottomnav-h) + var(--safe-bottom));
  animation: viewIn 180ms ease-out;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- loading ---------- */
.loading-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 50vh; gap: 16px;
}
.loading-mark {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--tg-hint);
}
.loading-line {
  width: 80px; height: 2px; background: var(--border); position: relative; overflow: hidden;
}
.loading-line::before {
  content: '';
  position: absolute; inset: 0;
  width: 30%; background: var(--app-accent);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(360%); }
}

/* ---------- typography ---------- */
.h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.005em; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tg-hint);
}
.hint  { color: var(--tg-hint); }
.small { font-size: 13px; }
.tiny  { font-size: 12px; }
.mono  { font-family: var(--font-mono); font-feature-settings: 'tnum' 1, 'cv11' 1; }
.label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tg-hint);
}

/* ---------- layout primitives ---------- */
.stack > * + *  { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tg-header-text);
  padding: 0 4px 8px;
}

/* ---------- card ---------- */
.card {
  background: var(--tg-section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.card-pad { padding: 16px; }
.card + .card, .card + .card-stack, .stack-lg > .card + * { margin-top: 12px; }

.card-row {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: var(--tg-section-bg);
}
.card-row:first-child { border-top: 0; }
.card-row[data-action] { cursor: pointer; }
.card-row[data-action]:active { background: var(--tg-secondary-bg); }

.card-row-main { flex: 1; min-width: 0; }
.card-row-title { font-weight: 500; }
.card-row-sub   { color: var(--tg-hint); font-size: 13px; margin-top: 2px; }
.card-row-meta  { font-family: var(--font-mono); font-size: 12px; color: var(--tg-hint); white-space: nowrap; }

/* ---------- inputs ---------- */
.input,
.textarea {
  width: 100%;
  background: var(--tg-section-bg);
  color: var(--tg-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  outline: none;
  transition: border-color 120ms ease;
}
.input:focus, .textarea:focus {
  border-color: var(--app-accent);
}
.input::placeholder, .textarea::placeholder { color: var(--tg-hint); }
.textarea { min-height: 140px; resize: vertical; font-family: var(--font-mono); font-size: 13px; }

/* ---------- search bar ---------- */
.search-bar {
  display: flex; gap: 8px; align-items: stretch;
}
.search-bar .input { flex: 1; }

/* ---------- filter pills (search type chips) ---------- */
.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* bleed to viewport edges so pills can scroll fully off-screen */
  margin: -4px -16px 0;
  padding: 4px 16px 4px;
}
.filter-pills::-webkit-scrollbar { display: none; }

.filter-pill {
  flex-shrink: 0;
  background: var(--tg-section-bg);
  color: var(--tg-text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 100ms ease;
  white-space: nowrap;
}
.filter-pill:active { transform: scale(0.96); }
.filter-pill[aria-pressed="true"] {
  background: var(--app-accent);
  color: #fff;
  border-color: var(--app-accent);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: 0;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-weight: 500;
  letter-spacing: 0.005em;
  transition: opacity 100ms ease, transform 100ms ease;
}
.btn:active { opacity: 0.85; transform: scale(0.98); }
.btn[disabled], .btn.is-loading { opacity: 0.5; pointer-events: none; }

.btn-block { width: 100%; }
.btn-secondary {
  background: var(--tg-section-bg);
  color: var(--tg-text);
  border: 1px solid var(--border);
}
.btn-amber {
  background: var(--app-accent);
  color: white;
}
.btn-danger {
  background: var(--tg-section-bg);
  color: var(--tg-destructive);
  border: 1px solid var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--tg-link);
  padding: 8px 10px;
}

/* ---------- pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  white-space: nowrap;
}
.pill-amber    { background: var(--app-accent-soft); color: var(--app-accent-fg); }
.pill-active   { background: var(--status-active-bg); color: var(--status-active); }
.pill-inactive { background: var(--status-inactive-bg); color: var(--status-inactive); }
.pill-revoked  { background: var(--status-revoked-bg); color: var(--status-revoked); }
.pill-pending  { background: var(--status-pending-bg); color: var(--status-pending); }

.docket-tag {
  display: inline-flex; align-items: baseline;
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  background: var(--tg-section-bg);
  white-space: nowrap;
}
.docket-tag .prefix {
  font-weight: 600;
  color: var(--app-accent-fg);
  background: var(--app-accent-soft);
  padding: 0 4px;
  margin: -2px 6px -2px -6px;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.docket-tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- entity profile ---------- */
.profile-hero {
  background: var(--tg-section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 16px;
}
.profile-dot {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--tg-hint);
  margin-bottom: 6px;
}
.profile-dot strong { color: var(--app-accent); font-weight: 600; }
.profile-name {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.profile-dba {
  color: var(--tg-hint);
  font-size: 14px;
  margin-top: 2px;
}
.profile-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 12px;
}

/* key-value rows */
.kv {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--border);
  align-items: baseline;
}
.kv:first-child { border-top: 0; }
.kv-key {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tg-hint);
}
.kv-val { word-break: break-word; }
.kv-val.mono { font-size: 14px; }
.kv-val a { display: inline-block; }

/* connection group */
.group {
  border-top: 1px solid var(--border);
}
.group:first-child { border-top: 0; }
.group-header {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px;
  background: transparent;
  border: 0;
  text-align: left;
  color: var(--tg-text);
}
.group-header:active { background: var(--tg-secondary-bg); }
.group-meta {
  display: flex; flex-direction: column; min-width: 0;
}
.group-type {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--app-accent-fg);
}
.group-value { margin-top: 2px; font-size: 14px; word-break: break-word; }
.group-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--tg-hint);
  white-space: nowrap;
}
.group-body { display: none; padding: 0 0 4px; }
.group.is-open .group-body { display: block; }
.group.is-open .chev { transform: rotate(90deg); }
.chev { transition: transform 160ms ease; color: var(--tg-hint); }

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--tg-bg);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: transparent; border: 0;
  gap: 3px;
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tg-hint);
}
.nav-btn[aria-current="true"] { color: var(--app-accent); }
.nav-btn:active { background: var(--tg-secondary-bg); }

/* ---------- empty / error ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--tg-hint);
  gap: 6px;
}
.empty-mark {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--app-accent);
}
.empty-title { font-size: 15px; color: var(--tg-text); font-weight: 500; }
.empty-desc { font-size: 13px; max-width: 280px; }

.error-box {
  border: 1px solid var(--status-revoked-bg);
  background: var(--status-revoked-bg);
  color: var(--status-revoked);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 12px);
  transform: translateX(-50%);
  background: var(--tg-text);
  color: var(--tg-bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show {
  opacity: 0.95;
  transform: translateX(-50%) translateY(-4px);
}

/* ---------- watchlist ---------- */
.watchlist-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.watchlist-item:first-child { border-top: 0; }
.watchlist-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* ---------- bulk upload ---------- */
.bulk-progress {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.bulk-progress-cell {
  background: var(--tg-section-bg);
  padding: 12px 8px;
  text-align: center;
}
.bulk-progress-num {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
}
.bulk-progress-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tg-hint);
  margin-top: 2px;
}

/* ---------- admin ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.stat-cell {
  background: var(--tg-section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}
.stat-num  { font-family: var(--font-mono); font-size: 22px; font-weight: 600; }
.stat-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--tg-hint); margin-top: 4px; }

/* ---------- back link ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 0;
  color: var(--tg-link);
  font-size: 14px;
  padding: 4px 0 12px;
}
.back-link:active { opacity: 0.6; }
