@import url("palette.css");

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--color-bg) url("APL-T2B-Background.jpg") center center / cover no-repeat fixed;
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  padding: 0 0 60px;
}

/* ---------------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------------- */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 16px 0;
}

/* ---------------------------------------------------------------------------
   Environment Footer
   --------------------------------------------------------------------------- */
.env-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 6px 0;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  z-index: 200;
}

.env-footer--dev     { background: #dc2626; }  /* red */
.env-footer--uat     { background: #d97706; }  /* amber */
.env-footer--staging { background: #2563eb; }  /* blue */

/* PROD-only: subtle fixed corner label carrying the build version so support
   can triage which deploy a user is on. Unobtrusive and pointer-transparent. */
.app-version {
  position: fixed;
  bottom: 6px;
  right: 10px;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  z-index: 150;
  pointer-events: none;
  user-select: none;
}

/* ---------------------------------------------------------------------------
   Site Header (full-width nav bar)
   --------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-header-bg);
  border-bottom: 1px solid var(--color-header-border);
  box-shadow: var(--shadow-md);
}

.site-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.site-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-header-text);
}

.user-menu {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--color-header-text);
}

.user-menu .user-email {
  opacity: 0.85;
}

.user-menu .user-signout {
  color: var(--color-header-text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.user-menu .user-signout:hover {
  opacity: 0.8;
}

.hero-signed-in {
  margin-top: 14px;
  font-size: 0.9rem;
  color: var(--color-muted, #666);
}

.hero-signed-in a {
  color: var(--color-primary);
  text-decoration: underline;
}

@media (max-width: 640px) {
  .user-menu .user-email { display: none; }
}

/* ---------------------------------------------------------------------------
   Cards
   --------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

/* ---------------------------------------------------------------------------
   Info Section
   --------------------------------------------------------------------------- */
.info-section {
  margin-bottom: 20px;
}

.info-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-heading-2);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-section h2 .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-info-badge-bg);
  color: var(--color-primary);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 480px) {
  .info-grid { grid-template-columns: 1fr; }
}

.info-box {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.info-box h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.info-box-what {
  background: var(--color-infobox-what-bg);
  border-color: var(--color-infobox-what-border);
}
.info-box-what h3 { color: var(--color-infobox-what-heading); }

.info-box-supported {
  background: var(--color-infobox-sup-bg);
  border-color: var(--color-infobox-sup-border);
}
.info-box-supported h3 { color: var(--color-infobox-sup-heading); }

.info-box p {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.directions-list {
  list-style: none;
  padding: 0;
  margin-top: 16px;
  counter-reset: step;
}

.directions-list li {
  position: relative;
  padding-left: 36px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: var(--color-text);
  line-height: 1.5;
}

.directions-list li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------------------------------------------------------------
   Timing Estimate Panel
   --------------------------------------------------------------------------- */
.timing-panel {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--color-infobox-what-bg);
  border: 1px solid var(--color-infobox-what-border);
  border-radius: var(--radius-sm);
}

.timing-panel-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  line-height: 1.4;
}

.timing-panel-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-infobox-what-heading);
  margin-bottom: 4px;
}

.timing-panel-text {
  font-size: 0.83rem;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.timing-cat {
  font-weight: 600;
  color: var(--color-text);
}

.timing-breakdown {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.size-estimate {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 4px;
  text-align: center;
}

/* ---------------------------------------------------------------------------
   Upload Area
   --------------------------------------------------------------------------- */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 16px;
}

.drop-zone:hover {
  border-color: var(--color-border-hover);
  background: var(--color-dropzone-hover-bg);
}

.drop-zone.dragover {
  border-color: var(--color-primary);
  background: var(--color-dropzone-dragover-bg);
}

.drop-zone:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-color: var(--color-primary);
}

.drop-zone svg {
  display: block;
  margin: 0 auto 12px;
  color: var(--color-text-muted);
}

