/* ==========================================================================
   ByeCFE Cloud Portal - Hoymiles S-Miles Style Light Theme CSS v2.0
   ========================================================================== */

:root {
  --bg-app: #f4f7fb;
  --bg-card: #ffffff;
  --bg-card-hover: #fcfdfe;
  --border-card: #e2e8f0;
  --border-light: #edf2f7;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --color-cfe: #0284c7;       /* Blue: Red Eléctrica CFE */
  --color-cfe-light: #e0f2fe;
  --color-solar: #10b981;     /* Green: Solar & Exportación */
  --color-solar-light: #d1fae5;
  --color-home: #f59e0b;      /* Amber: Consumo del Hogar */
  --color-home-light: #fef3c7;
  --color-night: #6366f1;     /* Indigo: Nocturno */
  --color-night-light: #e0e7ff;
  --color-danger: #ef4444;    /* Alarma Roja */
  --color-danger-light: #fee2e2;
  --color-warning: #f59e0b;   /* Alarma Amarilla */
  --color-warning-light: #fef3c7;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-card: 0 4px 16px -2px rgba(15, 23, 42, 0.06), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
  --shadow-hover: 0 8px 24px -4px rgba(15, 23, 42, 0.1);
  --shadow-modal: 0 20px 40px -8px rgba(0, 0, 0, 0.2);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ================= Top Navigation Bar ================= */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid var(--border-card);
  padding: 0.75rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 12px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-img {
  height: 38px;
  width: auto;
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--color-cfe-light);
  color: var(--color-cfe);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

/* Property / Multi-Home Switcher */
.property-switcher-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border-card);
  padding: 5px 12px;
  border-radius: var(--radius-full);
}

.switcher-icon {
  font-size: 1.1rem;
}

.property-select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-solar);
  background: var(--color-solar-light);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: var(--color-solar);
  border-radius: 50%;
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.btn-nav {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-nav:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

.btn-admin {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.btn-admin:hover {
  background: #dbeafe;
}

/* ================= Alarm Banner (Demanda) ================= */
.alarm-banner {
  display: none;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  align-items: center;
  justify-content: space-between;
  animation: slideDown 0.3s ease;
}

.alarm-yellow {
  display: flex;
  background: var(--color-warning-light);
  border: 1px solid #fcd34d;
  color: #92400e;
}

.alarm-red {
  display: flex;
  background: var(--color-danger-light);
  border: 1px solid #fca5a5;
  color: #991b1b;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================= Main Container ================= */
.portal-container {
  max-width: 1360px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* House Info Bar */
.house-header-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-card);
  padding: 1.25rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow-card);
}

.house-title-group h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-edit-title {
  background: transparent;
  border: none;
  color: var(--color-cfe);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.btn-edit-title:hover {
  background: var(--color-cfe-light);
}

.house-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.house-meta span b {
  color: var(--text-main);
}

.house-tariff-pill {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ================= Period Selector Card ================= */
.period-selector-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1rem 1.75rem;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.period-title-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.period-header-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.period-active-tag {
  background: var(--color-cfe-light);
  color: var(--color-cfe);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

.period-buttons-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-period {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  padding: 7px 16px;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-period:hover {
  background: #e2e8f0;
  color: var(--text-main);
  transform: translateY(-1px);
}

.btn-period.active {
  background: var(--color-cfe);
  color: #ffffff;
  border-color: var(--color-cfe);
  box-shadow: 0 4px 10px -2px rgba(2, 132, 199, 0.35);
}

.tariff-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #065f46;
  text-transform: uppercase;
}

.tariff-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: #047857;
}

/* ================= Hoymiles Style Power Flow ================= */
.power-flow-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-card);
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow-card);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 8px;
}

.section-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.power-flow-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  position: relative;
  align-items: stretch;
}

@media (max-width: 1100px) {
  .power-flow-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .power-flow-grid {
    grid-template-columns: 1fr;
  }
}

.flow-node {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.flow-node:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.node-icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  margin-bottom: 0.75rem;
}

