:root {
  /* Brand EYCOT */
  --eycot-navy: #1B2D5C;
  --eycot-navy-2: #243B7A;
  --eycot-navy-dark: #122047;
  --eycot-red: #D62229;
  --eycot-red-2: #B41A20;
  --eycot-accent: #5E7AC0;
  --eycot-amber: #E0A800;
  /* Aliases legacy (apuntan a navy/red para no romper referencias) */
  --eycot-green: var(--eycot-navy);
  --eycot-green-2: var(--eycot-navy-2);
  --eycot-mint: var(--eycot-accent);
  --eycot-gold: var(--eycot-red);
  /* Tokens UI */
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #14213d;
  --ink-mute: #5a6680;
  --line: #dde2ec;
  --line-2: #bcc5d6;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, var(--eycot-navy) 0%, var(--eycot-navy-dark) 100%);
  color: #e4ebf7;
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 4px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo { width: 130px; height: auto; }
.brand-sub { font-size: 10.5px; color: #a9b8e0; letter-spacing: .12em; text-transform: uppercase; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #8a9bc5; margin: 12px 6px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: #d4dcef; text-decoration: none; font-size: 14px;
  transition: background .12s;
}
.nav-link:hover { background: rgba(255,255,255,.06); }
.nav-link.active { background: rgba(214,34,41,.22); color: #fff; box-shadow: inset 3px 0 0 var(--eycot-red); }
.nav-icon { width: 18px; display: inline-block; text-align: center; opacity: .85; }
.nav-medidor-group { display: flex; flex-direction: column; gap: 2px; padding-left: 4px; }
.nav-medidor-group .nav-link { font-size: 13px; padding: 6px 10px; }
.nav-medidor-empty { font-size: 12px; color: #8a9bc5; padding: 4px 10px; }
/* Fila de medidor en sidebar: toggle ver/ocultar + link */
.nav-medidor-row { display: flex; align-items: center; gap: 6px; }
.nav-medidor-row .nav-link { flex: 1; min-width: 0; }
.nav-medidor-row .nav-link span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-medidor-row.meter-off { opacity: .45; }
.nav-meter-toggle {
  position: relative; flex-shrink: 0; cursor: pointer; border: 0; padding: 0;
  width: 30px; height: 16px; border-radius: 16px;
  background: rgba(255,255,255,.22); transition: background .2s;
}
.nav-meter-toggle::before {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.nav-meter-toggle[aria-pressed="true"] { background: #2da95a; }
.nav-meter-toggle[aria-pressed="true"]::before { transform: translateX(14px); }
.nav-meter-toggle:hover { filter: brightness(1.08); }
.nav-meter-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* Sidebar foot */
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.dev-credit-side {
  margin-top: 10px;
  text-align: center;
  font-size: 9px;
  color: #8a9bc5;
  letter-spacing: .04em;
  line-height: 1.4;
  padding: 0 4px;
}
.dev-credit-side .by { display: block; opacity: .7; margin-bottom: 4px; }
.dev-credit-side img { height: 22px; opacity: .85; }
.vendedor-card { background: rgba(255,255,255,.04); border-radius: 8px; padding: 10px; }
.vendedor-label { font-size: 11px; color: #a9b8e0; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 6px; }
.user-row { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--eycot-red); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-folio-prefix { font-size: 11px; color: #a9b8e0; }
.btn-mini {
  background: rgba(255,255,255,.06); color: #fff; border: 0;
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 13px;
}
.btn-mini:hover { background: rgba(255,255,255,.12); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.badge {
  background: #eaf0fb; color: var(--eycot-navy-2);
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line);
}
.badge.ok { background: #e7f6ec; color: #1e7a3b; border-color: #b9e2c6; }
.badge.warn { background: #fff5db; color: #8a6300; border-color: #f0d99a; }
.badge.err, .badge.bad { background: #fde9e8; color: var(--eycot-red-2); border-color: #f3b8b5; }
.badge.muted { background: #f4f5f9; color: #8a93a8; border-color: var(--line); }

/* Switch toggle ON/OFF (checkbox + label sliding) */
.switch {
  position: relative; display: inline-block; width: 44px; height: 24px;
  flex-shrink: 0;
}
.switch input {
  position: absolute; opacity: 0; width: 100%; height: 100%;
  margin: 0; cursor: pointer; z-index: 2;
}
.switch .slider {
  position: absolute; pointer-events: none; inset: 0;
  background: #c8d0de; transition: background .25s, transform .25s; border-radius: 24px;
  z-index: 1;
}
.switch .slider::before {
  position: absolute; content: ""; height: 18px; width: 18px;
  left: 3px; top: 3px; background: #fff; transition: .25s; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: #2da95a; }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + .slider { opacity: .5; }

/* Botón switch alternativo (más confiable que checkbox) */
.btn-switch {
  position: relative; display: inline-block;
  width: 48px; height: 26px; border-radius: 26px;
  background: #c8d0de; border: 0; padding: 0; cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
}
.btn-switch::before {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.btn-switch[aria-pressed="true"] { background: #2da95a; }
.btn-switch[aria-pressed="true"]::before { transform: translateX(22px); }
.btn-switch:hover { filter: brightness(1.05); }
.btn-switch:focus-visible { outline: 2px solid var(--eycot-navy-2); outline-offset: 2px; }

/* Tabla cumplimiento Calidad de Energía */
.ce-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.ce-table th, .ce-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.ce-table th { background: #f7f9fd; font-weight: 600; color: var(--eycot-navy-2); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.ce-table tbody tr:hover { background: #fafbfd; }

.view { padding: 22px 24px 64px; }

/* Headings */
h2 { margin: 0 0 12px; font-size: 22px; font-weight: 700; color: var(--ink); }
h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; color: var(--ink); }
p { margin: 0 0 10px; color: var(--ink-mute); line-height: 1.5; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  cursor: pointer; transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: #eef2f8; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--eycot-navy); color: #fff; border-color: var(--eycot-navy); }
.btn-primary:hover { background: var(--eycot-navy-2); }
.btn-block { width: 100%; justify-content: center; }
.btn-danger { background: var(--eycot-red); border-color: var(--eycot-red); color: #fff; }
.btn-danger:hover { background: var(--eycot-red-2); }
.btn-accent { background: var(--eycot-red); color: #fff; border-color: var(--eycot-red); }
.btn-accent:hover { background: var(--eycot-red-2); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #eef2f8; }

/* Forms */
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 12px; font-weight: 600; color: var(--ink-mute); letter-spacing: .02em; }
.input, .select, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2);
  border-radius: 8px; font-size: 14px; font-family: inherit;
  background: #fff; color: var(--ink); transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--eycot-navy-2);
  box-shadow: 0 0 0 3px rgba(27, 45, 92, .14);
}
.select-mini {
  padding: 5px 8px; border: 1px solid var(--line-2); border-radius: 6px;
  background: #fff; font-size: 13px;
}
.hint { font-size: 12px; color: var(--ink-mute); }

/* Cards / grid */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  :root { --sidebar-w: 64px; }
  .brand-logo, .brand-sub, .nav-link span:last-child, .vendedor-card, .nav-section { display: none; }
  .nav-link { justify-content: center; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Alerts */
.alert {
  border-radius: 8px; padding: 12px 14px; font-size: 14px; margin: 8px 0;
  border: 1px solid var(--line-2); background: #fafcfb; color: var(--ink);
}
.alert-info { background: #eaf0fb; border-color: #c5d3ed; color: var(--eycot-navy-2); }
.alert-warn { background: #fff5db; border-color: #f0d99a; color: #6f4e00; }
.alert-error { background: #fde9e8; border-color: #f3b8b5; color: var(--eycot-red-2); }
.alert-ok { background: #e7f6ec; border-color: #b9e2c6; color: #1e7a3b; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { background: #f4f7fc; font-weight: 600; color: var(--ink-mute); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.table tr:hover td { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Utility */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flex-gap { display: flex; gap: 10px; flex-wrap: wrap; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.muted { color: var(--ink-mute); }
.mono { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: 13px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 16, .45); display: grid; place-items: center; z-index: 50; }
.modal {
  background: #fff; border-radius: 12px; padding: 22px; width: min(520px, 92vw);
  box-shadow: 0 12px 32px rgba(0,0,0,.18);
}
.modal h3 { margin: 0 0 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Demo banner */
#demo-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: linear-gradient(90deg, #D62229 0%, #B41A20 100%);
  color: #fff; font-size: 13px; padding: 7px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
#demo-banner code { background: rgba(255,255,255,.18); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
#demo-banner .demo-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 4px rgba(255,255,255,.25); flex-shrink: 0;
  animation: demo-pulse 1.6s ease-in-out infinite;
}
@keyframes demo-pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
body:has(#demo-banner) { padding-top: 34px; }
body:has(#demo-banner) .sidebar { top: 34px; height: calc(100vh - 34px); }
body:has(#demo-banner) .topbar { top: 34px; }
