/**
 * Nexus Aviation LPI — digital-first minimalist SaaS theme
 * Light + dark mode token system layered onto the vanilla HTML/CSS app.
 */

:root {
  /* Fixed brand palette */
  --nexus-gold: #facc15;
  --nexus-gold-hover: #eab308;
  --nexus-gold-deep: #ca8a04;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-400: #94a3b8;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --emerald-600: #059669;
  --emerald-50: #ecfdf5;
  --rose-600: #e11d48;
  --rose-50: #fff1f2;

  /* Semantic tokens — light mode defaults */
  --nx-bg: var(--slate-50);
  --nx-surface: #ffffff;
  --nx-surface-2: var(--slate-50);
  --nx-border: var(--slate-200);
  --nx-text: var(--slate-900);
  --nx-muted: var(--slate-600);
  --nx-header-bg: #ffffff;
  --nx-nav-bg: #ffffff;
  --nx-highlight: #fef08a;
  --nx-highlight-soft: #fefce8;
  --nx-accent-on-active: var(--nexus-gold-deep);
  --nx-success-text: var(--emerald-600);
  --nx-success-bg: var(--emerald-50);
  --nx-success-border: #a7f3d0;
  --nx-danger-text: var(--rose-600);
  --nx-danger-bg: var(--rose-50);
  --nx-danger-border: #fecdd3;
  --nx-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --nx-shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07);
  --nx-shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12);
  --nx-scrollbar-thumb: #0b4f9e;
  --nx-scrollbar-thumb-hover: #084078;
  --nx-scrollbar-track: var(--slate-100);

  /* Responsive type scale (iPhone 12 → iPad → desktop) */
  --fs-body: clamp(0.875rem, 0.82rem + 0.25vw, 0.9375rem);
  --fs-label: clamp(0.8125rem, 0.79rem + 0.15vw, 0.875rem);
  --fs-note: clamp(0.72rem, 0.7rem + 0.1vw, 0.78rem);
  --fs-title: clamp(1.375rem, 1.15rem + 1.4vw, 1.875rem);
  --fs-section: clamp(0.95rem, 0.9rem + 0.4vw, 1.125rem);
  --fs-kpi: clamp(1.9rem, 1.35rem + 2.6vw, 2.75rem);

  /* Map onto base styles.css variables so it inherits the theme */
  --background: var(--nx-bg);
  --surface: var(--nx-surface);
  --surface-muted: var(--nx-surface-2);
  --border: var(--nx-border);
  --charcoal: var(--nx-text);
  --muted: var(--nx-muted);
  --impark-red: var(--nexus-gold);
  --primary-red: var(--nexus-gold);
  --impark-blue: var(--nx-muted);
  --aviation-blue: var(--nx-muted);
  --aviation-blue-dark: var(--nx-text);
  --success: var(--nx-success-text);
  --warning: var(--nexus-gold);
  --header-gradient: var(--nx-header-bg);
  --font-sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --shadow-sm: var(--nx-shadow-sm);
  --shadow-md: var(--nx-shadow-md);
}

[data-theme="dark"] {
  --nx-bg: #0b1220;
  --nx-surface: #131f33;
  --nx-surface-2: #0f1a2b;
  --nx-border: #26344b;
  --nx-text: #e8eef7;
  --nx-muted: #9fb0c7;
  --nx-header-bg: #0e1728;
  --nx-nav-bg: #0e1728;
  --nx-highlight: rgba(250, 204, 21, 0.18);
  --nx-highlight-soft: rgba(250, 204, 21, 0.1);
  --nx-accent-on-active: var(--nexus-gold);
  --nx-success-text: #34d399;
  --nx-success-bg: rgba(16, 185, 129, 0.16);
  --nx-success-border: rgba(16, 185, 129, 0.4);
  --nx-danger-text: #fb7185;
  --nx-danger-bg: rgba(244, 63, 94, 0.16);
  --nx-danger-border: rgba(244, 63, 94, 0.42);
  --nx-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --nx-shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --nx-shadow-lg: 0 20px 44px rgba(0, 0, 0, 0.55);
  --nx-scrollbar-thumb: #facc15;
  --nx-scrollbar-thumb-hover: #eab308;
  --nx-scrollbar-track: #0f1a2b;
}

