/* SoilFER Import Tracker v2
   Sistema de diseño: limpio, funcional, orientado a datos operativos.
   Sin frameworks externos — CSS propio mínimo y mantenible. */

:root {
  --color-bg:         #f8fafc;
  --color-surface:    #ffffff;
  --color-border:     #e2e8f0;
  --color-text:       #1e293b;
  --color-muted:      #64748b;
  --color-primary:    #2563eb;
  --color-primary-hover: #1d4ed8;

  --risk-low:      #22c55e;
  --risk-medium:   #eab308;
  --risk-high:     #f97316;
  --risk-critical: #ef4444;

  --radius:  6px;
  --shadow:  0 1px 3px rgba(0,0,0,.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ─── Header ──────────────────────────────────── */

.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--color-primary);
  text-decoration: none;
}

nav { display: flex; align-items: center; gap: 1.25rem; }
nav a { color: var(--color-muted); text-decoration: none; font-size: 13px; }
nav a:hover { color: var(--color-text); }

/* ─── Banner envío anticipado ─────────────────── */

.banner-unauthorized {
  background: #fef2f2;
  border-bottom: 2px solid var(--risk-critical);
  color: #991b1b;
  padding: .6rem 1.5rem;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.banner-icon { font-size: 16px; }

/* ─── Main layout ─────────────────────────────── */

.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ─── Dashboard ───────────────────────────────── */

.dashboard-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.dashboard-header h1 { font-size: 20px; font-weight: 600; }

.count-badge {
  background: var(--color-border);
  color: var(--color-muted);
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: 12px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.invoice-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: box-shadow .15s, transform .15s;
  border-left: 4px solid var(--color-border);
}

.invoice-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-1px); }

.invoice-card.risk-bajo    { border-left-color: var(--risk-low); }
.invoice-card.risk-medio   { border-left-color: var(--risk-medium); }
.invoice-card.risk-alto    { border-left-color: var(--risk-high); }
.invoice-card.risk-crítico { border-left-color: var(--risk-critical); }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.card-title { display: flex; flex-direction: column; }
.invoice-number { font-weight: 700; font-size: 15px; }
.po-number { color: var(--color-muted); font-size: 12px; }

.risk-badge {
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: .2rem .6rem;
  border-radius: 99px;
}

