/* ═══════════════════════════════════════════════════════════
   LOGÍSTICA CÓRDOBA Dashboard — Mobile-First
   Primary: #E30613 (Frigo Red)
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:           #f4f6f9;
  --surface:      #fff;
  --border:       #e2e8f0;
  --primary:      #E30613;
  --primary-light:#fff1f1;
  --primary-mid:  #fecaca;
  --primary-dark: #b30000;
  --text:         #1e293b;
  --muted:        #64748b;
  --gain:         #059669;
  --gain-bg:      #ecfdf5;
  --loss:         #b45309;
  --loss-bg:      #fff7ed;
  --warn:         #d97706;
  --warn-bg:      #fffbeb;
  --yel:          #ca8a04;
  --yel-bg:       #fef9c3;
  --shadow:       0 1px 3px rgba(0,0,0,.08);
  --r:            12px;
  --rs:           8px;
  --tr:           .16s ease;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ── Header ────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.logo {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.4px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.header-right  { display: flex; align-items: center; gap: 10px; }
.header-center { position: absolute; left: 50%; transform: translateX(-50%); display: flex; align-items: center; pointer-events: none; }
.magnum-logo   { height: 28px; width: auto; object-fit: contain; }
.header-meta  {
  font-size: 10px; color: var(--muted); text-align: right;
  line-height: 1.4; display: none;
}
.hbtn {
  font-size: 11px; text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: all var(--tr);
  cursor: pointer;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
}
.hbtn-logout:hover { border-color: var(--loss); color: var(--loss); }

/* ── Filters (inside client card) ─────────────────────────── */
.card-filters {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--r) var(--r) 0 0;
}
.filters-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.fg { display: flex; flex-direction: column; gap: 4px; }
.fg label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted);
}
.fg select {
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 8px 28px 8px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 9px center;
  appearance: none;
  cursor: pointer;
  width: 100%;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.fg select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(227,6,19,.12);
}
.fg-action {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.btn-reset {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--rs);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all var(--tr);
}
.btn-reset:hover { border-color: var(--primary); color: var(--primary); }
.filter-count { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }

/* ── Main ──────────────────────────────────────────────────── */
main {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--primary);
}
.kpi.g::before { background: var(--gain); }
.kpi.l::before { background: var(--loss); }
.kpi.w::before { background: var(--warn); }
.kpi-lbl {
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin-bottom: 4px;
}
.kpi-val { font-size: 20px; font-weight: 800; color: var(--text); line-height: 1; }
.kpi-sub { font-size: 10px; font-weight: 600; margin-top: 4px; color: var(--muted); }
.kpi-sub.up   { color: var(--gain); }
.kpi-sub.down { color: var(--loss); }
.kpi-sub.warn { color: var(--warn); }

/* ── Alarm Strip ───────────────────────────────────────────── */
.alarm-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.alarm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  border-left-width: 4px;
  border-left-style: solid;
}
.alarm-card.red  { border-left-color: var(--loss); }
.alarm-card.warn { border-left-color: var(--warn); }
.alarm-card.yel  { border-left-color: #eab308; }
.alarm-card:last-child { grid-column: 1 / -1; }
.alarm-icon { font-size: 22px; flex-shrink: 0; line-height: 1; }
.alarm-info { min-width: 0; }
.alarm-count { font-size: 26px; font-weight: 800; line-height: 1; }
.alarm-count.red  { color: var(--loss); }
.alarm-count.warn { color: var(--warn); }
.alarm-count.yel  { color: #ca8a04; }
.alarm-label {
  font-size: 10px; color: var(--muted);
  font-weight: 600; margin-top: 3px;
  text-transform: uppercase; letter-spacing: .4px;
}

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ch {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ch-left { min-width: 0; }
.ct { font-size: 13px; font-weight: 700; }
.cs { font-size: 11px; color: var(--muted); margin-top: 2px; }
.badge {
  font-size: 10px; font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap; flex-shrink: 0;
}
.badge.g { background: var(--gain-bg); color: var(--gain); }
.badge.l { background: var(--loss-bg); color: var(--loss); }
.badge.w { background: var(--warn-bg); color: var(--warn); }

/* ── Charts ────────────────────────────────────────────────── */
.chart-wrap { padding: 12px 14px; position: relative; }
.chart-wrap-donut { height: 240px; }
.chart-wrap-bar   { height: 240px; }
.chart-wrap-act   { height: 200px; padding: 12px 16px; }
.charts-grid  { display: flex; flex-direction: column; gap: 14px; }
.charts-top   { display: flex; flex-direction: column; gap: 14px; }

/* ── Table header ──────────────────────────────────────────── */
.table-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.search-wrap { flex: 1; }
.search-wrap input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--tr), box-shadow var(--tr);
}
.search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(227,6,19,.12);
}

