/**
 * Integrity Fix — Preview v2 theme
 * Layers on top of ../css/styles.css — does not replace production styles.
 */

html.ifx-redesign {
  --bg: #0c1222;
  --surface: #141c2e;
  --surface2: #1a2438;
  --surface-card: #1e2a42;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #2a3a55;
  --blue: #0ea5e9;
  --blue-dark: #0284c7;
  --blue-glow: rgba(14, 165, 233, 0.25);
  --orange: #f97316;
  --orange-dark: #ea580c;
  --ok: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.35);
  --touch-min: 48px;
}

html.ifx-redesign body {
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(14, 165, 233, 0.12), transparent 50%),
    radial-gradient(ellipse 80% 50% at 100% 100%, rgba(249, 115, 22, 0.06), transparent 45%),
    var(--bg);
}

/* ——— Preview banner ——— */
.ifx-redesign-banner {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  padding: 0.5rem 0.75rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  background: linear-gradient(90deg, #0c4a6e, #0369a1 40%, #0c4a6e);
  border-bottom: 2px solid var(--orange);
  font-size: 0.8rem;
  color: #e0f2fe;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.ifx-redesign-badge {
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--orange);
  color: #fff;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.ifx-redesign-banner-link {
  color: #fff;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ifx-redesign-banner-link:hover { color: #bae6fd; }

/* ——— Status bar (offline + autosave) ——— */
.ifx-status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}

.ifx-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
}

