:root {
  /* Paleta Trailer Logistics — light theme */
  --bg: #f4f6fb;
  --bg-2: #eef1f7;
  --panel: #ffffff;
  --panel-2: #f8fafd;
  --accent: #0066cc;          /* Azul Trailer principal */
  --accent-dark: #004c99;
  --accent-2: #ff6b35;        /* Naranja Trailer secundario */
  --warn: #f59e0b;
  --red: #ef4444;
  --green: #16a34a;
  --text: #1e293b;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-soft: #edf1f6;

  /* Sombras suaves para dar profundidad */
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 6px rgba(15,23,42,0.04), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-lg: 0 10px 20px rgba(15,23,42,0.07), 0 4px 8px rgba(15,23,42,0.05);

  /* Gradiente de cabecera */
  --grad-header: linear-gradient(135deg, #0066cc 0%, #004c99 100%);
  --grad-accent: linear-gradient(135deg, #0066cc 0%, #0284c7 100%);
  --grad-orange: linear-gradient(135deg, #ff6b35 0%, #f97316 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* === HEADER === */
header {
  background: var(--grad-header);
  color: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 20px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
}
header h1 {
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.02em;
}
header h1 .acc {
  color: var(--accent-2);
  background: rgba(255,107,53,0.15);
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: 4px;
}
nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  background: rgba(255,255,255,0.08);
  padding: 4px;
  border-radius: 10px;
}
nav button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s ease;
}
nav button:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}
nav button.active {
  color: var(--accent-dark);
  background: #fff;
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* === MAIN === */
main {
  padding: 24px 28px;
  max-width: 1700px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === FILTERS === */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--panel);
  padding: 14px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-soft);
}
.filters label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: #cbd5e1; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,204,0.12);
}
input[type="number"] { text-align: right; }

/* === KPI CARDS === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.6;
}
.kpi.green::before { background: var(--green); }
.kpi.blue::before { background: var(--accent); }
.kpi.warn::before { background: var(--warn); }
.kpi.orange::before { background: var(--accent-2); }
.kpi:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.kpi .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 600;
}
.kpi .val {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.kpi .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}
.kpi.green .val { color: var(--green); }
.kpi.blue .val { color: var(--accent); }
.kpi.warn .val { color: var(--warn); }
.kpi.orange .val { color: var(--accent-2); }

/* === PANELS === */
.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}
.panel:hover { box-shadow: var(--shadow-md); }
.panel h2 {
  padding: 16px 20px;
  background: var(--panel-2);
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.panel h2 .badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}
.panel h2 .actions { display: flex; gap: 8px; align-items: center; }

/* === TABLAS === */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th {
  background: var(--panel-2);
  padding: 12px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  color: var(--text-2);
}
tbody tr {
  transition: background 0.15s ease;
}

/* === Grilla detalle diario: bordes más oscuros para legibilidad === */
#grid { border: 2px solid #334155; }
#grid th {
  background: #d1d5db;
  color: #000;
  font-weight: 800;
  border-bottom: 2px solid #334155;
  border-right: 1px solid #94a3b8;
}
#grid td {
  border-bottom: 1px solid #94a3b8;
  border-right: 1px solid #cbd5e1;
}
#grid tbody tr:hover td { background: rgba(0, 102, 204, 0.06); }
#grid tfoot td {
  border-top: 2px solid #334155;
  border-bottom: 2px solid #334155;
  border-right: 1px solid #94a3b8;
}
#grid .gcell { border: 1px solid #cbd5e1 !important; }
#grid .gcell:focus { border-color: var(--accent) !important; }
tbody tr:hover {
  background: rgba(0,102,204,0.04);
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}
.uf { color: var(--accent); font-weight: 600; }
.clp { color: var(--accent-2); font-weight: 500; }
.muted { color: var(--muted); }
.red { color: var(--red); }

