/* ==========================================================
 * PowerNet Dashboard Grid & Component Layout
 * Faithful to the aesthetic of Ref/interface.png
 * ========================================================== */

/* Top Metrics Section Grid */
.metrics-section {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 24px;
  margin-bottom: 24px;
}

/* Card 1 & 2: Voltage & Current (Left 2 columns, 2.2 cols each) */
.metric-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 170px;
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

/* Phase pages: three phase cards per row (/voltage-ll, /voltage-ln, /current), four with the average card
   (/power, /power-factor); smaller screens use the responsive.css grid */
@media (min-width: 1281px) {
  .phase-card { grid-column: span 4; }
  .metrics-section.quad .phase-card { grid-column: span 3; }
}

.metric-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.metric-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-icon-box {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0F172A;
  font-size: 18px;
}

.metric-value-wrap {
  margin-bottom: 12px;
}

.metric-value {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.75px;
  color: var(--text-primary);
  line-height: 1.1;
}

.metric-unit {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 2px;
}

/* Voltage type beside the unit: "V LL" (line to line) / "V LN" (line to neutral) */
.unit-suffix {
  margin-left: 3px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.metric-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
}

.delta-up {
  color: var(--success);
}

.delta-down {
  color: var(--danger);
}

.delta-neutral {
  color: var(--text-muted);
}

.delta-context {
  color: var(--text-muted);
  font-weight: 500;
}

/* Donut Metric Cards (Cards 3 & 4: Users / Subscriptions style from interface.png) */
.donut-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 170px;
  position: relative;
}

.donut-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.donut-content-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 4px;
}

.donut-stats {
  display: flex;
  flex-direction: column;
}

.donut-main-val {
  font-size: 34px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.75px;
}

.donut-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 12px;
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.donut-chart-container {
  width: 92px;
  height: 92px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.donut-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  transform: rotate(-90deg);
  display: block;
}

.donut-bg-circle {
  stroke: #F1F5F9;
  stroke-width: 6.5;
}

.donut-progress-circle {
  stroke-width: 6.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.donut-center-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: baseline;
  justify-content: center;
  pointer-events: none;
  user-select: none;
}

.donut-percent-num {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.donut-percent-sign {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin-left: 1px;
}

/* Secondary KPI Cards (Cumulative Energy, Temperature, Paid Invoices, Funds Received) */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 24px;
  margin-bottom: 24px;
}

/* KPI Card with circular percentage badge (like Paid Invoices +15%, Funds received +59% in interface.png) */
.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 170px;
  position: relative;
  transition: transform var(--transition-fast);
}

.kpi-card:hover {
  transform: translateY(-2px);
}

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0F172A;
  background: none;
  font-size: 20px;
}

.kpi-circular-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: conic-gradient(#A855F7 0deg 250deg, #E9D5FF 250deg 360deg);
  padding: 3.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-circular-badge span {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #7C3AED;
}

.kpi-circular-badge.green {
  background: conic-gradient(#22C55E 0deg 280deg, #DCFCE7 280deg 360deg);
}

.kpi-circular-badge.green span {
  color: #15803D;
}

.kpi-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 14px;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Charts & Logs Main Grid Layout */
.dashboard-main-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 24px;
}

.charts-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  width: 100%;
  max-width: 100%;
}