.drop-zone p {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.browse-link {
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.browse-link:hover {
  text-decoration: underline;
}

#file-input { display: none; }

.selected-file {
  font-size: 0.85rem;
  color: var(--color-primary);
  font-weight: 500;
  min-height: 1.2em;
  margin-bottom: 4px;
}

.selected-file.file-error {
  color: var(--color-error);
}

.selected-file-size {
  color: var(--color-text-muted);
  font-weight: 400;
  margin-left: 0.2rem;
}

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
button[type="submit"],
.download-btn,
.reset-btn {
  display: block;
  width: 100%;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  text-align: center;
  text-decoration: none;
  transition: background var(--transition), transform 0.1s ease, box-shadow var(--transition);
}

button[type="submit"] {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
button[type="submit"]:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow);
}
button[type="submit"]:active:not(:disabled) {
  transform: scale(0.99);
}
button[type="submit"]:disabled {
  background: var(--color-disabled-btn);
  cursor: not-allowed;
}

.download-btn {
  background: var(--color-success);
  color: #fff;
  margin-top: 12px;
  box-shadow: var(--shadow-sm);
}
.download-btn:hover {
  background: var(--color-success);
  box-shadow: var(--shadow);
}

.reset-btn {
  background: var(--color-reset-btn);
  color: var(--color-reset-btn-text);
  border: none;
  margin-top: 10px;
}
.reset-btn:hover {
  background: var(--color-reset-btn-hover);
}

.cancel-btn {
  display: block;
  width: 100%;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--color-error);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-error);
  text-align: center;
  margin-top: 12px;
  transition: background var(--transition), color var(--transition);
}
.cancel-btn:hover {
  background: var(--color-error);
  color: #fff;
}

/* ---------------------------------------------------------------------------
   Progress Steps
   --------------------------------------------------------------------------- */
.steps {
  display: flex;
  align-items: flex-start;
  margin-bottom: 20px;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.step-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  transition: background var(--transition);
}

.step.inactive .step-icon {
  background: var(--color-inactive-step);
  color: var(--color-inactive-text);
}

.step.done .step-icon {
  background: var(--color-success);
}

.step-label {
  font-size: 0.75rem;
  text-align: center;
  max-width: 80px;
  color: var(--color-text-muted);
  line-height: 1.3;
}

.step:not(.inactive) .step-label {
  color: var(--color-text);
  font-weight: 600;
}

.step-connector {
  flex: 1;
  height: 2px;
  background: var(--color-border);
  margin-top: 17px; /* vertically center with icon */
  min-width: 20px;
}

/* ---------------------------------------------------------------------------
   Progress Bar — thin bar under the 3-step indicator that reinforces the
   ETA-driven countdown. Determinate when we have a timing estimate,
   indeterminate (sliding) when we don't.
   --------------------------------------------------------------------------- */