.loading {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-weight: 500;
}
.err {
  background: #fef2f2;
  color: #b91c1c;
  padding: 12px 18px;
  border-radius: 10px;
  margin: 16px 0;
  border: 1px solid #fecaca;
  font-weight: 500;
}
.ok {
  background: #f0fdf4;
  color: #15803d;
  padding: 12px 18px;
  border-radius: 10px;
  margin: 16px 0;
  border: 1px solid #bbf7d0;
  font-weight: 500;
}

/* === BOTONES === */
.btn {
  background: var(--grad-accent);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }
.btn.secondary {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn.secondary:hover {
  background: var(--panel-2);
  border-color: var(--accent);
}
.btn.danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
}
.btn.orange {
  background: var(--grad-orange);
  color: #fff;
}
.btn.small {
  padding: 5px 12px;
  font-size: 12px;
}

.overflow-x { overflow-x: auto; max-height: 75vh; overflow-y: auto; }
.overflow-x::-webkit-scrollbar { width: 8px; height: 8px; }
.overflow-x::-webkit-scrollbar-track { background: var(--panel-2); }
.overflow-x::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.overflow-x::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.tag-simple { background: rgba(0,102,204,0.12); color: var(--accent); }
.tag-doble { background: rgba(245,158,11,0.15); color: var(--warn); }
.tag-activa { background: rgba(22,163,74,0.12); color: var(--green); }
.tag-inactiva { background: rgba(100,116,139,0.15); color: var(--muted); }

/* === MODAL === */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  max-width: 820px;
  width: 100%;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-head {
  padding: 16px 22px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.btn-x {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  transition: all 0.15s;
}
.btn-x:hover { background: var(--border); color: var(--text); }
#modal-body { padding: 22px; overflow-y: auto; flex: 1; }

/* === FORMS === */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-full { grid-column: 1 / -1; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.field input, .field select, .field textarea { width: 100%; }
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
}

/* === MOVIMIENTOS: grilla con líneas tipo Excel === */
#m-summary table th, #m-summary table td,
#grid th, #grid td {
  border: 1px solid var(--border-soft) !important;
}
#m-summary table, #grid { border: 1px solid var(--border); }
/* Celdas blancas → texto NEGRO */
#grid tbody td, #m-summary tbody td { color: #000 !important; }
#grid tbody .muted, #m-summary tbody .muted { color: #475569 !important; }
#grid input.gcell {
  border: none !important;
  border-radius: 0;
  background: transparent;
  color: #000 !important;
  font-weight: 500;
}
#grid input.gcell:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: none;
}
#m-summary input.uf-input {
  border: 1px solid var(--border);
  background: #fff;
  color: #000 !important;
  font-weight: 600;
}
#m-summary input.uf-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(0,102,204,0.12);
}
/* Fila de HOY destacada */
#grid tr.row-hoy td {
  background: rgba(245,158,11,0.15) !important;
  color: #000 !important;
}
#grid tr.row-hoy input.gcell {
  background: transparent !important;
  color: #000 !important;
}
/* Separadores de ciclo (fondo azul oscuro Trailer) — texto blanco */
#grid tr.mf-sep td { color: #fff !important; }

/* === INVOICE (Prefactura) === */
.invoice {
  background: #fff;
  color: #1e293b;
  padding: 36px;
  border-radius: 12px;
  max-width: 820px;
  margin: 0 auto;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
}
.invoice h2 {
  color: var(--accent);
  margin-bottom: 20px;
  font-size: 24px;
  letter-spacing: -0.02em;
}
.invoice table { color: #1e293b; }
.invoice th {
  background: #f1f5f9;
  color: #475569;
}
.invoice td { color: #1e293b; }
.invoice .totals {
  margin-top: 22px;
  border-top: 2px solid var(--accent);
  padding-top: 12px;
}
.invoice .meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}
.invoice .meta div {
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.invoice .meta strong {
  display: block;
  font-size: 10.5px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
