/* ==========================================================================
   TECSA — Portal de Acesso a Obras — v1.0
   Mobile-first, identidade visual TECSA (Aurora design system)
   ========================================================================== */

:root {
  --tecsa-blue: #003C82;
  --tecsa-blue-hover: #1A5A9E;
  --tecsa-blue-light: #E6EDF5;
  --tecsa-gray: #8A8C8E;
  --tecsa-gray-soft: #b0b2b4;
  --tecsa-text: #231F20;
  --tecsa-border: #D0D0D0;
  --tecsa-bg: #F5F5F5;
  --tecsa-success: #16a34a;
  --tecsa-success-light: #dcfce7;
  --tecsa-danger: #dc2626;
  --tecsa-danger-light: #fef2f2;
  --tecsa-warning: #d97706;
  --tecsa-warning-light: #fffbeb;

  --font-sans: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(35,31,32,.04);
  --shadow-md: 0 4px 16px rgba(35,31,32,.06);
  --shadow-lg: 0 8px 30px rgba(0,60,130,.08);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--tecsa-text);
  background: var(--tecsa-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p, ul, ol { margin: 0; padding: 0; }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* --- Top bar ------------------------------------------------------------ */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--tecsa-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: 540px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-logo { height: 22px; width: auto; }
.topbar-sep { width: 1px; height: 18px; background: var(--tecsa-border); }
.topbar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--tecsa-gray);
}

/* --- Stages ------------------------------------------------------------- */
.stage {
  display: none;
  padding: 24px 16px 40px;
  max-width: 540px;
  margin: 0 auto;
}
.stage-active { display: block; animation: fadeIn .3s ease; }

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

/* --- Card --------------------------------------------------------------- */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 24px;
}
.card-center { text-align: center; }
.card-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 20px;
}
.card-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--tecsa-blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tecsa-blue);
  flex-shrink: 0;
}
.card-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--tecsa-text);
}
.card-subtitle {
  font-size: 13px;
  color: var(--tecsa-gray);
  margin-top: 2px;
}

/* --- Steps bar ---------------------------------------------------------- */
.steps-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 24px;
}
.step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  background: var(--tecsa-bg);
  color: var(--tecsa-gray);
  border: 2px solid var(--tecsa-border);
  transition: all .2s;
}
.step.active {
  background: var(--tecsa-blue);
  color: #fff;
  border-color: var(--tecsa-blue);
}
.step.done {
  background: var(--tecsa-success);
  color: #fff;
  border-color: var(--tecsa-success);
}
.step-line {
  width: 40px;
  height: 2px;
  background: var(--tecsa-border);
  transition: background .2s;
}
.step-line.done { background: var(--tecsa-success); }

/* --- Form --------------------------------------------------------------- */
.form-fields { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--tecsa-text);
}
.field input {
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--tecsa-border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--tecsa-text);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.field input:focus {
  border-color: var(--tecsa-blue);
  box-shadow: 0 0 0 3px rgba(0,60,130,.1);
}
.field input.invalid {
  border-color: var(--tecsa-danger);
  box-shadow: 0 0 0 3px rgba(220,38,38,.1);
}
.field-error {
  font-size: 12px;
  font-weight: 500;
  color: var(--tecsa-danger);
  min-height: 0;
}
.field-error:empty { display: none; }
.field-hint {
  font-size: 12px;
  color: var(--tecsa-gray-soft);
}

/* --- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  padding: 0 24px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  transition: all .2s;
}
.btn-primary {
  background: var(--tecsa-blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,60,130,.2);
}
.btn-primary:hover { background: var(--tecsa-blue-hover); }
.btn-primary:disabled {
  background: var(--tecsa-gray-soft);
  box-shadow: none;
  cursor: not-allowed;
}
.btn-success {
  background: var(--tecsa-success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(22,163,74,.2);
}
.btn-success:hover { background: #15803d; }
.btn-success:disabled {
  background: var(--tecsa-gray-soft);
  box-shadow: none;
  cursor: not-allowed;
}
.btn-outline {
  background: transparent;
  color: var(--tecsa-text);
  border: 2px solid var(--tecsa-border);
}
.btn-outline:hover { border-color: var(--tecsa-blue); color: var(--tecsa-blue); }
.btn-full { width: 100%; }
.btn-row { display: flex; gap: 12px; }
.btn-row .btn { flex: 1; }

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-remove {
  background: var(--tecsa-danger-light);
  color: var(--tecsa-danger);
}
.btn-remove:hover { background: #fecaca; }

/* --- Upload area -------------------------------------------------------- */
.upload-area {
  border: 2px dashed var(--tecsa-border);
  border-radius: var(--radius-md);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.upload-area:hover {
  border-color: var(--tecsa-blue);
  background: rgba(0,60,130,.02);
}
.upload-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--tecsa-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: var(--tecsa-gray);
}
.upload-text { font-size: 14px; font-weight: 500; color: var(--tecsa-text); }
.upload-hint { font-size: 12px; color: var(--tecsa-gray); margin-top: 4px; }

.upload-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 2px solid rgba(22,163,74,.3);
  border-radius: var(--radius-md);
  background: var(--tecsa-success-light);
}
.upload-preview img {
  width: 72px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--tecsa-bg);
}
.upload-preview-info { flex: 1; min-width: 0; }
.upload-preview-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-preview-size { font-size: 12px; color: var(--tecsa-gray); }

