/*
 * LF Audio unified admin theme.
 *
 * Loaded once at the shell root — every view module's inline CSS references
 * these vars (--lf-*). Lifted verbatim from the dark/light palette that used
 * to live inside admin-hub/nav.js; splitting it into a real stylesheet means
 * a palette change is one edit instead of a nav.js redeploy propagating to
 * six separate hosting origins.
 *
 * IMPORTANT: <link>'d from index.html BEFORE any view-specific CSS so the
 * vars are defined before first paint (no FOUC).
 */

:root {
  --lf-nav-h: 44px;
  /* Left list-panel width — shared across every two-pane view (CRM,
     RMA, Jobs, OTA Logs) so switching views doesn't shift the eye. */
  --lf-list-w: 340px;
  /* Right sidebar (customer card in CRM) — separate because it only
     exists in CRM today. */
  --lf-sidebar-w: 320px;

  /* Surfaces */
  --lf-bg: #0f1115;
  --lf-panel: #1a1d23;
  --lf-panel-alt: #14171c;
  --lf-panel-hover: #1f232b;

  /* Borders */
  --lf-border: #2a2e36;
  --lf-border-strong: #3a4150;

  /* Text */
  --lf-text: #e6e8ec;
  --lf-text-muted: #9aa0a6;
  --lf-text-dim: #6b7280;

  /* Accent */
  --lf-accent: #4f8cff;
  --lf-accent-hover: #6ba0ff;
  --lf-accent-bg: #1f2c44;
  --lf-accent-bg-hover: #27375a;
  --lf-accent-contrast: #ffffff;

  /* Status */
  --lf-success: #8fe29a;
  --lf-success-bg: #1f4d2e;
  --lf-success-border: rgba(143, 226, 154, 0.25);
  --lf-warn: #e2ce8f;
  --lf-warn-bg: #4d3e1f;
  --lf-warn-border: rgba(226, 206, 143, 0.25);
  --lf-error: #ff9aa2;
  --lf-error-bg: #4d1f28;
  --lf-error-border: rgba(255, 154, 162, 0.25);
  --lf-info: #8fb8e2;
  --lf-info-bg: #1f354d;
  --lf-info-border: rgba(143, 184, 226, 0.25);
  --lf-purple: #caa4ff;
  --lf-purple-bg: #3a1f4d;
  --lf-purple-border: rgba(202, 164, 255, 0.25);

  /* Form elements */
  --lf-input-bg: #0f1115;
  --lf-btn-bg: #2a2e36;
  --lf-btn-hover: #343942;

  /* Nav chrome */
  --lf-nav-bg: #0b0d12;
  --lf-nav-border: #2a2e36;
  --lf-nav-link: #9aa0a6;
  --lf-nav-link-hover-bg: #1a1d23;
  --lf-nav-brand: #e6e8ec;

  /* Shadows */
  --lf-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --lf-shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
}

html[data-theme="light"] {
  --lf-bg: #f5f6f8;
  --lf-panel: #ffffff;
  --lf-panel-alt: #f9fafb;
  --lf-panel-hover: #f3f4f6;

  --lf-border: #e5e7eb;
  --lf-border-strong: #d1d5db;

  --lf-text: #111827;
  --lf-text-muted: #4b5563;
  --lf-text-dim: #9ca3af;

  --lf-accent: #2563eb;
  --lf-accent-hover: #1d4ed8;
  --lf-accent-bg: #dbeafe;
  --lf-accent-bg-hover: #bfdbfe;
  --lf-accent-contrast: #ffffff;

  --lf-success: #16a34a;
  --lf-success-bg: #dcfce7;
  --lf-success-border: #bbf7d0;
  --lf-warn: #d97706;
  --lf-warn-bg: #fef3c7;
  --lf-warn-border: #fde68a;
  --lf-error: #dc2626;
  --lf-error-bg: #fee2e2;
  --lf-error-border: #fecaca;
  --lf-info: #2563eb;
  --lf-info-bg: #eff6ff;
  --lf-info-border: #bfdbfe;
  --lf-purple: #9333ea;
  --lf-purple-bg: #f3e8ff;
  --lf-purple-border: #e9d5ff;

  --lf-input-bg: #ffffff;
  --lf-btn-bg: #f3f4f6;
  --lf-btn-hover: #e5e7eb;

  --lf-nav-bg: #ffffff;
  --lf-nav-border: #e5e7eb;
  --lf-nav-link: #6b7280;
  --lf-nav-link-hover-bg: #f3f4f6;
  --lf-nav-brand: #111827;

  --lf-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --lf-shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* ── Reset + base ────────────────────────────────────────────────────── */

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--lf-bg);
  color: var(--lf-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  font-size: 14px;
}