.ifx-status-pill.online { border-color: rgba(34, 197, 94, 0.4); color: #86efac; }
.ifx-status-pill.offline { border-color: rgba(249, 115, 22, 0.5); color: #fdba74; }
.ifx-status-pill.saved { border-color: rgba(14, 165, 233, 0.4); color: #7dd3fc; }

.ifx-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* ——— App shell ——— */
html.ifx-redesign {
  --ifx-banner-h: 2.75rem;
  --ifx-status-h: 2.25rem;
  --ifx-trial-h: 3.25rem;
}

html.ifx-redesign:not(:has(#ifx-redesign-banner)) {
  --ifx-banner-h: 0rem;
}

html.ifx-redesign .app-shell {
  min-height: 100dvh;
}

/* Keep sidebar + workspace columns even when v2 chrome is injected */
@media (min-width: 901px) {
  html.ifx-redesign .app-shell:not(.app-locked):not(.shell-hidden) {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: start;
  }

  html.ifx-redesign .app-shell > .nav {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: calc(var(--ifx-banner-h) + var(--ifx-status-h) + env(safe-area-inset-top, 0px));
    max-height: calc(100dvh - var(--ifx-banner-h) - var(--ifx-status-h) - env(safe-area-inset-top, 0px));
    overflow-y: auto;
  }

  html.ifx-redesign .app-shell > .main {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    width: 100%;
  }

  html.ifx-redesign body.trial-demo-active .app-shell > .nav {
    top: calc(var(--ifx-banner-h) + var(--ifx-status-h) + var(--ifx-trial-h) + env(safe-area-inset-top, 0px));
    max-height: calc(100dvh - var(--ifx-banner-h) - var(--ifx-status-h) - var(--ifx-trial-h) - env(safe-area-inset-top, 0px));
  }
}

html.ifx-redesign .nav {
  background: linear-gradient(180deg, var(--surface2) 0%, var(--surface) 100%);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
}

html.ifx-redesign .nav h1 {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

html.ifx-redesign .nav button[data-section] {
  min-height: var(--touch-min);
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

html.ifx-redesign .nav button[data-section].active {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  color: #fff;
  box-shadow: 0 4px 14px var(--blue-glow);
}

html.ifx-redesign .nav button[data-section]:not(.active):hover {
  background: rgba(14, 165, 233, 0.12);
}

/* Step progress (boilermaker / inspector) */
.ifx-step-progress {
  padding: 0.65rem 0.85rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.ifx-step-progress-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ifx-step-progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.ifx-step-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--orange));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.ifx-step-progress-steps {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.65rem;
  color: var(--muted);
}

.ifx-step-progress-steps .done { color: var(--blue); font-weight: 700; }
.ifx-step-progress-steps .current { color: var(--orange); font-weight: 700; }

/* ——— Main content ——— */
html.ifx-redesign .main {
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
}

html.ifx-redesign .app-head {
  background: transparent;
  padding-top: 0.5rem;
}

html.ifx-redesign .app-head-sub {
  color: var(--muted);
}

html.ifx-redesign .role-badge {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

html.ifx-redesign .panel {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.15rem 1.1rem;
  margin-bottom: 1rem;
  transition: box-shadow 0.2s;
}

html.ifx-redesign .panel h2 {
  margin-top: 0;
  font-size: 1.1rem;
  color: var(--text);
  border-bottom: 2px solid var(--blue);
  padding-bottom: 0.45rem;
  margin-bottom: 0.75rem;
}

html.ifx-redesign .hint {
  color: var(--muted);
  line-height: 1.5;
}

/* ——— Buttons ——— */
html.ifx-redesign .btn {
  min-height: var(--touch-min);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
}

html.ifx-redesign .btn:active { transform: scale(0.98); }

html.ifx-redesign .btn-primary {
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue) 100%);
  border: none;
  color: #fff;
  box-shadow: 0 4px 16px var(--blue-glow);
}

html.ifx-redesign .btn-primary:hover {
  box-shadow: 0 6px 22px rgba(14, 165, 233, 0.4);
}

html.ifx-redesign .btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

html.ifx-redesign .btn-danger {
  background: linear-gradient(135deg, #991b1b, var(--danger));
}

/* ——— Inputs ——— */
html.ifx-redesign input,
html.ifx-redesign select,
html.ifx-redesign textarea {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  caret-color: var(--text);
  -webkit-text-fill-color: var(--text);
  font-size: 16px;
  min-height: var(--touch-min);
  transition: border-color 0.2s, box-shadow 0.2s;
}

html.ifx-redesign input::placeholder,
html.ifx-redesign textarea::placeholder {
  color: var(--muted);
  opacity: 1;
  -webkit-text-fill-color: var(--muted);
}

html.ifx-redesign input:-webkit-autofill,
html.ifx-redesign input:-webkit-autofill:hover,
html.ifx-redesign input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text) !important;
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset !important;
  box-shadow: 0 0 0 1000px var(--bg) inset !important;
  caret-color: var(--text);
}

html.ifx-redesign input:focus,
html.ifx-redesign select:focus,
html.ifx-redesign textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

/* ——— Cards: folders & reports ——— */
html.ifx-redesign .folder-row,
html.ifx-redesign .folder-row.report-row {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  transition: border-color 0.2s, transform 0.15s;
}

html.ifx-redesign .folder-row:hover,
html.ifx-redesign .folder-row.selected {
  border-color: var(--blue);
}

html.ifx-redesign .folder-row.selected {
  box-shadow: 0 0 0 1px var(--blue), 0 4px 16px var(--blue-glow);
}

html.ifx-redesign .folder-open {
  cursor: pointer;
}

html.ifx-redesign .folder-icon {
  font-size: 1.25rem;
}

/* Supervisor quick search — pinned below header on all supervisor tabs */
html.ifx-redesign #supervisor-shell .ifx-supervisor-search {
  margin: 0 0.65rem 1rem;
  padding: 0;
}

.ifx-supervisor-search {
  margin-bottom: 0.85rem;
}

.ifx-supervisor-search input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.5rem;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 0.85rem center;
  box-sizing: border-box;
}

/* ——— Photo / drop zones ——— */
html.ifx-redesign .drop-zone,
html.ifx-redesign .photo-slot,
html.ifx-redesign .insp-drop {
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);
  background: rgba(14, 165, 233, 0.04);
  min-height: 120px;
  transition: border-color 0.2s, background 0.2s;
}

html.ifx-redesign .drop-zone:hover,
html.ifx-redesign .photo-slot:hover {
  border-color: var(--blue);
  background: rgba(14, 165, 233, 0.08);
}

html.ifx-redesign .ifx-add-photo-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 52px;
  margin-top: 0.5rem;
  font-weight: 700;
  color: var(--blue);
}

/* ——— Top bar / report number ——— */
html.ifx-redesign .top-bar {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.85rem;
}

html.ifx-redesign .report-no {
  font-weight: 700;
  color: var(--blue);
  letter-spacing: 0.04em;
}

/* ——— Export panel ——— */
html.ifx-redesign .export-panel {
  text-align: center;
  border: 2px solid var(--blue);
  background: linear-gradient(180deg, var(--surface-card), var(--surface2));
}

html.ifx-redesign .export-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

html.ifx-redesign .export-actions .btn {
  width: 100%;
}

/* ——— Modals ——— */
html.ifx-redesign .modal-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

html.ifx-redesign .toast.show {
  background: var(--surface-card);
  border: 1px solid var(--blue);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-sm);
}

/* ——— Mobile bottom nav ——— */
.ifx-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10080;
  pointer-events: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  touch-action: manipulation;
}

.ifx-bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  padding: 0.35rem 0.25rem;
  max-width: 640px;
  margin: 0 auto;
}

