/* Copyright (c) 2025-2026 Payquity. All rights reserved. */

/* MRLD Frontend — brand: #1a365d (primary), #2c5282 (header) */

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

:root {
  --primary:       #1a365d;
  --primary-light: #2c5282;
  --primary-hover: #2a4a7f;
  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --success:       #16a34a;
  --success-bg:    #f0fdf4;
  --danger:        #dc2626;
  --danger-bg:     #fef2f2;
  --warning:       #d97706;
  --gray-50:       #f8fafc;
  --gray-100:      #f1f5f9;
  --gray-200:      #e2e8f0;
  --gray-300:      #cbd5e1;
  --gray-400:      #94a3b8;
  --gray-500:      #64748b;
  --gray-600:      #475569;
  --gray-700:      #334155;
  --gray-900:      #0f172a;
  --white:         #ffffff;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.04);
  --shadow-lg:     0 4px 20px rgba(0,0,0,.10);
  --transition:    .2s ease;
  --font:          'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--primary);
  color: var(--white);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.header-inner {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.logo { font-size: 1.25rem; font-weight: 700; letter-spacing: .04em; }
.header-subtitle { font-size: .8rem; opacity: .7; font-weight: 400; }

.auth-status { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.auth-user { font-size: .82rem; opacity: .85; }
.btn-signout {
  background: rgba(255,255,255,.12); color: var(--white);
  border: 1px solid rgba(255,255,255,.25); border-radius: var(--radius-sm);
  padding: .3rem .7rem; font-size: .8rem; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: background var(--transition);
}
.btn-signout:hover { background: rgba(255,255,255,.22); }

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-field { display: flex; flex-direction: column; gap: .35rem; }
.login-field span { font-size: .85rem; font-weight: 500; color: var(--gray-700); }
.login-field input {
  font-family: inherit; font-size: .95rem; padding: .65rem .8rem;
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  background: var(--white); color: var(--gray-900); outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.login-field input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.mfa-setup { display: flex; flex-direction: column; gap: 1rem; }
.mfa-setup-lead {
  margin: 0; font-size: .9rem; color: var(--gray-700); text-align: center;
}
.mfa-qr-wrap {
  display: flex; justify-content: center; padding: .75rem;
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
}
.mfa-qr-wrap canvas { display: block; border-radius: 4px; }
.mfa-manual {
  border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: .5rem .75rem; background: var(--gray-50);
}
.mfa-manual summary {
  cursor: pointer; font-size: .85rem; font-weight: 500; color: var(--gray-700);
  user-select: none;
}
.mfa-manual-body {
  display: flex; flex-direction: column; gap: .75rem;
  margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--gray-200);
}
.mfa-secret {
  display: block; padding: .6rem .75rem; font-size: .8rem; line-height: 1.4;
  word-break: break-all; background: var(--white);
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
}

.main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  transition: opacity var(--transition), transform var(--transition);
}

.step { display: none; }
.step.active { display: block; animation: fadeSlideIn .35s ease both; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.step-indicator { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.25rem; }

.step-number {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--white);
  font-size: .8rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.step-label { font-size: 1.05rem; font-weight: 600; color: var(--gray-700); }

.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(59,130,246,.04);
}

.upload-icon { color: var(--gray-400); margin-bottom: .5rem; }
.upload-text { font-weight: 600; color: var(--gray-700); }
.upload-subtext { font-size: .85rem; color: var(--gray-400); margin-top: .25rem; }

.file-info {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem; background: var(--gray-100);
  border-radius: var(--radius-sm); margin-top: 1rem;
}

.file-info-icon { color: var(--accent); flex-shrink: 0; }
.file-info-details { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.file-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: .78rem; color: var(--gray-500); }

.file-remove {
  background: none; border: none; font-size: 1.3rem; color: var(--gray-400);
  cursor: pointer; padding: .25rem; line-height: 1; transition: color var(--transition);
}
.file-remove:hover { color: var(--danger); }

.file-error {
  font-size: .85rem; color: var(--danger); background: var(--danger-bg);
  padding: .6rem .85rem; border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger); margin-top: .75rem;
  animation: fadeSlideIn .25s ease both;
}

.tolerance-group { margin-top: 1.5rem; }

.tolerance-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .9rem; font-weight: 500; color: var(--gray-700); margin-bottom: .5rem;
}