html,
body {
  background: var(--nx-bg);
  height: 100%;
}

:root {
  --scrollbar-thumb: var(--nx-scrollbar-thumb);
  --scrollbar-thumb-hover: var(--nx-scrollbar-thumb-hover);
  --scrollbar-track: var(--nx-scrollbar-track);
}

.sites-status.is-error,
#sites-status.is-error,
.helper-text.is-error {
  color: var(--nx-danger-text) !important;
  font-weight: 600;
}

input.is-invalid,
textarea.is-invalid,
select.is-invalid {
  border-color: var(--nx-danger-text) !important;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--nx-danger-text) 24%, transparent);
}

label.has-error {
  color: var(--nx-danger-text);
}

body {
  color: var(--nx-text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
}

/* --- Header & shell --- */

.app-header {
  background: var(--nx-header-bg);
  color: var(--nx-text);
  border-bottom: 1px solid var(--nx-border);
  box-shadow: var(--nx-shadow-sm);
}

.header-icon-tile {
  background: #ffffff;
  box-shadow: var(--nx-shadow-sm);
}

.header-logo--wide {
  width: min(230px, 48vw);
  max-height: 34px;
}

.header-logo--ondark {
  display: none;
}

@media (min-width: 640px) {
  .header-logo--onlight {
    display: block;
  }
  .header-logo--ondark {
    display: none;
  }
  [data-theme="dark"] .header-logo--onlight {
    display: none;
  }
  [data-theme="dark"] .header-logo--ondark {
    display: block;
  }
}

.sync-status {
  color: var(--nx-muted);
  font-size: var(--fs-note);
}

.status-dot {
  background: var(--nx-success-text);
}

.status-dot.offline {
  background: var(--nx-danger-text);
}

/* Icon buttons in header (theme toggle + logout) */
.header-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--nx-border);
  background: var(--nx-surface-2);
  color: var(--nx-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.header-icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.header-icon-btn:hover,
.header-icon-btn:focus-visible {
  background: var(--nx-highlight);
  color: var(--nx-text);
  border-color: var(--nexus-gold);
  outline: none;
}

.header-logout-btn {
  border: 1px solid var(--nx-border);
  color: var(--nx-muted);
  background: var(--nx-surface-2);
}

.header-logout-btn:hover,
.header-logout-btn:focus-visible {
  background: var(--nx-highlight);
  color: var(--nx-text);
}

.workspace {
  gap: 1.5rem;
  padding: 1.5rem 1.25rem 1rem;
}

.page-head {
  margin-bottom: 0.25rem;
}

.page-head h1 {
  font-size: var(--fs-title);
  font-weight: 700;
  color: var(--nx-text);
  letter-spacing: -0.02em;
}

/* --- Navigation --- */

.bottom-nav {
  background: var(--nx-nav-bg);
  border-top: 1px solid var(--nx-border);
  box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
}

.nav-item {
  color: var(--nx-muted);
}

.nav-item-icon svg {
  fill: currentColor;
}

.nav-item.active,
.nav-item:hover {
  color: var(--nx-text);
  background: var(--nx-highlight);
}

.nav-item.active .nav-item-icon svg {
  fill: var(--nx-accent-on-active);
}

/* --- Typography & badges --- */

.badge,
.beta-badge,
.beta-badge--rail {
  background: var(--nx-highlight);
  color: var(--nx-text);
  border: 1px solid var(--nexus-gold);
}

.section-heading h2,
.section-heading h3,
.table-heading h3,
.search-results h3 {
  font-size: var(--fs-section);
  font-weight: 600;
  color: var(--nx-muted);
}

.eyebrow {
  color: var(--nx-muted);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.helper-text,
.footer,
.field-optional {
  color: var(--nx-muted);
}

/* --- Buttons --- */

.primary-button {
  background: var(--nexus-gold);
  color: var(--slate-900);
  font-weight: 700;
  box-shadow: var(--nx-shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.primary-button:hover {
  background: var(--nexus-gold-hover);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.primary-button .btn-icon svg,
.secondary-button .btn-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.secondary-button {
  border: 1px solid var(--nx-border);
  color: var(--nx-text);
  background: var(--nx-surface);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.secondary-button:hover {
  background: var(--nx-highlight-soft);
  border-color: var(--nexus-gold);
}

.danger-button {
  border-color: var(--nx-danger-border) !important;
  color: var(--nx-danger-text) !important;
  background: transparent !important;
}

.danger-button:hover {
  background: var(--nx-danger-bg) !important;
}

.text-button {
  color: var(--nx-text);
}

/* --- Cards & panels --- */

.panel,
.metric,
.entry-grid,
.table-wrap,
.message,
.login-card,
.login-panel,
.search-results,
.edit-meta {
  background: var(--nx-surface);
  border-color: var(--nx-border);
  box-shadow: var(--nx-shadow-sm);
}

.metric-grid,
.workflow-grid,
.eod-metric-grid {
  gap: 1.25rem;
  margin-top: 0.5rem;
}

.metric {
  gap: 0.5rem;
  padding: 1.25rem 1.125rem;
}

.metric span {
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--nx-muted);
}

.metric strong {
  font-size: var(--fs-kpi);
  font-weight: 600;
  color: var(--nx-text);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.metric-note {
  font-size: var(--fs-note);
  color: var(--nx-muted);
}

.metric--highlight {
  background: var(--nx-highlight);
  border-color: var(--nexus-gold);
}

.metric--highlight strong {
  color: var(--nx-text);
}

.active-view {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.active-view > * {
  min-width: 0;
  max-width: 100%;
}

/* --- Tables --- */

table {
  min-width: 560px;
}

th {
  color: var(--nx-muted);
  background: var(--nx-surface-2);
  font-size: var(--fs-note);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--nx-border);
}

td {
  color: var(--nx-text);
  border-bottom: 1px solid var(--nx-border);
  font-size: var(--fs-label);
}

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

/* --- Status badges (icon + label) --- */

.sync-chip {
  gap: 5px;
  padding: 3px 10px 3px 8px;
  font-weight: 600;
  font-size: var(--fs-note);
  color: var(--nx-muted);
  background: var(--nx-surface-2);
  border: 1px solid var(--nx-border);
}

.sync-chip-icon {
  display: inline-flex;
  align-items: center;
}

.sync-chip-icon svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.sync-chip.synced,
.sync-chip.completed {
  color: var(--nx-success-text);
  background: var(--nx-success-bg);
  border-color: var(--nx-success-border);
}

.sync-chip.pending {
  color: var(--nx-danger-text);
  background: var(--nx-danger-bg);
  border-color: var(--nx-danger-border);
}

.tab-btn {
  color: var(--nx-muted);
  border-color: var(--nx-border);
  background: var(--nx-surface);
}

.tab-btn.active {
  color: var(--slate-900);
  background: var(--nexus-gold);
  border-color: var(--nexus-gold);
}

.tab-btn:hover:not(.active) {
  background: var(--nx-highlight-soft);
}

/* --- Forms & inputs --- */

label {
  color: var(--nx-muted);
  font-size: var(--fs-label);
  font-weight: 600;
}

input,
select {
  background: var(--nx-surface);
  border-color: var(--nx-border);
  color: var(--nx-text);
}

input::placeholder {
  color: var(--slate-400);
}

input:focus,
select:focus {
  border-color: var(--nexus-gold-deep);
  outline: 2px solid rgba(250, 204, 21, 0.35);
  outline-offset: 0;
}

/* Prevent iOS zoom on focus for phones */
@media (max-width: 640px) {
  input,
  select {
    font-size: 16px;
  }

  #plate-search-input {
    font-size: 18px;
  }
}

.search {
  background: var(--nx-surface);
  border-color: var(--nx-border);
  color: var(--nx-text);
}

.message {
  color: var(--nx-text);
}

.message--error {
  color: var(--nx-danger-text);
  background: var(--nx-danger-bg);
  border-color: var(--nx-danger-border);
}

.search-sync-status {
  background: var(--nx-surface-2);
  border-color: var(--nx-border);
  color: var(--nx-muted);
}

.search-sync-status--error {
  color: var(--nx-danger-text);
  background: var(--nx-danger-bg);
  border-color: var(--nx-danger-border);
}

.help-details summary {
  color: var(--nx-muted);
  border-color: var(--nx-border);
}

.help-details summary:hover,
.help-details[open] summary {
  color: var(--nx-text);
  border-color: var(--nexus-gold);
  background: var(--nx-highlight);
}

.help-details-body {
  color: var(--nx-muted);
}

/* --- Login & setup branding --- */

.login-brand-block {
  background: linear-gradient(145deg, #ffffff 0%, #eef2f7 100%);
  border: 1px solid var(--nx-border);
  box-shadow: var(--nx-shadow-md);
}

.login-brand-frame {
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.login-brand--mark {
  width: 56px;
  height: 56px;
}

.login-brand--wordmark {
  width: min(300px, 78%);
  height: auto;
}

.setup-brand {
  background: #ffffff;
  border-color: var(--nx-border);
}

.setup-logo {
  width: min(280px, 70%);
  height: auto;
}

.setup-brand-frame {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

[data-theme="dark"] #setup .setup-brand--compact {
  padding: 8px 12px;
  border-radius: 12px;
  background: linear-gradient(145deg, #ffffff 0%, #f4f7fb 55%, #eef2f7 100%);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.65),
    0 6px 18px rgba(8, 64, 120, 0.12);
}

[data-theme="dark"] #setup .setup-brand-frame {
  padding: 6px 10px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
}

/* --- Scan modal --- */

.scan-modal-panel {
  background: var(--nx-surface);
  color: var(--nx-text);
  border: 1px solid var(--nx-border);
}

.scan-modal-head h3 {
  color: var(--nx-text);
}

/* --- Desktop rail: main column fills viewport; scrollbar stays at the right edge --- */

@media (min-width: 1024px) {
  .workspace {
    padding: 2rem 2.5rem 2rem 2rem;
    width: 100%;
    max-width: none;
    margin-inline: 0;
    justify-self: stretch;
    align-self: stretch;
  }

  .side-rail.is-visible {
    background: var(--nx-surface);
    color: var(--nx-text);
    border-right: 1px solid var(--nx-border);
    box-shadow: var(--nx-shadow-sm);
  }

  .rail-logo {
    background: #ffffff;
    box-shadow: var(--nx-shadow-sm);
  }

  .rail-nav .nav-item {
    color: var(--nx-muted);
  }

  .rail-nav .nav-item.active,
  .rail-nav .nav-item:hover {
    color: var(--nx-text);
    background: var(--nx-highlight);
  }

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

  .rail-nav .nav-item.active .nav-item-icon svg {
    fill: var(--nx-accent-on-active);
  }

  .rail-nav .nav-item.nav-item--done {
    color: var(--nx-muted) !important;
    opacity: 0.6;
  }

  .operator-card {
    border: 1px solid var(--nx-border);
    background: var(--nx-surface-2);
    color: var(--nx-text);
  }

  .operator-card .label {
    color: var(--nx-muted);
  }
}

/* --- Header connection pill (readable in light + dark) --- */

.app-header .sync-status {
  color: var(--nx-muted);
  background: var(--nx-surface-2);
  border-color: var(--nx-border);
}

[data-theme="dark"] .app-header .sync-status {
  color: var(--nx-text);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.14);
}

.app-header .sync-status #connection-label {
  color: inherit;
}

/* --- Operator card (rail) readable in light + dark --- */

.operator-card {
  border-color: var(--nx-border);
  background: var(--nx-surface-2);
}

.operator-card span,
.operator-card .label {
  color: var(--nx-muted);
}

.operator-card strong {
  color: var(--nx-text);
}

/* --- Plate-style inputs: always readable white "plate" look --- */

.plate-field input,
#plate-search-input,
#edit-plate-input,
.search {
  background: #ffffff;
  color: var(--slate-900);
}

.plate-field input::placeholder,
#plate-search-input::placeholder,
.search::placeholder {
  color: var(--slate-400);
}

/* --- Search result (found) type scale --- */

#plate-search-result.message--plate-result.visible {
  font-size: var(--fs-body);
  line-height: 1.5;
  padding: 14px 16px;
}

.search-notice-header {
  font-size: var(--fs-section);
}

.search-notice-line1 {
  font-size: var(--fs-section);
}

.search-notice-line2 {
  font-size: var(--fs-label);
}

/* --- Page title row + mobile scan icon on the title line --- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.page-head h1 {
  min-width: 0;
}

.page-scan-btn {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: var(--nexus-gold);
  color: var(--slate-900);
  cursor: pointer;
  box-shadow: var(--nx-shadow-sm);
}

.page-scan-btn .btn-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.page-scan-btn:hover,
.page-scan-btn:focus-visible {
  background: var(--nexus-gold-hover);
  outline: 2px solid rgba(250, 204, 21, 0.45);
  outline-offset: 1px;
}

/* On phones, use the compact icon beside the title and hide the full row */
@media (max-width: 666px) {
  body[data-active-view="capture"] .page-scan-btn {
    display: inline-flex;
  }

  body[data-active-view="capture"] .capture-scan-row {
    display: none;
  }
}

/* --- Desktop: workspace scrolls at the browser edge --- */

@media (min-width: 1024px) {
  .app-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .side-rail.is-visible {
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }
}

/* --- End-of-day notification bar: airier letter spacing --- */

#end-day-message {
  letter-spacing: 0.05em;
  line-height: 1.6;
}

/* --- Lot page: larger bold value on the dashboard cards --- */

#location .metric strong {
  font-size: clamp(2.1rem, 1.55rem + 3vw, 3.1rem);
  overflow-wrap: anywhere;
}

/* --- Phone (iPhone 12 ~390px) --- */

@media (max-width: 640px) {
  .workspace {
    padding: 1rem;
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .metric {
    padding: 1rem;
  }

  .sync-status span:last-child {
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* --- Branded confirmation dialog (End of Day, etc.) --- */
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.confirm-modal[hidden] {
  display: none;
}

.confirm-modal-panel {
  width: min(420px, 100%);
  background: var(--nx-surface);
  color: var(--nx-text);
  border: 1px solid var(--nx-border);
  border-radius: 16px;
  box-shadow: var(--nx-shadow-lg);
  padding: 22px 22px 18px;
}

.confirm-modal-title {
  margin: 0 0 10px;
  font-size: clamp(1.15rem, 1rem + 0.7vw, 1.35rem);
  font-weight: 600;
  color: var(--nx-text);
}

.confirm-modal-body {
  margin: 0 0 20px;
  color: var(--nx-muted);
  font-size: var(--fs-body, 0.95rem);
  line-height: 1.55;
}

.confirm-modal-body p {
  margin: 0 0 8px;
}

.confirm-modal-body p:last-child {
  margin-bottom: 0;
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-modal-actions .primary-button,
.confirm-modal-actions .secondary-button {
  min-width: 108px;
}

.confirm-modal-actions .primary-button.is-danger {
  background: var(--nx-danger-text);
  border-color: var(--nx-danger-text);
  color: #ffffff;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 666px) {
  .confirm-modal-actions {
    flex-direction: column-reverse;
  }
  .confirm-modal-actions .primary-button,
  .confirm-modal-actions .secondary-button {
    width: 100%;
  }
}

/* --- Toast notifications (replaces native alert) --- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--nx-surface);
  color: var(--nx-text);
  border: 1px solid var(--nx-border);
  border-left: 4px solid var(--nx-muted);
  box-shadow: var(--nx-shadow-lg);
  font-size: var(--fs-body, 0.95rem);
  line-height: 1.45;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast--success {
  border-left-color: var(--nx-success-text);
}

.toast--error {
  border-left-color: var(--nx-danger-text);
}

/* --- Desktop: center the login card + footer (single column, not left-pinned) --- */
@media (min-width: 900px) {
  .login-layout {
    grid-template-columns: minmax(0, 520px);
    justify-content: center;
  }
}