.charts-row .chart-card {
  margin-bottom: 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.chart-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-switcher {
  display: flex;
  background: #F1F5F9;
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.sw-btn {
  padding: 5px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.sw-btn.active {
  background: #0F172A;
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.16);
}

.sw-btn:hover:not(.active) {
  color: #0F172A;
}

/* Skeleton loading placeholder */
.skeleton-chart {
  width: 100%;
  height: 100%;
  min-height: 180px;
  border-radius: 12px;
  background: linear-gradient(90deg, #F1F5F9 25%, #E2E8F0 50%, #F1F5F9 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.chart-filter-pill {
  background: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Sales Dynamics Track-Column Bar Chart (Directly replicated from interface.png) */
@keyframes barGrowUp {
  0% {
    transform: scaleY(0);
    opacity: 0.25;
  }
  100% {
    transform: scaleY(1);
    opacity: 1;
  }
}

.bar-chart-visual {
  height: 240px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  align-items: stretch;
  position: relative;
  box-sizing: border-box;
  overflow: visible;
}

.chart-y-axis {
  flex-shrink: 0;
  width: 34px;
  height: 100%;
  padding: 46px 6px 28px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  box-sizing: border-box;
  user-select: none;
  background: var(--bg-card);
  z-index: 5;
}

.bar-chart-scroll-wrap {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow: visible;
  display: flex;
  align-items: flex-end;
  padding: 46px 6px 4px 6px;
  box-sizing: border-box;
  position: relative;
}

.bar-chart-bars-track {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 100%;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  gap: 4px;
}

.bar-chart-bars-track.is-30d {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  gap: 2px;
}

.bar-column-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
  justify-content: flex-end;
  min-width: 0;
}

.bar-chart-bars-track.is-30d .bar-column-group {
  flex: 1 1 0;
  min-width: 0;
}

.bar-chart-bars-track.is-30d .bar-track {
  width: 100%;
  max-width: 9px;
  height: 145px;
}

.bar-chart-bars-track.is-30d .bar-label {
  font-size: 8.5px;
  font-weight: 600;
  margin-top: 8px;
  letter-spacing: -0.3px;
}

/* The faint background track column behind the bar, as in interface.png */
.bar-track {
  width: 14px;
  height: 145px;
  background-color: #F1F4F9;
  border-radius: var(--radius-pill);
  position: relative;
  display: flex;
  align-items: flex-end;
  cursor: pointer;
  z-index: 1;
}

.bar-fill {
  width: 100%;
  background: var(--primary);
  border-radius: var(--radius-pill);
  transform-origin: bottom;
  animation: barGrowUp 0.65s cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: height 0.4s ease, background 0.2s ease;
}

.bar-track:hover {
  z-index: 60;
}

.bar-track:hover .bar-fill {
  background: #1D4ED8;
  filter: brightness(1.12);
}

.bar-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #FFFFFF;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 50;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

.bar-track:hover .bar-tooltip,
.bar-track:focus .bar-tooltip,
.bar-track:focus-visible .bar-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.bar-tooltip.align-right {
  left: auto;
  right: -8px;
  transform: none;
}

.bar-track:hover .bar-tooltip.align-right,
.bar-track:focus .bar-tooltip.align-right,
.bar-track:focus-visible .bar-tooltip.align-right {
  transform: translateY(-2px);
}

.bar-tooltip.align-left {
  left: -8px;
  right: auto;
  transform: none;
}

.bar-track:hover .bar-tooltip.align-left,
.bar-track:focus .bar-tooltip.align-left,
.bar-track:focus-visible .bar-tooltip.align-left {
  transform: translateY(-2px);
}

.bar-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px 5px 0;
  border-style: solid;
  border-color: rgba(15, 23, 42, 0.94) transparent;
}

.bar-tooltip.align-right::after {
  left: auto;
  right: 14px;
  transform: none;
}

.bar-tooltip.align-left::after {
  left: 14px;
  transform: none;
}

.bar-tooltip-date {
  font-size: 10.5px;
  color: #94A3B8;
  margin-bottom: 4px;
  font-weight: 500;
}

.bar-tooltip-val {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
  color: #FFFFFF;
}

.bar-tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.bar-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 8px;
  text-transform: uppercase;
}

/* Live Waveform Container & Visual Layout */
.waveform-canvas-container {
  height: 240px;
  width: 100%;
  position: relative;
}

.waveform-visual {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
  padding: 10px 10px 0 0;
}

.waveform-y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 54px;
  height: calc(100% - 30px);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  padding-right: 10px;
  user-select: none;
}

.waveform-plot-area {
  flex: 1;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  cursor: crosshair;
}

