/* =========================================================================
   DeyeMonitor · tema propio sobre Bootstrap 5 + CoreUI Free
   Identidad: tecnológica, limpia, premium. Nada de neón ni estética gaming.
   ========================================================================= */

:root {
  --dm-solar: #f6a821;
  --dm-solar-soft: rgba(246, 168, 33, .15);
  --dm-battery: #23c48f;
  --dm-battery-soft: rgba(35, 196, 143, .15);
  --dm-load: #4d8bf0;
  --dm-load-soft: rgba(77, 139, 240, .15);
  --dm-grid: #9b6bf2;
  --dm-grid-soft: rgba(155, 107, 242, .15);
  --dm-critical: #e5484d;
  --dm-warning: #f5a623;
  --dm-ok: #23c48f;
  --dm-radius: 16px;
  --dm-radius-sm: 10px;
  --dm-transition: 180ms cubic-bezier(.4, 0, .2, 1);
  --dm-sidebar-width: 264px;
  --dm-header-height: 60px;
}

[data-theme="dark"] {
  --dm-bg: #070b14;
  --dm-bg-elevated: #0e1424;
  --dm-surface: #121a2c;
  --dm-surface-2: #162034;
  --dm-border: rgba(255, 255, 255, .07);
  --dm-border-strong: rgba(255, 255, 255, .14);
  --dm-text: #eaf0ff;
  --dm-text-muted: #8f9cba;
  --dm-shadow: 0 18px 40px rgba(0, 0, 0, .45);
  --dm-sidebar-bg: #0a1120;
  color-scheme: dark;
}

[data-theme="light"] {
  --dm-bg: #f3f5fa;
  --dm-bg-elevated: #ffffff;
  --dm-surface: #ffffff;
  --dm-surface-2: #f7f9fd;
  --dm-border: rgba(16, 24, 40, .08);
  --dm-border-strong: rgba(16, 24, 40, .16);
  --dm-text: #101828;
  --dm-text-muted: #667085;
  --dm-shadow: 0 14px 32px rgba(16, 24, 40, .08);
  --dm-sidebar-bg: #ffffff;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--dm-bg);
  color: var(--dm-text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.dm-dark-bg {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(77, 139, 240, .13), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(35, 196, 143, .10), transparent 55%),
    var(--dm-bg);
  background-attachment: fixed;
}

a {
  color: inherit;
  text-decoration: none;
}

h1, h2, h3, h4, h5 {
  font-weight: 650;
  letter-spacing: -.015em;
  margin: 0 0 .35rem;
}

.dm-muted { color: var(--dm-text-muted); }
.dm-mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.dm-small { font-size: .82rem; }
.dm-tiny { font-size: .74rem; }

/* ------------------------------------------------------------------ Layout */
.dm-app {
  display: flex;
  min-height: 100vh;
}

.dm-sidebar {
  width: var(--dm-sidebar-width);
  flex: 0 0 var(--dm-sidebar-width);
  background: var(--dm-sidebar-bg);
  border-right: 1px solid var(--dm-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  z-index: 30;
}

.dm-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
}

.dm-brand__mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
}

.dm-brand__name {
  font-weight: 700;
  font-size: 1.06rem;
  letter-spacing: -.02em;
}

.dm-brand__sub {
  font-size: .72rem;
  color: var(--dm-text-muted);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.dm-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding-bottom: 12px;
}

.dm-nav__group {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--dm-text-muted);
  margin: 14px 10px 6px;
}

.dm-nav__link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--dm-radius-sm);
  color: var(--dm-text-muted);
  font-weight: 520;
  transition: background var(--dm-transition), color var(--dm-transition);
}

.dm-nav__link svg {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  opacity: .9;
}

.dm-nav__link:hover {
  background: var(--dm-surface-2);
  color: var(--dm-text);
}

.dm-nav__link.is-active {
  background: linear-gradient(90deg, rgba(77, 139, 240, .18), rgba(77, 139, 240, .04));
  color: var(--dm-text);
  box-shadow: inset 2px 0 0 var(--dm-load);
}

.dm-sidebar__footer {
  margin-top: auto;
  border-top: 1px solid var(--dm-border);
  padding-top: 12px;
}

.dm-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.dm-user__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--dm-load), var(--dm-battery));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  font-size: .85rem;
}

.dm-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dm-topbar {
  height: var(--dm-header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--dm-border);
  background: color-mix(in srgb, var(--dm-bg) 82%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.dm-topbar__title {
  font-size: 1.02rem;
  font-weight: 650;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-content {
  padding: 22px 20px 40px;
  max-width: 1560px;
  width: 100%;
}

/* -------------------------------------------------------------- Componentes */
.dm-card {
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: var(--dm-radius);
  padding: 18px;
  box-shadow: var(--dm-shadow);
  min-width: 0;
}

.dm-card--flush { padding: 0; overflow: hidden; }
.dm-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.dm-card__title {
  font-size: .95rem;
  font-weight: 620;
}

.dm-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 100%;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  border: 1px solid var(--dm-border-strong);
  background: var(--dm-surface-2);
  white-space: nowrap;
}

.dm-status > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dm-text-muted);
  flex: 0 0 8px;
}