.progress-bar {
  position: relative;
  width: 100%;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-bar-fill {
  height: 100%;
  width: 0;
  background: var(--color-primary);
  border-radius: 2px;
  transition: width 500ms linear, background var(--transition);
}

.progress-bar.indeterminate .progress-bar-fill {
  width: 40%;
  animation: progressSlide 1.4s ease-in-out infinite;
}

.progress-bar.complete .progress-bar-fill {
  background: var(--color-success);
}

@keyframes progressSlide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* ---------------------------------------------------------------------------
   Spinner
   --------------------------------------------------------------------------- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.step.inactive .spinner {
  border-color: rgba(0, 0, 0, 0.1);
  border-top-color: var(--color-inactive-text);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------------
   Status Message & Timer
   --------------------------------------------------------------------------- */
.processing-filename {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 16px;
  text-align: center;
}

.processing-company-count {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: -12px;
  margin-bottom: 16px;
  text-align: center;
}

.status-message {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  min-height: 1.4em;
  margin-bottom: 8px;
}

.elapsed {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.elapsed .remaining {
  font-weight: 600;
  color: var(--color-text);
}

/* ---------------------------------------------------------------------------
   Error
   --------------------------------------------------------------------------- */
.error-box {
  background: var(--color-error-light);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--color-error);
  font-size: 0.85rem;
  margin-top: 12px;
  word-break: break-word;
}

.error-message {
  margin: 0;
}

.error-details {
  margin-top: 8px;
  font-size: 0.8rem;
}

.error-details summary {
  cursor: pointer;
  user-select: none;
  color: var(--color-error);
  opacity: 0.85;
}

.error-details summary:hover {
  opacity: 1;
}

.error-details pre {
  margin: 4px 0 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
}

.error-details-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.error-copy-btn {
  padding: 3px 10px;
  font-size: 0.72rem;
  font-family: inherit;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.7);
  color: var(--color-error);
  border: 1px solid rgba(220, 38, 38, 0.35);
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.error-copy-btn:hover {
  background: var(--color-error);
  color: #fff;
  border-color: var(--color-error);
}

.error-copy-btn.copied {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}

/* ---------------------------------------------------------------------------
   Toggle Slider
   --------------------------------------------------------------------------- */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.toggle-text {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  user-select: none;
}

.toggle-hint {
  margin: -8px 0 16px 54px;
  font-size: 0.78rem;
  color: #475569; /* slate-600 — stronger contrast than muted at 0.78rem */
  line-height: 1.4;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-toggle-track);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider {
  background: var(--color-primary);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(18px);
}

/* ---------------------------------------------------------------------------
   Toast Notifications
   --------------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  position: relative;
  overflow: hidden;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: auto;
  max-width: 340px;
}

.toast--success { background: var(--color-success); }
.toast--error   { background: var(--color-error); }

/* Auto-dismiss countdown bar — shrinks from full to 0 over the toast lifetime.
   Uses scaleX (GPU-compositable) for smooth motion. */
.toast::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: rgba(255, 255, 255, 0.55);
  transform-origin: left;
  animation: toastCountdown linear forwards;
  animation-duration: var(--toast-duration, 5000ms);
}

@keyframes toastCountdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

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

/* ---------------------------------------------------------------------------
   Keyboard Focus Indicators
   Unified :focus-visible rings so keyboard users always see where they are.
   Mouse clicks don't trigger :focus-visible, so sighted mouse users are
   unaffected.
   --------------------------------------------------------------------------- */
button:focus-visible,
.download-btn:focus-visible,
.browse-link:focus-visible,
.hero-cta:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.cancel-btn:focus-visible {
  outline: 2px solid var(--color-error);
  outline-offset: 2px;
}

.error-details summary:focus-visible {
  outline: 2px solid var(--color-error);
  outline-offset: 2px;
  border-radius: 2px;
}

/* The native checkbox is visually hidden, so route its focus ring to the
   visible slider element instead. */
.toggle input:focus-visible + .toggle-slider {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------------------
   Section Fade Transition
   Fades in #upload-section / #status-section when they become visible,
   so the upload → status handoff (and reset → upload) isn't a hard snap.
   --------------------------------------------------------------------------- */
@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#upload-section:not(.hidden),
#status-section:not(.hidden) {
  animation: cardFadeIn 220ms ease-out;
}

/* ---------------------------------------------------------------------------
   Reduced-Motion Preference
   Honour users who've opted out of continuous animations.
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
  #upload-section:not(.hidden),
  #status-section:not(.hidden) {
    animation: none;
  }
  .progress-bar.indeterminate .progress-bar-fill {
    animation: none;
    width: 100%;
    opacity: 0.4;
  }
  .toast::after {
    animation: none;
    opacity: 0;
  }
}

/* ---------------------------------------------------------------------------
   Utility
   --------------------------------------------------------------------------- */
.hidden { display: none !important; }

/* ---------------------------------------------------------------------------
   Landing Page
   --------------------------------------------------------------------------- */
.landing-wrap {
  max-width: 700px;
  margin: 0 auto;
  padding: 56px 24px 60px;
}

.hero {
  text-align: center;
  margin-bottom: 40px;
}

.hero-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-heading);
  margin-bottom: 14px;
}

.hero-subtitle {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.9);
  max-width: 480px;
  margin: 0 auto 28px;
  line-height: 1.6;
  background: var(--color-landing-card-bg);
  border: 1px solid var(--color-landing-card-border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
}

.hero-cta {
  display: inline-block;
  padding: 11px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition);
}

.hero-cta:hover {
  background: var(--color-primary-hover);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 640px) {
  .feature-grid { grid-template-columns: 1fr; }
}

.feature-card {
  background: var(--color-landing-card-bg);
  border: 1px solid var(--color-landing-card-border);
  border-radius: var(--radius);
  padding: 20px 18px;
}

.feature-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 6px;
}

.feature-card p {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.5;
}