.ifx-bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-height: 52px;
  padding: 0.35rem 0.25rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
  border-radius: 10px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ifx-bottom-nav button .ifx-nav-icon { font-size: 1.2rem; }

.ifx-bottom-nav button.active {
  color: var(--blue);
  background: rgba(14, 165, 233, 0.12);
}

.ifx-bottom-nav button.ifx-nav-pressed,
.ifx-bottom-nav button:active {
  color: var(--blue);
  background: rgba(14, 165, 233, 0.2);
  transform: scale(0.96);
  transition: none;
}

@media (max-width: 1024px) {
  html.ifx-redesign .app-shell {
    display: block;
  }

  html.ifx-redesign .app-shell > .main {
    display: block;
    min-height: 50vh;
    overflow-x: hidden;
    overflow-y: visible;
  }

  html.ifx-redesign .nav {
    position: sticky;
    top: calc(var(--ifx-banner-h) + var(--ifx-status-h) + env(safe-area-inset-top, 0px));
    z-index: 90;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.4rem;
    gap: 0.35rem;
    -webkit-overflow-scrolling: touch;
  }

  html.ifx-redesign body.trial-demo-active .nav {
    top: calc(var(--ifx-banner-h) + var(--ifx-status-h) + var(--ifx-trial-h) + env(safe-area-inset-top, 0px));
  }

  html.ifx-redesign .nav .brand-lock,
  html.ifx-redesign .nav h1 {
    display: none;
  }

  html.ifx-redesign .nav .nav-actions {
    flex: 0 0 auto;
    flex-direction: row;
    margin-left: auto;
    padding-top: 0;
    gap: 0.3rem;
  }

  html.ifx-redesign .nav .nav-actions .btn-sm {
    min-height: 40px;
    font-size: 0.72rem;
    padding: 0.35rem 0.5rem;
    white-space: nowrap;
  }

  html.ifx-redesign .nav button[data-section] {
    display: none !important;
  }

  html.ifx-redesign .nav {
    justify-content: flex-end;
    min-height: 0;
    padding: 0.35rem 0.5rem;
    border-bottom: none;
    box-shadow: none;
    background: transparent;
    position: relative;
    top: auto;
  }

  .ifx-bottom-nav.ifx-bottom-nav-show {
    display: block;
  }

  .ifx-bottom-nav button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
  }

  html.ifx-redesign .main {
    padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* ——— Login preview ——— */
.ifx-redesign-login .ifx-v2-login {
  min-height: 100dvh;
  padding-top: 3rem;
}

.ifx-redesign-banner-login {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.ifx-v2-login-card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

.ifx-v2-login-tag {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--blue);
  font-weight: 600;
}

.ifx-v2-demo-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.ifx-v2-demo-hint code {
  font-size: 0.76rem;
  color: var(--text);
}

.ifx-v2-login .cloud-login-page {
  background:
    radial-gradient(ellipse at top, rgba(14, 165, 233, 0.2) 0%, transparent 55%),
    var(--bg);
}

.ifx-redesign-login .cloud-login-form input[type="email"],
.ifx-redesign-login .cloud-login-form input[type="password"],
.ifx-redesign-login .cloud-login-form input[type="text"] {
  width: 100%;
  padding: 0.75rem 0.8rem;
  margin-bottom: 0.85rem;
  color: var(--text);
  caret-color: var(--text);
  -webkit-text-fill-color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 16px;
  min-height: 44px;
}

.ifx-redesign-login .cloud-login-form input::placeholder {
  color: var(--muted);
  opacity: 1;
  -webkit-text-fill-color: var(--muted);
}

.ifx-redesign-login .cloud-login-form input:-webkit-autofill,
.ifx-redesign-login .cloud-login-form input:-webkit-autofill:hover,
.ifx-redesign-login .cloud-login-form input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text) !important;
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset !important;
  box-shadow: 0 0 0 1000px var(--bg) inset !important;
  caret-color: var(--text);
}

.ifx-redesign-login .cloud-login-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.ifx-offline-login-banner {
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.35);
  border-radius: var(--radius-sm);
}

.ifx-offline-login-banner.hidden { display: none; }

.ifx-offline-continue-btn {
  width: 100%;
  margin-top: 0.5rem;
}

.login-org-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.login-org-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.login-org-btn:hover {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.35);
}

.login-org-btn img {
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
}

/* Trial bar */
html.ifx-redesign .trial-demo-bar {
  background: var(--surface2);
  border-bottom: 1px solid var(--orange);
}

/* Upload loading — v2 style */
html.ifx-redesign .upload-loading-card {
  border-color: var(--blue);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

html.ifx-redesign .upload-loading-spinner {
  border-top-color: var(--blue);
}