.dm-status--online .dm-dot { background: var(--dm-ok); box-shadow: 0 0 0 3px rgba(35, 196, 143, .18); }
.dm-status--offline .dm-dot { background: var(--dm-critical); box-shadow: 0 0 0 3px rgba(229, 72, 77, .18); }
.dm-status--stale .dm-dot { background: var(--dm-warning); box-shadow: 0 0 0 3px rgba(245, 166, 35, .18); }
.dm-status--offline { color: var(--dm-critical); }
.dm-status--stale { color: var(--dm-warning); }

.dm-kpi {
  position: relative;
  overflow: hidden;
  padding: 16px 16px 15px;
}

.dm-kpi__icon {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}

.dm-kpi__icon svg { width: 20px; height: 20px; }
.dm-kpi__label {
  font-size: .74rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--dm-text-muted);
  font-weight: 620;
}

.dm-kpi__value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.1;
  margin-top: 2px;
}

.dm-kpi__value small { font-size: .95rem; font-weight: 600; color: var(--dm-text-muted); margin-left: 3px; }
.dm-kpi__detail { font-size: .8rem; color: var(--dm-text-muted); margin-top: 4px; min-height: 1.2em; }

.dm-kpi--solar .dm-kpi__icon { background: var(--dm-solar-soft); color: var(--dm-solar); }
.dm-kpi--battery .dm-kpi__icon { background: var(--dm-battery-soft); color: var(--dm-battery); }
.dm-kpi--load .dm-kpi__icon { background: var(--dm-load-soft); color: var(--dm-load); }
.dm-kpi--grid .dm-kpi__icon { background: var(--dm-grid-soft); color: var(--dm-grid); }

.dm-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 620;
  border: 1px solid transparent;
}
.dm-badge--ok { background: var(--dm-battery-soft); color: var(--dm-battery); }
.dm-badge--warn { background: rgba(245, 166, 35, .15); color: var(--dm-warning); }
.dm-badge--crit { background: rgba(229, 72, 77, .15); color: var(--dm-critical); }
.dm-badge--info { background: var(--dm-load-soft); color: var(--dm-load); }
.dm-badge--muted { background: var(--dm-surface-2); color: var(--dm-text-muted); }

.dm-chart { position: relative; width: 100%; height: 320px; }
.dm-chart--sm { height: 220px; }
.dm-chart--tall { height: 380px; }

.dm-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.dm-table th {
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--dm-text-muted);
  font-weight: 620;
  padding: 10px 12px;
  border-bottom: 1px solid var(--dm-border);
  white-space: nowrap;
}
.dm-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--dm-border);
  vertical-align: middle;
}
.dm-table tbody tr:hover { background: var(--dm-surface-2); }
.dm-table tbody tr:last-child td { border-bottom: 0; }

