@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=DM+Mono&display=swap');

:root {
  --bg:        #0d0d0d;
  --surface:   #161616;
  --surface2:  #1f1f1f;
  --border:    #2a2a2a;
  --text:      #e8e8e8;
  --muted:     #666;
  --lime:      #f0f0f0;
  --cyan:      #22d3ee;
  --orange:    #fb923c;
  --red:       #f87171;
  --green:     #4ade80;
  --radius:    10px;
  --font:      'DM Sans', sans-serif;
  --mono:      'DM Mono', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
}

/* ── Sidebar nav ── */
nav {
  position: fixed;
  top: 0; left: 0;
  width: 200px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.5rem;
  z-index: 50;
  overflow-y: auto;
}
.nav-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: #fff;
  border-radius: 10px;
  padding: 8px 12px;
}
.nav-brand img {
  width: 100%;
  max-width: 140px;
  height: auto;
  display: block;
}
.nav-links {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  padding: .5rem .8rem;
  border-radius: 6px;
  font-size: .88rem;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.nav-links a:hover  { color: var(--text); background: var(--surface2); }
.nav-links a.active { color: var(--text); background: var(--surface2); }

/* ── Layout ── */
body { display: flex; }
.page {
  margin-left: 200px;
  padding: 2rem;
  max-width: 1200px;
  width: 100%;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }
.page-header p  { color: var(--muted); font-size: .9rem; margin-top: .2rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

/* ── Tabla ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left;
  padding: .6rem 1rem;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

.mono { font-family: var(--mono); font-size: .85rem; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-green  { background: #14532d; color: var(--green); }
.badge-red    { background: #450a0a; color: var(--red); }
.badge-orange { background: #431407; color: var(--orange); }

/* ── Botones ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 7px;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--lime); color: #000; }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger  { background: #450a0a; color: var(--red); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* ── Formularios ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  padding: .5rem .75rem;
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--lime);
}
.form-group select option { background: var(--surface2); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.5rem; }
.btn-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}
.btn-close:hover { color: var(--text); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1.25rem;
  font-size: .875rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  z-index: 200;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { border-color: var(--green); color: var(--green); }
#toast.error   { border-color: var(--red);   color: var(--red);   }

/* ── Index cards ── */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.module-card:hover { border-color: var(--lime); background: var(--surface2); }
.module-card .icon { font-size: 1.6rem; }
.module-card .title { font-weight: 600; font-size: 1rem; }
.module-card .desc  { font-size: .8rem; color: var(--muted); }

/* ── Health dot ── */
.health-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.health-dot.ok  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.health-dot.err { background: var(--red); }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: .9rem;
}

/* ── Mobile topbar (inyectado por auth.js) ── */
.nav-topbar {
  display: none;
}
.nav-toggle {
  display: none;
}

/* ── Responsive Mobile ── */
@media (max-width: 768px) {
  .nav-topbar {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 1rem;
    gap: .75rem;
    z-index: 60;
  }

  .nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    flex-shrink: 0;
  }
  .nav-toggle span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
  }

  nav {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 70;
    width: 220px;
  }
  nav.nav-open {
    transform: translateX(0);
  }

  .page {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(52px + 1rem);
    max-width: 100%;
  }

  .page-header {
    flex-wrap: wrap;
    gap: .75rem;
  }
  .page-header h1 { font-size: 1.2rem; }

  /* Tablas con scroll horizontal */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  td, th { padding: .55rem .65rem; font-size: .82rem; }

  /* Modales full-width */
  .modal {
    margin: 0 .75rem;
    max-width: calc(100vw - 1.5rem);
    max-height: 92vh;
    padding: 1.25rem;
  }
  .confirm-box {
    width: calc(100vw - 2rem);
    max-width: 360px;
  }

  /* Toast abajo centrado */
  #toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    text-align: center;
  }

  /* Grid de módulos en 2 columnas */
  .module-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Dashboard KPIs ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.kpi-label {
  font-size: .72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .55rem;
}
.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: .4rem;
}
.kpi-sub { font-size: .78rem; color: var(--muted); }
.kpi-sub.up   { color: var(--green); }
.kpi-sub.down { color: var(--red); }

.truck-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.truck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.truck-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding-bottom: .9rem;
  margin-bottom: .9rem;
  border-bottom: 1px solid var(--border);
}
.truck-patente {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
}
.truck-chofer { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.truck-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}
.truck-stat { }
.truck-stat-label { font-size: .7rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2rem; }
.truck-stat-value { font-size: 1.05rem; font-weight: 700; }

.dest-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .75rem; }
.dest-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
}
.dest-bar-wrap {
  flex: 1;
  height: 5px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}
.dest-bar {
  height: 100%;
  background: var(--cyan);
  border-radius: 99px;
  transition: width .4s ease;
}
.dest-name  { width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.dest-count { width: 28px; text-align: right; color: var(--muted); font-size: .8rem; }
.dest-total { width: 90px; text-align: right; color: var(--muted); font-size: .78rem; font-family: var(--mono); }

.hist-bars {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  height: 64px;
  margin-top: .75rem;
}
.hist-bar-col { display: flex; flex-direction: column; align-items: center; gap: .3rem; flex: 1; height: 100%; justify-content: flex-end; }
.hist-bar {
  width: 100%;
  background: var(--surface2);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  transition: height .4s ease;
  position: relative;
}
.hist-bar.current { background: var(--cyan); }
.hist-label { font-size: .65rem; color: var(--muted); white-space: nowrap; }

@media (max-width: 768px) {
  .kpi-grid   { grid-template-columns: repeat(2, 1fr); }
  .truck-grid { grid-template-columns: 1fr; }
  .dest-name  { width: 110px; }
  .dest-total { display: none; }
  .kpi-value  { font-size: 1.4rem; }
  #bottomRow  { grid-template-columns: 1fr !important; }
}

/* ── Confirm dialog ── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 150;
  align-items: center;
  justify-content: center;
}
.confirm-overlay.open { display: flex; }
.confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 360px;
}
.confirm-box h3 { font-size: 1rem; margin-bottom: .5rem; }
.confirm-box p  { color: var(--muted); font-size: .875rem; margin-bottom: 1.25rem; }
.confirm-box .confirm-footer { display: flex; justify-content: flex-end; gap: .75rem; }