.tolerance-value { font-weight: 700; color: var(--primary); font-size: .95rem; min-width: 3ch; text-align: right; }

.tolerance-slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  background: var(--gray-200); border-radius: 3px; outline: none;
  transition: background var(--transition);
}

.tolerance-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px;
  border-radius: 50%; background: var(--primary); cursor: pointer;
  border: 3px solid var(--white); box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: transform var(--transition), box-shadow var(--transition);
}

.tolerance-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15); box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.tolerance-slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--primary);
  cursor: pointer; border: 3px solid var(--white); box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

.tolerance-range-labels {
  display: flex; justify-content: space-between;
  font-size: .72rem; color: var(--gray-400); margin-top: .25rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.5rem; font-size: .9rem; font-weight: 600;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition), transform .1s ease, box-shadow var(--transition);
  font-family: inherit;
}
.btn:active:not(:disabled) { transform: scale(.97); }

.btn-primary { background: var(--accent); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(37,99,235,.3); }
.btn-primary:disabled { background: var(--gray-300); color: var(--gray-500); cursor: not-allowed; }

.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }

.btn-start-full { width: 100%; margin-top: 1.5rem; padding: .85rem; font-size: .95rem; }

.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: var(--white);
  border-radius: 50%; animation: spin .6s linear infinite;
}

.status-container { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1.25rem; }
.status-icon { flex-shrink: 0; }

.spinner {
  width: 40px; height: 40px;
  border: 3.5px solid var(--gray-200); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}

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

.status-details { flex: 1; }

.status-badge {
  display: inline-block; padding: .2rem .65rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}

.status-badge.created  { background: var(--gray-200); color: var(--gray-600); }
.status-badge.running  { background: #dbeafe; color: #1d4ed8; }
.status-badge.succeeded { background: #dcfce7; color: #15803d; }
.status-badge.failed   { background: #fee2e2; color: #b91c1c; }

.status-message { font-size: .88rem; color: var(--gray-600); margin-top: .35rem; }
.status-time { font-size: .78rem; color: var(--gray-400); margin-top: .15rem; }

.progress-bar-track { height: 4px; background: var(--gray-200); border-radius: 2px; overflow: hidden; }

.progress-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--primary-light));
  border-radius: 2px; transition: width .4s ease;
}

.progress-bar-fill.indeterminate { width: 30%; animation: progressIndeterminate 1.5s ease-in-out infinite; }

@keyframes progressIndeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.result-content { animation: fadeSlideIn .35s ease both; }
.result-header { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.result-icon { flex-shrink: 0; }
.success-icon { color: var(--success); }
.failure-icon { color: var(--danger); }
.result-title { font-size: 1.1rem; font-weight: 700; color: var(--gray-900); }
.result-subtitle { font-size: .82rem; color: var(--gray-500); margin-top: .15rem; }

.result-error {
  font-size: .85rem; color: var(--danger); margin-top: .35rem;
  background: var(--danger-bg); padding: .5rem .75rem;
  border-radius: var(--radius-sm); border-left: 3px solid var(--danger);
}

.result-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }

.pdf-container { border: 1px solid var(--gray-200); border-radius: var(--radius-sm); overflow: hidden; margin-top: .5rem; }
.pdf-iframe { width: 100%; height: 75vh; min-height: 500px; border: none; display: block; }

.footer { text-align: center; padding: 1.25rem; font-size: .78rem; color: var(--gray-400); }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer-sep { margin: 0 .4rem; }

.hidden { display: none !important; }

/* ----- App navigation (tab bar under the header) ----- */
.app-nav {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 56px;
  z-index: 90;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.app-nav-inner {
  display: flex;
  gap: .25rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem;
  overflow-x: auto;
}
.nav-link {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: .85rem .9rem;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
}
.nav-link:hover { color: var(--gray-700); }
.nav-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ----- Views ----- */
.view { display: flex; flex-direction: column; gap: 1.25rem; }
.view-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.25rem;
}
.view-head .step-indicator { margin-bottom: 0; }