.card-alert  { font-size: 12px; color: #b91c1c; background: #fef2f2; padding: .25rem .5rem; border-radius: var(--radius); }
.card-step   { font-size: 13px; color: var(--color-muted); }
.card-skipped { font-size: 12px; color: #92400e; background: #fffbeb; padding: .25rem .5rem; border-radius: var(--radius); }
.card-footer { display: flex; justify-content: space-between; margin-top: .25rem; }
.eta         { font-size: 12px; color: var(--color-muted); }
.eta.warning { color: #d97706; font-weight: 600; }
.eta.critical { color: var(--risk-critical); font-weight: 700; }
.amount      { font-size: 13px; font-weight: 600; color: var(--color-text); }

.empty-state { text-align: center; padding: 3rem; color: var(--color-muted); }

/* ─── Detail layout ───────────────────────────── */

.detail-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 768px) {
  .detail-layout { grid-template-columns: 1fr; }
}

.detail-sidebar { display: flex; flex-direction: column; gap: 1rem; }

.invoice-meta {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.invoice-meta h1 { font-size: 20px; font-weight: 700; }
.invoice-meta h2 { font-size: 14px; color: var(--color-muted); margin-bottom: .75rem; }

dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem .75rem; }
dt { color: var(--color-muted); font-size: 12px; }
dd { font-size: 13px; font-weight: 500; }
.eta-critical { color: var(--risk-critical); font-weight: 700; }
.tag-precursor { color: #92400e; background: #fffbeb; padding: .1rem .4rem; border-radius: 4px; font-size: 12px; }

.risk-panel {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.risk-score { font-size: 48px; font-weight: 800; line-height: 1; }
.risk-score span { font-size: 18px; color: var(--color-muted); }
.risk-label { font-size: 16px; font-weight: 600; margin: .25rem 0; }
.risk-canal { font-size: 12px; color: var(--color-muted); margin-bottom: .75rem; }

.risk-factors {
  list-style: none;
  text-align: left;
  font-size: 11px;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  padding-top: .5rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.risk-factors li::before { content: '• '; color: var(--risk-high); }

.notes-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.notes-panel h3 { font-size: 13px; color: var(--color-muted); margin-bottom: .4rem; }
.notes-panel p { font-size: 13px; }

/* ─── Timeline ────────────────────────────────── */

.protocol-timeline {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.protocol-timeline h2 { font-size: 15px; font-weight: 600; margin-bottom: 1rem; }

.timeline-steps { display: flex; flex-direction: column; gap: .75rem; }

.timeline-step {
  display: flex;
  gap: .75rem;
  padding: .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}

.timeline-step.step-completed { background: #f0fdf4; border-color: #bbf7d0; }
.timeline-step.step-active    { background: #eff6ff; border-color: #bfdbfe; }
.timeline-step.step-skipped   { background: #fffbeb; border-color: #fde68a; }
.timeline-step.step-blocked   { background: #fff1f2; border-color: #fecdd3; }

.step-indicator { width: 28px; flex-shrink: 0; }
.step-icon {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--color-border);
  font-size: 12px; font-weight: 700;
  color: var(--color-muted);
}

.step-icon.warn   { background: #fde68a; color: #92400e; }
.step-icon.active { background: var(--color-primary); color: white; }
.step-completed .step-icon { background: #22c55e; color: white; }

.step-content { flex: 1; }
.step-name    { font-size: 13px; font-weight: 600; }
.step-owner   { font-size: 11px; color: var(--color-muted); }
.step-skipped-warning { font-size: 11px; color: #92400e; font-weight: 600; margin-top: .2rem; }

.step-state-select {
  margin-top: .4rem;
  font-size: 12px;
  padding: .2rem .4rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

/* ─── Items table ─────────────────────────────── */

.items-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.items-section h2 { font-size: 15px; font-weight: 600; margin-bottom: 1rem; }
.empty-items { color: var(--color-muted); font-size: 13px; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.items-table th {
  text-align: left;
  padding: .4rem .6rem;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.items-table td {
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--color-border);
}

.row-missing-msds td { background: #fffbeb; }

/* ─── Forms ───────────────────────────────────── */

.form-layout { max-width: 680px; }
.form-layout h1 { font-size: 20px; font-weight: 600; margin-bottom: 1.25rem; }

.shipment-form fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--color-surface);
}

.shipment-form legend {
  font-size: 13px;
  font-weight: 600;
  padding: 0 .4rem;
  color: var(--color-muted);
}

.form-row { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .75rem; }
.form-row:last-child { margin-bottom: 0; }
.form-row.two-col { flex-direction: row; gap: 1rem; }
.form-row.two-col > div { flex: 1; display: flex; flex-direction: column; gap: .35rem; }

label { font-size: 13px; font-weight: 500; }
.hint { font-size: 11px; color: var(--color-muted); display: block; }

input[type="text"], input[type="number"], input[type="date"], textarea, select {
  padding: .45rem .6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

textarea { resize: vertical; }

.form-check {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  margin-bottom: .75rem;
}

.form-check input[type="checkbox"] { margin-top: 2px; width: auto; }
.form-check label { font-weight: 500; font-size: 13px; }

.form-errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  color: #991b1b;
  font-size: 13px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1rem;
}

/* ─── Buttons ─────────────────────────────────── */

.btn-primary, .btn-new {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: .45rem 1rem;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-primary:hover, .btn-new:hover { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: .45rem 1rem;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.btn-secondary:hover { background: var(--color-bg); }

/* ─── Items import ───────────────────────────── */

.import-format-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.import-format-card h3 { font-size: 13px; font-weight: 600; margin-bottom: .4rem; }
.import-format-card p  { font-size: 12px; color: var(--color-muted); margin-bottom: .5rem; }

.format-example {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: .6rem .8rem;
  font-size: 11px;
  font-family: monospace;
  overflow-x: auto;
  margin-bottom: .6rem;
  color: var(--color-text);
}

.format-rules {
  font-size: 11px;
  color: var(--color-muted);
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.format-rules code {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0 .25rem;
  font-size: 10px;
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: .75rem;
  font-size: 13px;
}

.tag-warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: 11px;
}

.table-scroll { overflow-x: auto; margin-bottom: 1rem; }

.preview-table td { padding: .25rem .3rem; vertical-align: middle; }

.cell-input {
  width: 100%;
  min-width: 140px;
  padding: .3rem .4rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}

.cell-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.cell-sm  { min-width: 70px !important; }
.cell-xs  { min-width: 50px !important; }
.td-center { text-align: center; }
.row-num { color: var(--color-muted); font-size: 11px; text-align: right; padding-right: .5rem; }

.btn-remove {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 13px;
  padding: .2rem .4rem;
  border-radius: 4px;
}
.btn-remove:hover { color: var(--risk-critical); background: #fef2f2; }

.preview-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: .75rem;
}

.btn-sm { font-size: 12px; padding: .3rem .7rem; }

.items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.items-header h2 { margin-bottom: 0; }

/* ─── Error page ──────────────────────────────── */

.error-page {
  text-align: center;
  padding: 4rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.error-page h1 { font-size: 24px; font-weight: 700; }
.error-stack {
  text-align: left;
  font-size: 11px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  max-width: 600px;
  overflow: auto;
  color: var(--color-muted);
}

/* ─── Footer ──────────────────────────────────── */

.app-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 11px;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  margin-top: 2rem;
}

/* ─── Archivos de verificación por paso ───────── */

.step-files {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin: .45rem 0 .5rem;
  min-height: 1.4rem;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.file-chip:hover {
  border-color: var(--color-accent);
  background: #1a2a3a;
}
.file-icon {
  flex-shrink: 0;
  font-size: 12px;
}

.no-files {
  font-size: 11px;
  color: var(--color-muted);
  font-style: italic;
}
.files-loading {
  font-size: 11px;
  color: var(--color-muted);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* Botón de adjuntar — label que envuelve input[type=file] */
.btn-upload-file {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
  user-select: none;
}
.btn-upload-file:hover {
  border-color: var(--color-accent);
  color: var(--color-text);
}

/* Alinear select en la misma fila */
.step-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .5rem;
}

/* ─── Acordeón de pasos ───────────────────────── */

.step-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  cursor: pointer;
  user-select: none;
  padding: .1rem 0;
}
.step-header:hover .step-name {
  color: var(--color-accent);
}
.step-header-main {
  flex: 1;
  min-width: 0;
}
.step-expand-icon {
  font-size: 9px;
  color: var(--color-muted);
  margin-top: 3px;
  flex-shrink: 0;
  transition: color .15s;
}
.step-header:hover .step-expand-icon {
  color: var(--color-accent);
}

/* Detalle expandido */
.step-detail {
  border-top: 1px solid var(--color-border);
  margin-top: .6rem;
  padding-top: .75rem;
}
.step-section {
  margin-bottom: .85rem;
}
.step-section:last-child {
  margin-bottom: 0;
}
.step-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  margin-bottom: .35rem;
}

/* Listas de actividades */
.step-activities-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 12px;
  color: var(--color-text);
  line-height: 1.55;
}
.step-activities-list li {
  margin-bottom: .2rem;
}

/* Lista de documentos requeridos */
.step-reqdocs-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 12px;
  color: var(--color-muted);
  line-height: 1.55;
}
.step-reqdocs-list li {
  margin-bottom: .15rem;
}
.step-reqdocs-list li::marker {
  content: '○  ';
  font-size: 10px;
}