.node-solar .node-icon-circle { background: #ecfdf5; color: var(--color-solar); border: 2px solid #a7f3d0; }
.node-grid .node-icon-circle  { background: #f0f9ff; color: var(--color-cfe);   border: 2px solid #bae6fd; }
.node-home .node-icon-circle  { background: #fffbeb; color: var(--color-home);  border: 2px solid #fde68a; }
.node-ref .node-icon-circle   { background: #fffbeb; color: #b45309;            border: 2px solid #fde68a; }

.node-ref {
  background: #fffdf5;
  border: 1px dashed #f59e0b;
}

.node-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.node-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  margin: 4px 0;
}

.node-unit {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}

.node-subtext {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 4px;
}

.node-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-top: 6px;
}

.badge-importing { background: var(--color-cfe-light); color: var(--color-cfe); }
.badge-exporting { background: var(--color-solar-light); color: var(--color-solar); }
.badge-neutral   { background: #f1f5f9; color: var(--text-muted); }

/* ================= 4-Key Metrics Cards Row ================= */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.metric-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.metric-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.metric-icon-small {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.metric-val-main {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.metric-footer {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border-light);
  padding-top: 6px;
}

.card-import .metric-icon-small { background: var(--color-cfe-light); color: var(--color-cfe); }
.card-export .metric-icon-small { background: var(--color-solar-light); color: var(--color-solar); }
.card-net .metric-icon-small    { background: #ede9fe; color: #7c3aed; }
.card-cost .metric-icon-small   { background: #fef2f2; color: #dc2626; }

/* Alert Variations for Balance Neto and Costo */
.metric-card.card-net.net-ok, .metric-card.card-cost.cost-ok {
  border: 1.5px solid #a7f3d0 !important;
  background: #f0fdf4 !important;
}
.metric-card.card-net.net-warn, .metric-card.card-cost.cost-warn {
  border: 2px solid #fcd34d !important;
  background: #fffdf5 !important;
  box-shadow: 0 4px 12px -2px rgba(245, 158, 11, 0.18) !important;
}
.metric-card.card-net.net-alert, .metric-card.card-cost.cost-alert {
  border: 2px solid #fca5a5 !important;
  background: #fef2f2 !important;
  box-shadow: 0 4px 12px -2px rgba(220, 38, 38, 0.22) !important;
}

/* ================= Main Charts & Breakdowns (2 Columns) ================= */
.dashboard-grid-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
}

.chart-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.view-toggle-bar {
  display: flex;
  background: #f1f5f9;
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.btn-toggle-view {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-toggle-view.active {
  background: #ffffff;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.quick-date-pills {
  display: flex;
  gap: 4px;
}

.pill-date {
  border: 1px solid var(--border-card);
  background: #ffffff;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
}

.pill-date.active {
  background: var(--color-cfe);
  color: #ffffff;
  border-color: var(--color-cfe);
}

.chart-canvas-container {
  position: relative;
  height: 320px;
  width: 100%;
  margin-top: 1rem;
}

/* ================= Tabla Detallada Hora por Hora ================= */
.table-container {
  display: none;
  margin-top: 1rem;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border-card);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.tag-period {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}
.tag-day   { background: #fef9c3; color: #a16207; }
.tag-night { background: #e0e7ff; color: #4338ca; }

.alarm-badge-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
}
.badge-ok     { background: #ecfdf5; color: #047857; }
.badge-warn   { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }

/* ================= Diurno vs Nocturno Card ================= */
.day-night-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.day-night-split-box {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin: 1.25rem 0;
}

.period-row {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.period-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.period-icon-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.period-day .period-icon-circle { background: #fef9c3; color: #ca8a04; }
.period-night .period-icon-circle { background: var(--color-night-light); color: var(--color-night); }

.period-info h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.period-info p {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.period-metrics {
  text-align: right;
}

.period-kwh {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-main);
}

.period-cost {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-danger);
}

.pct-bar-track {
  height: 8px;
  width: 100%;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}

.pct-bar-day   { background: #eab308; height: 100%; transition: width 0.4s ease; }
.pct-bar-night { background: #6366f1; height: 100%; transition: width 0.4s ease; }

/* ================= Mensual & Bimestral Row ================= */
.summaries-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.summary-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.summary-details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

.summary-item-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.summary-item-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 2px;
}

.summary-highlight-box {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.highlight-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.highlight-money {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-danger);
}

/* ================= MODALS (Auth, Profile, Admin) ================= */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border-card);
  overflow: hidden;
  animation: modalPop 0.25s ease;
}

@keyframes modalPop {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  padding: 8px 12px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

.form-control:focus {
  border-color: var(--color-cfe);
  box-shadow: 0 0 0 2px var(--color-cfe-light);
}

.toggle-switch-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.toggle-switch-group span {
  font-size: 0.88rem;
  font-weight: 600;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--color-solar); }
input:checked + .slider:before { transform: translateX(20px); }

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

.btn-primary {
  background: var(--color-cfe);
  color: #ffffff;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: #0369a1;
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-muted);
  border: 1px solid var(--border-card);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

/* ================= Clean Customer Footer ================= */
.app-footer {
  text-align: center;
  padding: 1.75rem 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-card);
  margin-top: 2rem;
  background: #ffffff;
}

/* ================= Solar Weather & Climate Factors Card ================= */
.solar-weather-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffffff 0%, #fefce8 100%);
}

.solar-weather-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 12px;
}

.solar-weather-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.solar-card-icon {
  font-size: 2.2rem;
  background: #fef08a;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(234, 179, 8, 0.25);
}

.solar-weather-title-group h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.solar-weather-title-group p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.solar-efficiency-tag {
  background: #ffffff;
  border: 1px solid #fde047;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: #854d0e;
  box-shadow: var(--shadow-sm);
}

.solar-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 1.25rem;
}

.solar-stat-item {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.solar-stat-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.solar-stat-val {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ca8a04;
  margin-bottom: 2px;
}

.solar-stat-sub {
  font-size: 0.74rem;
  color: var(--text-light);
}

.climate-factors-wrapper {
  background: #ffffff;
  border: 1px solid #fef08a;
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
}

.climate-factors-title {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: #854d0e;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.climate-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.climate-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: #fdfdfd;
  transition: all 0.2s ease;
}

.climate-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.climate-card.active-factor {
  border-color: #facc15;
  background: #fefce8;
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.35);
}

.climate-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.climate-emoji {
  font-size: 1.6rem;
}

.climate-status-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-factor-high {
  background: #dcfce7;
  color: #15803d;
}

.badge-factor-med {
  background: #fef3c7;
  color: #b45309;
}

.badge-factor-low {
  background: #e2e8f0;
  color: #475569;
}

.climate-card strong {
  display: block;
  font-size: 0.84rem;
  color: var(--text-main);
  margin-bottom: 4px;
}

.climate-card p {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ================= Budget Target Progress Box ================= */
.budget-target-box {
  margin-top: 14px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.budget-target-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.84rem;
  margin-bottom: 8px;
}

.budget-progress-track {
  width: 100%;
  height: 8px;
  background: #f1f5f9;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 8px;
}

.budget-progress-bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: #10b981;
  transition: width 0.4s ease;
}

.budget-progress-bar.bar-overrun {
  background: #f97316;
}

.budget-status-sub {
  display: flex;
  justify-content: flex-end;
}

.badge-budget-ok {
  font-size: 0.75rem;
  font-weight: 700;
  color: #059669;
  background: #d1fae5;
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

.badge-budget-overrun {
  font-size: 0.75rem;
  font-weight: 700;
  color: #c2410c;
  background: #ffedd5;
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

/* ================= Expediente Cliente & AWS S3 Styles ================= */
.btn-expediente {
  background: #f0fdf4 !important;
  color: #15803d !important;
  border: 1px solid #bbf7d0 !important;
  font-weight: 700;
}

.btn-expediente:hover {
  background: #dcfce7 !important;
}

.modal-large {
  max-width: 880px !important;
  width: 95%;
}

.modal-tabs-bar {
  display: flex;
  gap: 8px;
  padding: 0 1.5rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-card);
}

.modal-tab-btn {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.modal-tab-btn:hover {
  color: var(--color-cfe);
}

.modal-tab-btn.active {
  color: var(--color-cfe);
  border-bottom-color: var(--color-cfe);
  background: #ffffff;
}

.modal-tab-pane {
  display: none;
}

.modal-tab-pane.active {
  display: block;
}

.expediente-section-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.expediente-section-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.s3-info-banner {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 10px;
}

.s3-info-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.s3-badge-icon {
  font-size: 1.8rem;
}

.s3-info-left strong {
  display: block;
  font-size: 0.88rem;
  color: #0369a1;
}

.s3-info-left p {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.s3-info-left code {
  background: rgba(255, 255, 255, 0.8);
  padding: 2px 6px;
  border-radius: 4px;
  color: #0284c7;
  font-weight: 600;
}

.s3-status-badge {
  background: #0284c7;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.upload-box-card {
  background: #f8fafc;
  border: 1px dashed var(--color-cfe);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.docs-category-group {
  margin-bottom: 1.5rem;
}

.docs-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 6px;
}

.docs-category-header h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.badge-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: #e2e8f0;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.docs-grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.doc-file-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.doc-file-card:hover {
  box-shadow: var(--shadow-card);
  border-color: #cbd5e1;
}

.doc-file-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.doc-file-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.doc-file-meta {
  flex: 1;
  overflow: hidden;
}

.doc-file-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.doc-file-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

.doc-file-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-light);
  border-top: 1px solid var(--border-light);
  padding-top: 8px;
  margin-top: 6px;
}

.doc-actions {
  display: flex;
  gap: 6px;
}

.btn-doc-action {
  background: #f1f5f9;
  border: 1px solid var(--border-card);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--text-main);
  text-decoration: none;
  font-weight: 600;
}

.btn-doc-action:hover {
  background: #e2e8f0;
}

.btn-doc-delete {
  color: #dc2626;
}

.btn-doc-delete:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

.photos-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.photo-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  position: relative;
}

.photo-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.photo-thumbnail-box {
  width: 100%;
  height: 140px;
  background: #f1f5f9;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

.photo-thumbnail-box img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.photo-thumbnail-box:hover img {
  transform: scale(1.05);
}

.photo-zoom-hint {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.photo-card-info {
  padding: 8px 10px;
}

.photo-card-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.photo-card-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.photo-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-top: 1px solid var(--border-light);
  background: #fafafa;
}

/* Lightbox Modal */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.88);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  object-fit: contain;
}

.lightbox-caption {
  color: #ffffff;
  margin-top: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.lightbox-close {
  position: absolute;
  top: -36px;
  right: 0;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}

/* ==========================================================================
   Mobile-First & iPhone / iPad Responsive Excellence
   Breakpoints: Mobile (320px-480px), Tablet (768px-1024px), Desktop (1200px+)
   ========================================================================== */

/* iOS Safari Safe Areas and Base Reset */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

body.auth-locked {
  overflow: hidden !important;
}

/* Prevent annoying iOS auto-zoom by enforcing 16px font-size on all form elements */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  font-size: 16px !important;
}

/* Touch controls minimum target size (Apple HIG: 44px min) */
button, 
.btn-nav, 
.btn-period, 
.btn-toggle-view,
.btn-primary, 
.btn-secondary {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Login Gate Modal (Full Screen with Blur) */
.login-gate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card-custom {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  width: 100%;
  max-width: 440px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  padding: 1.75rem;
  box-sizing: border-box;
  animation: modalFadeIn 0.25s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Responsive Table Wrapper with Touch Inertia */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  border: 1px solid var(--border-card);
  margin-top: 10px;
}

.data-table {
  min-width: 720px;
  width: 100%;
  border-collapse: collapse;
}

/* Tablet Optimizations (max-width: 1024px) */
@media (max-width: 1024px) {
  .power-flow-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }
  .solar-stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  .climate-cards-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  .metrics-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .dashboard-grid-2col {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .summaries-row {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

/* Smartphone & iPhone Optimizations (max-width: 768px) */
@media (max-width: 768px) {
  .portal-container {
    padding: 0.75rem;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }

  /* Top Navigation Bar */
  .navbar {
    padding: 0.65rem 0.85rem;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .nav-brand {
    justify-content: space-between;
    width: 100%;
  }

  .brand-logo-img {
    height: 32px;
  }

  .property-switcher-wrapper {
    width: 100%;
    justify-content: flex-start;
    padding: 6px 12px;
  }

  .property-select {
    width: 100%;
    font-size: 0.85rem;
  }

  .nav-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
  }

  .nav-actions .btn-nav {
    flex: 1 1 calc(50% - 6px);
    justify-content: center;
    padding: 7px 8px;
    font-size: 0.76rem;
    min-height: 38px;
  }

  .nav-actions .btn-nav:last-child {
    flex: 0 0 38px;
  }

  .live-indicator {
    padding: 4px 8px;
    font-size: 0.70rem;
  }

  /* House Title Card */
  .house-header-card {
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .house-title-group h2 {
    font-size: 1.15rem;
    flex-wrap: wrap;
    gap: 6px;
  }

  .house-meta {
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.75rem;
  }

  .house-tariff-pill {
    align-self: flex-start;
    padding: 4px 10px;
    font-size: 0.80rem;
  }

  /* Period Selector Carousel */
  .period-selector-card {
    padding: 0.75rem;
  }

  .period-title-block {
    margin-bottom: 6px;
    font-size: 0.80rem;
  }

  .period-buttons-group {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 4px;
    width: 100%;
  }

  .period-buttons-group::-webkit-scrollbar {
    display: none;
  }

  .btn-period {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 0.80rem;
    border-radius: 20px;
  }

  /* Power Flow Grid (2x2 on Mobile) */
  .power-flow-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .flow-node {
    padding: 10px 8px;
    text-align: center;
  }

  .flow-node .node-value {
    font-size: 1.25rem;
  }

  .flow-node .node-unit {
    font-size: 0.75rem;
  }

  .flow-node .node-title {
    font-size: 0.75rem;
  }

  .flow-node .node-subtext {
    font-size: 0.68rem;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .node-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
  }

  /* Solar Weather Card */
  .solar-weather-card {
    padding: 1rem;
  }

  .solar-weather-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .solar-weather-title-group h3 {
    font-size: 0.95rem;
  }

  .solar-stats-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .climate-cards-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* 4 Metrics Cards (2x2 on Mobile) */
  .metrics-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .metric-card {
    padding: 10px 12px;
  }

  .metric-val-main {
    font-size: 1.25rem;
  }

  .metric-label {
    font-size: 0.74rem;
  }

  .metric-footer {
    font-size: 0.68rem;
  }

  /* Chart & Tabs */
  .chart-card {
    padding: 0.85rem;
  }

  .chart-canvas-container {
    height: 250px !important;
    min-height: 250px;
    max-height: 260px;
    position: relative;
    width: 100%;
  }

  .view-toggle-bar {
    width: 100%;
    display: flex;
    gap: 6px;
    margin-top: 6px;
  }

  .btn-toggle-view {
    flex: 1;
    text-align: center;
    padding: 8px 10px;
    font-size: 0.80rem;
  }

  /* Modals on Mobile Screens */
  .modal-overlay {
    padding: 8px;
    align-items: flex-end;
  }

  .modal-card {
    width: 100%;
    max-height: 90vh;
    border-radius: 20px 20px 0 0;
    margin: 0;
  }

  .modal-header {
    padding: 1rem 1.2rem;
  }

  .modal-body {
    padding: 1rem 1.2rem;
  }

  .modal-footer {
    padding: 0.85rem 1.2rem;
  }

  .login-card-custom {
    border-radius: 20px !important;
    margin: auto !important;
  }
}

/* Extra Compact Phones: iPhone SE, etc. (max-width: 360px) */
@media (max-width: 360px) {
  .power-flow-grid {
    grid-template-columns: 1fr;
  }
  .metrics-row {
    grid-template-columns: 1fr;
  }
  .nav-actions .btn-nav {
    flex: 1 1 100%;
  }
}