.dm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 16px;
  border-radius: var(--dm-radius-sm);
  border: 1px solid var(--dm-border-strong);
  background: var(--dm-surface-2);
  color: var(--dm-text);
  font-weight: 600;
  font-size: .87rem;
  cursor: pointer;
  transition: background var(--dm-transition), border-color var(--dm-transition), transform var(--dm-transition);
}
.dm-btn:hover { border-color: var(--dm-load); }
.dm-btn:active { transform: translateY(1px); }
.dm-btn--primary {
  background: linear-gradient(135deg, #4d8bf0, #2f6fd0);
  border-color: transparent;
  color: #fff;
}
.dm-btn--ghost { background: transparent; }
.dm-btn--danger { background: rgba(229, 72, 77, .12); border-color: rgba(229, 72, 77, .35); color: var(--dm-critical); }
.dm-btn--sm { min-height: 32px; padding: 5px 11px; font-size: .8rem; }

.dm-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.dm-field > label { font-size: .8rem; font-weight: 600; color: var(--dm-text-muted); }
.dm-input, .dm-select {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: var(--dm-radius-sm);
  border: 1px solid var(--dm-border-strong);
  background: var(--dm-surface-2);
  color: var(--dm-text);
  font-size: .92rem;
}
.dm-input:focus, .dm-select:focus {
  outline: none;
  border-color: var(--dm-load);
  box-shadow: 0 0 0 3px rgba(77, 139, 240, .18);
}

.dm-segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--dm-surface-2);
  border: 1px solid var(--dm-border);
}
.dm-segmented a, .dm-segmented button {
  padding: 7px 12px;
  border-radius: 9px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--dm-text-muted);
  border: 0;
  background: transparent;
  cursor: pointer;
}
.dm-segmented a.is-active, .dm-segmented button.is-active {
  background: var(--dm-surface);
  color: var(--dm-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.dm-alert {
  display: flex;
  gap: 12px;
  padding: 13px 15px;
  border-radius: var(--dm-radius-sm);
  border: 1px solid var(--dm-border-strong);
  background: var(--dm-surface-2);
  margin-bottom: 10px;
}
.dm-alert--crit { border-color: rgba(229, 72, 77, .4); background: rgba(229, 72, 77, .08); }
.dm-alert--warn { border-color: rgba(245, 166, 35, .4); background: rgba(245, 166, 35, .08); }
.dm-alert--ok { border-color: rgba(35, 196, 143, .4); background: rgba(35, 196, 143, .08); }

/* ------------------------------------------------------------ Energy flow */
.dm-flow {
  position: relative;
  width: 100%;
}
.dm-flow svg { width: 100%; height: auto; display: block; }
.dm-flow__line { fill: none; stroke-width: 3; stroke-linecap: round; stroke: var(--dm-border-strong); }
.dm-flow__line.is-active { stroke-dasharray: 10 12; animation: dm-dash 1.1s linear infinite; }
.dm-flow__line--solar.is-active { stroke: var(--dm-solar); }
.dm-flow__line--battery.is-active { stroke: var(--dm-battery); }
.dm-flow__line--load.is-active { stroke: var(--dm-load); }
.dm-flow__line--grid.is-active { stroke: var(--dm-grid); }
.dm-flow__line.is-reverse { animation-direction: reverse; }
.dm-flow__node-label { font-size: 11px; fill: var(--dm-text-muted); letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
.dm-flow__node-value { font-size: 22px; fill: var(--dm-text); font-weight: 700; }
.dm-flow__node-sub { font-size: 11px; fill: var(--dm-text-muted); }
.dm-flow__hub { fill: var(--dm-surface-2); stroke: var(--dm-border-strong); }
.dm-flow__node-icon { fill: none; stroke-width: 1.8; }

@keyframes dm-dash {
  to { stroke-dashoffset: -44; }
}

/* -------------------------------------------------------------- Login page */
.dm-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(77, 139, 240, .18), transparent 55%),
    radial-gradient(800px 500px at 90% 90%, rgba(35, 196, 143, .16), transparent 55%),
    var(--dm-bg);
}
.dm-login__card {
  width: 100%;
  max-width: 400px;
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 20px;
  padding: 30px 26px;
  box-shadow: var(--dm-shadow);
}
.dm-login__brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; }

/* ---------------------------------------------------------------- Mobile */
.dm-bottomnav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--dm-surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--dm-border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.dm-bottomnav__items { display: flex; }
.dm-bottomnav__item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px;
  min-height: 52px;
  font-size: .68rem;
  font-weight: 600;
  color: var(--dm-text-muted);
  border-radius: 12px;
}
.dm-bottomnav__item svg { width: 21px; height: 21px; }
.dm-bottomnav__item.is-active { color: var(--dm-load); }

.dm-mobilebar { display: none; }

@media (max-width: 991.98px) {
  .dm-sidebar { display: none; }
  .dm-sidebar.is-open {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 300px);
    box-shadow: var(--dm-shadow);
  }
  .dm-content { padding: 16px 14px 96px; }
  .dm-topbar { padding: 0 14px; }
  .dm-mobilebar { display: inline-flex; }
  .dm-bottomnav { display: block; }
  .dm-kpi__value { font-size: 1.72rem; }
  .dm-chart { height: 260px; }
}

@media (max-width: 575.98px) {
  .dm-kpi { padding: 14px; }
  .dm-kpi__value { font-size: 1.6rem; }
  .dm-card { padding: 15px; }
  .dm-content { padding: 14px 12px 96px; }
  .dm-status { font-size: .68rem; padding: 4px 8px; gap: 5px; }
  .dm-status #dm-status-text { max-width: 118px; }
  .dm-topbar { gap: 8px; }
  .dm-topbar__title { font-size: .95rem; }
}

.dm-chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

.dm-scrim {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, .55);
  z-index: 25;
  display: none;
}
.dm-scrim.is-visible { display: block; }

.dm-offline-banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: rgba(229, 72, 77, .12);
  border-bottom: 1px solid rgba(229, 72, 77, .35);
  color: var(--dm-critical);
  font-size: .85rem;
  font-weight: 600;
}
.dm-offline-banner.is-visible { display: flex; }

.dm-grid { display: grid; gap: 16px; }
.dm-grid--kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dm-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dm-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

@media (max-width: 1199.98px) {
  .dm-grid--kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 991.98px) {
  .dm-grid--2, .dm-grid--3 { grid-template-columns: 1fr; }
}
@media (max-width: 575.98px) {
  .dm-grid--kpi { grid-template-columns: 1fr; }
}

.dm-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.dm-skip {
  position: absolute;
  left: -9999px;
}
.dm-skip:focus {
  left: 12px;
  top: 12px;
  z-index: 100;
  background: var(--dm-surface);
  padding: 8px 14px;
  border-radius: 8px;
}