#waveform-svg {
  width: 100%;
  height: calc(100% - 30px);
  overflow: visible;
  display: block;
}

.waveform-x-axis {
  height: 30px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 4px 0 4px;
  user-select: none;
}

.waveform-tz-badge {
  font-size: 9.5px;
  font-weight: 700;
  background: #EFF6FF;
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  cursor: help;
}

.waveform-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #FFFFFF;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  transform: translate(-50%, -100%);
  margin-top: -12px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 25;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.waveform-tooltip.align-left {
  transform: translate(0%, -100%);
}

.waveform-tooltip.align-right {
  transform: translate(-100%, -100%);
}

.waveform-tooltip.visible {
  opacity: 1;
}

.waveform-tooltip::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px 5px 0;
  border-style: solid;
  border-color: rgba(15, 23, 42, 0.94) transparent;
}

.waveform-tooltip.align-left::after {
  left: 20px;
}

.waveform-tooltip.align-right::after {
  left: auto;
  right: 20px;
}

.waveform-tooltip-time {
  font-size: 10.5px;
  color: #94A3B8;
  margin-bottom: 4px;
  font-weight: 500;
}

.waveform-tooltip-val {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
}

.waveform-tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Customer Orders Style Live Telemetry Stream Logs Table */
.logs-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-card);
}

.logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.logs-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.logs-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logs-btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 13.5px;
  background: #FFFFFF;
  color: #0F172A;
  border: 1px solid #E2E8F0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.logs-btn-icon:hover {
  background: #0F172A;
  color: #FFFFFF;
  border-color: #0F172A;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
  transform: translateY(-1px);
}

.logs-btn-icon:active {
  transform: scale(0.96);
}

.logs-btn-icon.btn-refresh {
  background: #FFFFFF;
  color: #0F172A;
  border-color: #E2E8F0;
}

.logs-btn-icon.btn-refresh:hover {
  background: #0F172A;
  color: #FFFFFF;
  border-color: #0F172A;
}

.logs-btn-icon.btn-clear {
  background: #FFFFFF;
  color: #0F172A;
  border-color: #E2E8F0;
}

.logs-btn-icon i {
  display: inline-block;
  transform-origin: center center;
}

.logs-btn-icon .spin-icon {
  animation: iconSpin 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes iconSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.logs-btn-icon.btn-clear:hover {
  background: #0F172A;
  color: #FFFFFF;
  border-color: #0F172A;
}

.refresh-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: transform var(--transition-fast), color var(--transition-fast);
}

.refresh-btn:hover {
  color: var(--primary);
  transform: rotate(45deg);
}

.logs-table-container {
  max-height: 440px;
  overflow-y: auto;
  overflow-x: auto;
  border-radius: 8px;
  position: relative;
}

.logs-table-container::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.logs-table-container::-webkit-scrollbar-track {
  background: #F8FAFC;
  border-radius: 4px;
}

.logs-table-container::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}

.logs-table-container::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.logs-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-card, #FFFFFF);
  z-index: 5;
  box-shadow: 0 1px 0 var(--border-subtle, #E2E8F0);
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 12px 14px;
}

.logs-table td {
  padding: 14px 12px;
  color: var(--text-primary);
  font-weight: 600;
  vertical-align: middle;
  border-bottom: 1px solid #F8FAFC;
}

.logs-table tr:hover td {
  background-color: var(--bg-input);
}

.node-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #F8FAFC;
  color: #0F172A;
  border: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.node-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.node-loc {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.status-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
}

.status-pill.success {
  background-color: var(--success-light);
  color: var(--success);
}

.status-pill.danger {
  background-color: var(--danger-light);
  color: var(--danger);
}

.status-pill.warning {
  background-color: var(--warning-light);
  color: var(--warning);
}

.status-pill.info {
  background-color: var(--accent-purple-light);
  color: var(--accent-purple);
}

.price-power-cell {
  font-weight: 700;
  color: var(--text-primary);
}