body {
  padding-top: var(--lf-nav-h);
  min-height: 100dvh;
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ── Shell nav ───────────────────────────────────────────────────────── */

#lf-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--lf-nav-h);
  background: var(--lf-nav-bg);
  border-bottom: 1px solid var(--lf-nav-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 13px;
  color: var(--lf-text);
  z-index: 9999;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

#lf-nav .lf-nav-brand {
  font-weight: 700;
  color: var(--lf-nav-brand);
  padding-right: 14px;
  margin-right: 14px;
  border-right: 1px solid var(--lf-nav-border);
  letter-spacing: 0.3px;
}
#lf-nav .lf-nav-brand:hover { color: var(--lf-accent); }

#lf-nav .lf-nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

#lf-nav .lf-nav-link {
  color: var(--lf-nav-link);
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
}
#lf-nav .lf-nav-link:hover { background: var(--lf-nav-link-hover-bg); color: var(--lf-text); }
#lf-nav .lf-nav-link.active { background: var(--lf-accent-bg); color: var(--lf-accent); }
#lf-nav .lf-nav-link.denied { opacity: 0.35; pointer-events: none; }

#lf-nav .lf-nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--lf-text-muted);
  font-size: 12px;
  border-left: 1px solid var(--lf-nav-border);
  margin-left: 8px;
  height: 100%;
}
#lf-nav .lf-nav-user .lf-nav-email { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lf-nav .lf-nav-user .lf-nav-role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--lf-panel);
  color: var(--lf-text-muted);
}
#lf-nav .lf-nav-user .lf-nav-role.admin { background: var(--lf-accent-bg); color: var(--lf-accent); }

#lf-nav .lf-nav-signout {
  background: transparent;
  border: 1px solid var(--lf-nav-border);
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--lf-nav-link);
  font-size: 12px;
}
#lf-nav .lf-nav-signout:hover { background: var(--lf-nav-link-hover-bg); color: var(--lf-text); }

#lf-theme-toggle {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--lf-nav-border);
  border-radius: 8px;
  color: var(--lf-nav-link);
  margin-left: 8px;
  padding: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
#lf-theme-toggle:hover {
  background: var(--lf-nav-link-hover-bg);
  color: var(--lf-text);
  border-color: var(--lf-border-strong);
}
#lf-theme-toggle svg { width: 16px; height: 16px; }

@media (max-width: 760px) {
  #lf-nav .lf-nav-user { display: none; }
}
@media (max-width: 640px) {
  #lf-nav { padding: 0 10px; }
  #lf-nav .lf-nav-brand { padding-right: 10px; margin-right: 10px; font-size: 12px; letter-spacing: 0; }
  #lf-nav .lf-nav-links { gap: 2px; overflow-x: auto; flex-wrap: nowrap; }
  #lf-nav .lf-nav-link { padding: 5px 9px; font-size: 12px; white-space: nowrap; }
  #lf-theme-toggle { width: 28px; height: 28px; }
  #lf-theme-toggle svg { width: 14px; height: 14px; }
}
@media (max-width: 400px) {
  #lf-nav .lf-nav-brand { display: none; }
}

/* ── View container + shell states ───────────────────────────────────── */

#lf-view {
  min-height: calc(100dvh - var(--lf-nav-h));
}

.lf-shell-loading,
.lf-shell-auth,
.lf-shell-denied {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--lf-nav-h));
  padding: 40px 20px;
}
.lf-shell-card {
  background: var(--lf-panel);
  border: 1px solid var(--lf-border);
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--lf-shadow-lg);
}
.lf-shell-card h1 {
  margin: 0 0 8px 0;
  font-size: 20px;
  font-weight: 700;
}
.lf-shell-card p {
  margin: 0 0 20px 0;
  color: var(--lf-text-muted);
  font-size: 13px;
  line-height: 1.5;
}
.lf-shell-card button.lf-primary {
  background: var(--lf-accent);
  color: var(--lf-accent-contrast);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: 14px;
}
.lf-shell-card button.lf-primary:hover { background: var(--lf-accent-hover); }
.lf-shell-card .lf-error {
  color: var(--lf-error);
  font-size: 12px;
  margin-top: 12px;
}