/* --- Hint box ----------------------------------------------------------- */
.hint-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--tecsa-blue-light);
  border-radius: var(--radius-md);
  color: var(--tecsa-blue);
}
.hint-box svg { flex-shrink: 0; margin-top: 1px; }
.hint-box p { font-size: 12px; color: var(--tecsa-gray); line-height: 1.5; }

/* --- LGPD notice -------------------------------------------------------- */
.lgpd-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(0,60,130,.03);
  border-radius: var(--radius-sm);
}
.lgpd-notice svg { flex-shrink: 0; color: var(--tecsa-blue); margin-top: 1px; }
.lgpd-notice p { font-size: 11px; color: var(--tecsa-gray); }

/* --- Camera ------------------------------------------------------------- */
.camera-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
}
.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.camera-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 55%;
  aspect-ratio: 3/4;
  border: 3px dashed rgba(255,255,255,.5);
  border-radius: 50%;
}
.camera-caption {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.9);
  font-size: 13px;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  pointer-events: none;
}
.camera-buttons { display: flex; flex-direction: column; gap: 10px; }

.selfie-preview {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.selfie-preview img {
  width: 100%;
  display: block;
  transform: scaleX(-1);
}

/* --- Success ------------------------------------------------------------ */
.success-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--tecsa-success-light);
  color: var(--tecsa-success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}
.success-summary {
  text-align: left;
  margin-top: 20px;
  padding: 16px;
  background: var(--tecsa-bg);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sum-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
}
.sum-label {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--tecsa-gray);
  text-transform: uppercase;
}
.sum-value {
  flex: 1 1 auto;
  text-align: right;
  color: var(--tecsa-text);
  word-break: break-word;
}
.analysis-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(0,60,130,.1);
}
.extracted-section { text-align: left; }
.extracted-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--tecsa-blue);
  margin-bottom: 10px;
}
.extracted-list { display: flex; flex-direction: column; gap: 10px; }
.ext-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ext-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .8px;
  color: var(--tecsa-gray);
  text-transform: uppercase;
}
.ext-value {
  font-size: 14px;
  color: var(--tecsa-text);
  padding-left: 20px;
  word-break: break-word;
}
.observation-box {
  margin-top: 14px;
  padding: 12px 14px;
  background: #fef9c3;
  border-left: 3px solid #ca8a04;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.5;
  color: #713f12;
}
.observation-box strong { color: #854d0e; }

/* --- Analysis section --------------------------------------------------- */
.analysis-section {
  text-align: left;
  margin-top: 20px;
  padding: 16px;
  background: var(--tecsa-blue-light);
  border-radius: var(--radius-md);
}
.analysis-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--tecsa-blue);
  margin-bottom: 10px;
}
.analysis-content {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.analysis-content p { font-size: 13px; color: var(--tecsa-gray); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--tecsa-success-light); color: var(--tecsa-success); }
.badge-warning { background: var(--tecsa-warning-light); color: var(--tecsa-warning); }
.badge-danger { background: var(--tecsa-danger-light); color: var(--tecsa-danger); }

/* Cross-validation alert */
.cv-alert {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.cv-match {
  background: var(--tecsa-success-light);
  color: #166534;
}
.cv-divergence {
  background: var(--tecsa-warning-light);
  color: #92400e;
}

/* --- Spinner ------------------------------------------------------------ */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--tecsa-border);
  border-top-color: var(--tecsa-blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
.spinner-small {
  width: 20px;
  height: 20px;
  border: 2px solid var(--tecsa-border);
  border-top-color: var(--tecsa-blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast -------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--tecsa-text);
  z-index: 1000;
  transition: transform .25s ease;
  max-width: 90%;
}
.toast[data-visible="true"] { transform: translateX(-50%) translateY(0); }
.toast[data-type="error"] { background: var(--tecsa-danger); }
.toast[data-type="success"] { background: var(--tecsa-success); }

/* --- Footer ------------------------------------------------------------- */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 11px;
  color: var(--tecsa-gray-soft);
}
.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--tecsa-blue);
  font-size: 13px;
  margin-bottom: 4px;
}
.footer-brand strong { font-weight: 700; }
.footer-shield { color: var(--tecsa-blue); }
.footer-lgpd { font-size: 11px; color: var(--tecsa-gray-soft); }

/* --- Admin table -------------------------------------------------------- */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--tecsa-gray);
  border-bottom: 2px solid var(--tecsa-border);
  white-space: nowrap;
}
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--tecsa-bg);
  vertical-align: middle;
}
.admin-table tr:hover td { background: var(--tecsa-blue-light); }
.admin-table .btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 11px;
  border-radius: 4px;
}

/* Admin detail sections */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.detail-grid .detail-item {
  padding: 10px;
  background: var(--tecsa-bg);
  border-radius: var(--radius-sm);
}
.detail-item label {
  font-size: 11px;
  font-weight: 600;
  color: var(--tecsa-gray);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.detail-item p {
  font-size: 14px;
  font-weight: 500;
  margin-top: 2px;
}

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 480px) {
  .card { padding: 22px 18px; }
  .btn { height: 48px; font-size: 14px; }
  .field input { height: 44px; font-size: 14px; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (min-width: 768px) {
  #stage-admin .card,
  #stage-admin-detail .card { max-width: 960px; margin: 0 auto; }
  #stage-admin, #stage-admin-detail { max-width: 1000px; }
}