/* ----- Buttons (extra variants) ----- */
.btn-sm { padding: .5rem 1rem; font-size: .82rem; }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; box-shadow: 0 2px 8px rgba(220,38,38,.3); }

.form-success {
  font-size: .85rem; color: var(--success); background: var(--success-bg);
  padding: .6rem .85rem; border-radius: var(--radius-sm);
  border-left: 3px solid var(--success); margin-top: .25rem;
  animation: fadeSlideIn .25s ease both;
}

/* ----- History ----- */
.history-hint { font-size: .85rem; color: var(--gray-500); }
.history-list { list-style: none; display: flex; flex-direction: column; gap: .65rem; }
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.1rem; border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); background: var(--gray-50);
}
.history-meta { min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.history-row1 { display: flex; align-items: center; gap: .6rem; }
.history-date { font-size: .82rem; color: var(--gray-600); }
.history-runid {
  font-size: .72rem; color: var(--gray-400); font-family: ui-monospace, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.history-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  font-size: .72rem; font-weight: 600; color: var(--gray-700);
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: 999px; padding: .12rem .55rem;
}
.history-err { font-size: .78rem; color: var(--danger); }
.history-actions { flex-shrink: 0; align-self: center; margin-left: .5rem; }
.history-more-wrap { display: flex; justify-content: center; margin-top: 1rem; }

/* ----- Profile key/value ----- */
.kv { display: flex; flex-direction: column; gap: .1rem; }
.kv-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .6rem 0; border-bottom: 1px solid var(--gray-100);
}
.kv-row:last-child { border-bottom: none; }
.kv-row dt { font-size: .85rem; color: var(--gray-500); }
.kv-row dd { font-size: .9rem; font-weight: 600; color: var(--gray-900); text-align: right; word-break: break-word; }

/* ----- Admin ----- */
.config-summary {
  font-size: .88rem; color: var(--gray-800);
  background: var(--gray-50); border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); padding: 1rem 1.1rem;
}
.config-summary.hidden { display: none; }
.config-summary-title {
  font-size: .92rem; font-weight: 700; color: var(--gray-900);
  margin-bottom: .75rem;
}
.config-kv { display: flex; flex-direction: column; gap: .35rem; margin: 0 0 1rem; }
.config-kv-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .35rem 0; border-bottom: 1px solid var(--gray-200);
}
.config-kv-row:last-child { border-bottom: none; }
.config-kv-row dt { font-size: .82rem; color: var(--gray-600); margin: 0; }
.config-kv-row dd { font-size: .88rem; font-weight: 600; color: var(--gray-900); margin: 0; text-align: right; }
.config-kv-row dd code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .82rem; font-weight: 600;
}
.config-columns-block { display: flex; flex-direction: column; gap: .85rem; }
.config-columns-label {
  display: block; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--gray-600);
  margin-bottom: .4rem;
}
.config-columns-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: .35rem;
}
.config-columns-list li {
  font-size: .8rem; color: var(--gray-800);
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: 999px; padding: .2rem .6rem;
}
.config-summary--empty {
  color: var(--gray-700); background: #fffbeb;
  border-color: #fcd34d;
}
.code-area {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: .8rem; line-height: 1.5; padding: .75rem;
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  background: var(--gray-50); color: var(--gray-900); width: 100%;
  resize: vertical; outline: none; min-height: 240px;
}
.code-area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.danger-card { border: 1px solid #fecaca; }

@media (max-width: 600px) {
  .main { margin: 1rem auto; }
  .card { padding: 1.25rem; }
  .upload-zone { padding: 1.5rem .75rem; }
  .result-actions { flex-direction: column; }
  .result-actions .btn { width: 100%; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
  .pdf-iframe { height: 60vh; min-height: 350px; }
  .history-item { flex-direction: column; align-items: stretch; }
  .history-actions { align-self: stretch; margin-left: 0; margin-top: .75rem; }
  .history-actions .btn { width: 100%; }
}