/* ── Mobile Client Cards ───────────────────────────────────── */
.client-cards { }
.cc {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  cursor: pointer;
  transition: background var(--tr);
}
.cc:hover { background: #fafafa; }
.cc.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.cc-chevron { font-size: 14px; color: var(--muted); flex-shrink: 0; align-self: center; transition: transform var(--tr); margin-left: 2px; }
.cc.active .cc-chevron { transform: rotate(180deg); color: var(--primary); }

/* Client detail panel (accordion) */
.cc-detail {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 14px;
}
.cc-detail.open { display: block; }

/* COTC product grid */
.cotc-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-top: 8px;
}
.cotc-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid transparent;
}
.cotc-item.ok   { background: var(--gain-bg); border-color: #a7f3d0; }
.cotc-item.pend { background: var(--loss-bg); border-color: #fecaca; }
.cotc-item.none { background: #f1f5f9;        border-color: var(--border); }
.cotc-prod-lbl  { font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .2px; color: var(--text); margin-bottom: 5px; line-height: 1.2; }
.cotc-status    { font-size: 11px; font-weight: 800; letter-spacing: .4px; }
.cotc-status.ok   { color: var(--gain); }
.cotc-status.pend { color: var(--loss); }
.cotc-status.none { color: var(--muted); }

/* Detail sections */
.detail-section { margin-bottom: 12px; }
.detail-section:last-child { margin-bottom: 0; }
.detail-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 6px; }
.detail-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.ds-item { display: flex; flex-direction: column; gap: 2px; }
.ds-lbl  { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.ds-val  { font-size: 13px; font-weight: 700; color: var(--text); }
.ds-val.up    { color: var(--gain); }
.ds-val.down  { color: var(--loss); }
.ds-val.muted { color: var(--muted); font-weight: 500; font-size: 12px; }

/* Desktop detail row */
.dt tr { cursor: pointer; }
.dt-detail-row { cursor: default; }
.dt-detail-row td { padding: 0 !important; border-bottom: 2px solid var(--primary) !important; }
.dt-detail-inner {
  padding: 16px 16px;
  background: var(--bg);
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.dt-detail-sales { flex: 0 0 300px; }
.dt-detail-sales .detail-stats { grid-template-columns: 1fr 1fr 1fr; }
.dt-detail-cotc  { flex: 1; min-width: 280px; }

.cc:last-child { border-bottom: none; }
.av {
  width: 36px; height: 36px;
  border-radius: 50%;
  color: #fff;
  font-size: 10px; font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}
.cc-body { flex: 1; min-width: 0; }
.cc-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-meta { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.cc-right { text-align: right; flex-shrink: 0; padding-top: 2px; }
.cc-niv  { font-weight: 700; font-size: 13px; }
.cc-crec { font-size: 11px; font-weight: 600; margin-top: 3px; }
.cc-crec.up   { color: var(--gain); }
.cc-crec.down { color: var(--loss); }
.cc-crec.flat { color: var(--muted); }

/* ── Name indicator bar ────────────────────────────────────── */
.name-bar {
  height: 2px;
  border-radius: 1px;
  margin-top: 3px;
  margin-bottom: 1px;
  width: 55%;
  min-width: 30px;
}
.name-bar.up   { background: var(--gain); }
.name-bar.down { background: var(--loss); }
.name-bar.flat { background: var(--muted); opacity: .3; }

/* ── COTC Battery ───────────────────────────────────────────── */
.bat-wrap {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin: 0 4px;
}
.bat-body {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1.5px solid var(--border);
  border-right: none;
  border-radius: 3px 0 0 3px;
  background: var(--surface);
}
.bat-seg {
  width: 9px;
  height: 16px;
  border-radius: 2px;
  background: var(--border);
}
.bat-seg.ok   { background: var(--gain); }
.bat-seg.pend { background: #fed7aa; }
.bat-seg.none { background: var(--border); opacity: .4; }
.bat-tip {
  width: 4px;
  height: 8px;
  background: var(--border);
  border-radius: 0 2px 2px 0;
  align-self: center;
}

/* ── Tags / badges ─────────────────────────────────────────── */
.tag {
  display: inline-block;
  font-size: 9px; font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}
.tag-activo   { background: var(--gain-bg);  color: var(--gain); }
.tag-inactivo { background: #f1f5f9;          color: var(--muted); }
.tag-alarm-r  { background: var(--loss-bg);  color: var(--loss); }
.tag-alarm-w  { background: var(--warn-bg);  color: var(--warn); }
.tag-alarm-y  { background: var(--yel-bg);   color: var(--yel); }
.tag-cotc-ok  { background: var(--gain-bg);  color: var(--gain); }
.tag-cotc-no  { background: #f1f5f9;          color: var(--muted); }

/* ── Desktop Table ─────────────────────────────────────────── */
.desktop-table-wrap { display: none; overflow-x: auto; }
.dt {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.dt th {
  padding: 9px 12px;
  text-align: left;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.dt th:hover   { color: var(--primary); }
.dt th.sorted  { color: var(--primary); }
.sort-icon { margin-left: 3px; opacity: .45; font-style: normal; }
.dt th.sorted .sort-icon { opacity: 1; }
.dt td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.dt tr:last-child td { border-bottom: none; }
.dt tr:hover td { background: #fafafa; }
.td-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.td-pop  { color: var(--muted); white-space: nowrap; }
.td-niv  { text-align: right; font-weight: 600; white-space: nowrap; }
.td-niv.aa { color: var(--muted); font-weight: 400; font-size: 11px; }
.td-crec { text-align: right; font-weight: 700; white-space: nowrap; }
.td-crec.up   { color: var(--gain); }
.td-crec.down { color: var(--loss); }
.td-crec.flat { color: var(--muted); }
.td-med  { text-align: center; color: var(--muted); font-weight: 600; }
.td-tags { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; min-width: 60px; }

/* ── Table Footer ──────────────────────────────────────────── */
.table-footer {
  padding: 10px 14px;
  font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.btn-more {
  padding: 6px 14px;
  border: 1px solid var(--primary);
  border-radius: var(--rs);
  background: transparent;
  color: var(--primary);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all var(--tr);
}
.btn-more:hover { background: var(--primary); color: #fff; }

/* ── Loading / Error ───────────────────────────────────────── */
.loading-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; z-index: 999;
}
.loading-logo {
  font-size: 18px; font-weight: 800; color: var(--primary);
  display: flex; align-items: center; gap: 8px;
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--muted); }
.error-screen {
  position: fixed; inset: 0; background: var(--bg);
  flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; z-index: 999; display: none;
}
.error-icon { font-size: 36px; }
.error-msg  { font-size: 14px; color: var(--loss); font-weight: 600; }
.error-hint { font-size: 12px; color: var(--muted); }

/* ── Login ─────────────────────────────────────────────────── */
.lc-login-page {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-wrap  { width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo  {
  font-size: 22px; font-weight: 800; letter-spacing: -1px; color: var(--primary);
  display: flex; align-items: center; justify-content: center; gap: 9px; margin-bottom: 6px;
}
.login-tagline { font-size: 13px; color: var(--muted); }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 30px;
  box-shadow: 0 4px 20px rgba(0,0,0,.08);
}
.login-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--muted); margin-bottom: 22px; }
.field       { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.field label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.field input {
  border: 1px solid var(--border); border-radius: var(--rs);
  padding: 11px 14px; font-size: 14px; color: var(--text);
  background: var(--bg); width: 100%;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(227,6,19,.12); }
.btn-login {
  width: 100%; padding: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--rs);
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity var(--tr);
}
.btn-login:hover { opacity: .88; }
.lc-login-alert {
  padding: 11px 14px; border-radius: var(--rs);
  font-size: 13px; font-weight: 500; margin-bottom: 16px;
  background: var(--loss-bg); color: var(--loss); border: 1px solid #fed7aa;
}
.login-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--muted); }

/* ── Overlay ───────────────────────────────────────────────── */
#lc-overlay {
  position: fixed; inset: 0; z-index: 99999;
  overflow-y: auto; background: var(--bg);
}
#lc-overlay header { position: sticky; }
#lc-overlay .loading-screen,
#lc-overlay .error-screen { position: absolute; }

/* ══════════════════════════════════════════════════════════
   TABLET  ≥ 640px
   ══════════════════════════════════════════════════════════ */
@media (min-width: 640px) {
  header { padding: 0 20px; height: 58px; }
  .logo  { font-size: 17px; }
  .header-meta { display: block; }

  .filters-inner { grid-template-columns: repeat(3, 1fr); }
  .fg-action { grid-column: auto; flex-direction: column; align-items: stretch; gap: 6px; }
  .btn-reset { flex: none; }

  main { padding: 16px 20px; gap: 16px; }

  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi-val { font-size: 22px; }

  .alarm-strip { grid-template-columns: repeat(3, 1fr); }
  .alarm-card:last-child { grid-column: auto; }

  .charts-top { flex-direction: row; gap: 14px; }
  .chart-canal { flex: 0 0 260px; }
  .chart-dsr   { flex: 1; min-width: 0; }

  .table-header { padding: 12px 18px; }
  .cc { padding: 12px 18px; }
  .table-footer { padding: 10px 18px; }
}

/* ══════════════════════════════════════════════════════════
   DESKTOP  ≥ 1024px
   ══════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
  header { padding: 0 24px; }
  .logo  { font-size: 19px; }

  .filters-inner {
    grid-template-columns: repeat(5, 1fr) auto;
    align-items: end;
    gap: 10px;
  }
  .fg-action {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  .btn-reset { width: 100%; }

  main { padding: 20px 24px; gap: 18px; }

  .kpi-val { font-size: 24px; }

  /* Desktop: hide mobile cards, show table */
  .client-cards        { display: none; }
  .desktop-table-wrap  { display: block; }

  .chart-wrap-donut { height: 260px; }
  .chart-wrap-bar   { height: 260px; }
  .chart-wrap-act   { height: 220px; }
}