.lf-flash {
  position: fixed;
  top: calc(var(--lf-nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--lf-panel);
  border: 1px solid var(--lf-border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--lf-text);
  box-shadow: var(--lf-shadow-lg);
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.lf-flash.show { opacity: 1; }
.lf-flash.error { border-color: var(--lf-error-border); color: var(--lf-error); }

/* ── Universal card container ─────────────────────────────────────── */
/* Shared visual grouping primitive. Any view can use these classes to
 * keep sections visually consistent with the Dashboard + Admin Users
 * tabs. Structure:
 *   <div class="lf-card">
 *     <div class="lf-card-head">Title <span class="lf-card-meta">...</span></div>
 *     <div class="lf-card-body">...</div>
 *   </div>
 */
.lf-card {
  background: var(--lf-panel);
  border: 1px solid var(--lf-border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--lf-shadow);
}
.lf-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.lf-card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--lf-text-muted);
  margin: 0;
}
.lf-card-meta {
  font-size: 11px;
  color: var(--lf-text-dim);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.lf-card-body {
  font-size: 13px;
  color: var(--lf-text);
  line-height: 1.5;
}
.lf-card-body > *:last-child { margin-bottom: 0; }

/* Compact variant for dense sections. */
.lf-card.lf-card-compact {
  padding: 14px 16px;
  margin-bottom: 12px;
}

/* Emphasize variant for the top-of-page identity/header card. */
.lf-card.lf-card-header {
  background: linear-gradient(135deg, var(--lf-panel), var(--lf-panel-alt));
}

/* ── Universal inline spinner for async buttons ───────────────────── */

.btn-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: lf-spin 0.7s linear infinite;
  vertical-align: -1px;
}
@keyframes lf-spin { to { transform: rotate(360deg); } }

/* When a button is swapped into its busy state: */
button.busy {
  pointer-events: none;
  cursor: wait;
  opacity: 0.85;
}
button:disabled {
  cursor: not-allowed;
}

/* ── Shell-wide dialog primitive ───────────────────────────────── */
/* Used by any view that needs a modal — RMA Create wizard, RMA
 * outbound-order picker, Admin Users add/edit, etc. Lives in theme.css
 * (not a view CSS) so dialogs open correctly regardless of which view
 * is currently mounted. */

.adm-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
}
.adm-dialog {
  background: var(--lf-panel);
  border: 1px solid var(--lf-border);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--lf-shadow-lg);
}
.adm-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--lf-border);
}
.adm-dialog-head h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--lf-text);
}
.adm-dialog-close {
  background: transparent;
  border: none;
  color: var(--lf-text-muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
}
.adm-dialog-close:hover { color: var(--lf-text); }
.adm-dialog-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.adm-dialog-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--lf-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Fields inside dialogs — shared form-field primitive. */
.adm-field {
  display: block;
  margin-bottom: 16px;
}
.adm-field > span {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--lf-text-muted);
  margin-bottom: 6px;
}
.adm-field input[type="email"],
.adm-field input[type="text"],
.adm-field input[type="url"],
.adm-field textarea,
.adm-field select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--lf-border);
  background: var(--lf-input-bg);
  color: var(--lf-text);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}
.adm-field textarea {
  min-height: 68px;
  resize: vertical;
}
.adm-field input:focus,
.adm-field textarea:focus,
.adm-field select:focus {
  outline: none;
  border-color: var(--lf-accent);
}
.adm-field input:disabled {
  opacity: 0.6;
}

/* Dialog buttons — small convenience primitive. */
.adm-btn {
  background: var(--lf-btn-bg);
  border: 1px solid var(--lf-border);
  color: var(--lf-text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.adm-btn:hover { background: var(--lf-btn-hover); }
.adm-btn-primary {
  background: var(--lf-accent);
  border-color: var(--lf-accent);
  color: var(--lf-accent-contrast);
}
.adm-btn-primary:hover {
  background: var(--lf-accent-hover);
  border-color: var(--lf-accent-hover);
}
.adm-btn-danger {
  color: var(--lf-error);
  border-color: var(--lf-error-border);
}
.adm-btn-danger:hover {
  background: var(--lf-error-bg);
}

/* Generic error banner used in dialogs + view bodies. */
.adm-error {
  color: var(--lf-error);
  background: var(--lf-error-bg);
  border: 1px solid var(--lf-error-border);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
}
