/* ========================================
   Solar Assistant Dashboard - Styles
   ======================================== */

:root {
  /* Colors - Dark Theme */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-blue: #3b82f6;
  --accent-green: #22c55e;
  --accent-yellow: #fbbf24;
  --accent-orange: #f97316;
  --accent-red: #ef4444;
  --accent-purple: #a855f7;

  --border-color: #334155;

  /* Sizing */
  --sidebar-width: 240px;
  --header-height: 64px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
}

/* ========================================
   Base Styles
   ======================================== */

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  transition: opacity 0.2s;
}

.logo:hover {
  opacity: 0.8;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-yellow) 0%, var(--accent-orange) 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #000;
}

.logo-text {
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}

.nav-menu {
  list-style: none;
  padding: 16px 12px;
  flex: 1;
}

.nav-item {
  margin-bottom: 4px;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--border-radius-sm);
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
}

.nav-item a:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active a {
  background: var(--accent-blue);
  color: white;
}

.nav-item .material-icons {
  font-size: 20px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

.device-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

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

.status-dot.online {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

/* ========================================
   Main Content
   ======================================== */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* ========================================
   Header
   ======================================== */

.header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
}

/* Breadcrumbs */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.breadcrumb-link {
  color: var(--accent-blue);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.breadcrumb-link:hover {
  color: #60a5fa;
  text-decoration: underline;
}

.breadcrumb-separator {
  color: var(--text-muted);
  font-weight: 400;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.last-update {
  font-size: 13px;
  color: var(--text-muted);
}

.header-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--border-radius-sm);
  transition: all 0.2s;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ========================================
   Dashboard Grid
   ======================================== */

.dashboard-grid {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* ========================================
   Cards
   ======================================== */

.card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
}

.badge.charging {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
}

.badge.discharging {
  background: rgba(249, 115, 22, 0.15);
  color: var(--accent-orange);
}

.badge.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
}

.badge.neutral {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
}

.badge.warning {
  background: rgba(251, 191, 36, 0.15);
  color: var(--accent-yellow);
}

/* ========================================
   Power Flow Card - Cross Layout
   ======================================== */

.power-flow-card {
  grid-column: span 2;
  grid-row: span 2;
}

.power-flow.cross-layout {
  padding: 20px;
  height: 100%;
  min-height: 350px;
}

.pf-cross-grid {
  display: grid;
  grid-template-columns: 1fr 50px 1fr 50px 1fr;
  grid-template-rows: auto 40px auto 40px auto;
  gap: 0;
  height: 100%;
  align-items: center;
  justify-items: center;
}

.pf-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.pf-node {
  text-align: center;
}

/* Horizontal flow lines */
.pf-line-h {
  width: 100%;
}

.flow-line-h {
  width: 100%;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
}

.flow-line-h.active {
  background: var(--accent-purple);
  box-shadow: 0 0 8px var(--accent-purple);
}

.flow-line-h.load-flow.active {
  background: var(--accent-purple);
  box-shadow: 0 0 8px var(--accent-purple);
}

.flow-line-h.grid-flow.active {
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
}

/* Vertical flow lines */
.pf-line-v {
  height: 100%;
}

.flow-line-v {
  width: 4px;
  height: 100%;
  background: var(--border-color);
  border-radius: 2px;
}

.flow-line-v.active {
  box-shadow: 0 0 8px currentColor;
}

.flow-line-v.solar-flow.active {
  background: var(--accent-yellow);
  box-shadow: 0 0 8px var(--accent-yellow);
}

.flow-line-v.battery-flow.charging {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.pf-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
  border: 2px solid;
}

.pf-icon .material-icons {
  font-size: 28px;
}

.pf-icon.solar {
  background: rgba(251, 191, 36, 0.15);
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
}

.pf-icon.grid {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.pf-icon.inverter {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  width: 72px;
  height: 72px;
}

.pf-icon.battery {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.pf-icon.battery.charging {
  animation: pulse-green 2s ease-in-out infinite;
}

.pf-icon.load {
  background: rgba(168, 85, 247, 0.15);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
}

.pf-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.pf-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Animated flow lines */
.flow-line-h.active,
.flow-line-v.active,
.flow-line-h.charging,
.flow-line-v.charging {
  position: relative;
  overflow: hidden;
}

.flow-line-h.active::after,
.flow-line-v.active::after,
.flow-line-h.charging::after,
.flow-line-v.charging::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.5);
  animation: flow-pulse 1.5s ease-in-out infinite;
}

.flow-line-h.active::after,
.flow-line-h.charging::after {
  width: 20px;
  height: 100%;
  top: 0;
  left: -20px;
  animation: flow-pulse-h 1.5s ease-in-out infinite;
}

.flow-line-v.active::after,
.flow-line-v.charging::after {
  width: 100%;
  height: 20px;
  left: 0;
  top: -20px;
  animation: flow-pulse-v 1.5s ease-in-out infinite;
}

@keyframes flow-pulse-h {
  0% { left: -20px; opacity: 0; }
  50% { opacity: 1; }
  100% { left: 100%; opacity: 0; }
}

@keyframes flow-pulse-v {
  0% { top: -20px; opacity: 0; }
  50% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

/* ========================================
   Battery Card
   ======================================== */

.battery-visual {
  display: flex;
  gap: 24px;
  padding: 20px;
}

.battery-container {
  width: 80px;
  height: 160px;
  background: var(--bg-primary);
  border: 3px solid var(--border-color);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.battery-container::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px 4px 0 0;
}

.battery-level {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, var(--accent-green), #4ade80);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: height 0.5s ease;
}

.battery-percent {
  font-size: 18px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.battery-stats {
  flex: 1;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-value.positive {
  color: var(--accent-green);
}

.stat-value.negative {
  color: var(--accent-orange);
}

/* ========================================
   Solar Card
   ======================================== */

.solar-stats {
  padding: 20px;
}

.solar-main {
  text-align: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.solar-icon {
  font-size: 48px;
  color: var(--accent-yellow);
  margin-bottom: 8px;
}

.solar-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-yellow);
}

.solar-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.solar-details {
  margin-bottom: 16px;
}

.mini-chart {
  padding: 0 20px 20px;
}

.mini-chart svg {
  width: 100%;
  height: 80px;
}

/* ========================================
   Grid Card
   ======================================== */

.grid-stats {
  padding: 20px;
}

.grid-main {
  text-align: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.grid-icon {
  font-size: 48px;
  color: var(--accent-red);
  margin-bottom: 8px;
}

.grid-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
}

.grid-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========================================
   Load Card
   ======================================== */

.load-stats {
  padding: 20px;
}

.load-main {
  text-align: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.load-icon {
  font-size: 48px;
  color: var(--accent-purple);
  margin-bottom: 8px;
}

.load-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-purple);
}

.load-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========================================
   Inverter Card
   ======================================== */

.inverter-stats {
  padding: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stat-item {
  text-align: center;
  padding: 16px;
  background: var(--bg-primary);
  border-radius: var(--border-radius-sm);
}

.stat-item .stat-label {
  display: block;
  margin-bottom: 8px;
}

.stat-item .stat-value {
  font-size: 18px;
}

/* ========================================
   Actions Card
   ======================================== */

.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 20px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 12px;
  font-weight: 500;
}

.action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.action-btn.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.action-btn.warning {
  background: rgba(251, 191, 36, 0.15);
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
}

.action-btn.danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.action-btn .material-icons {
  font-size: 24px;
}

/* ========================================
   Environment Card
   ======================================== */

.env-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 20px;
}

.env-item {
  text-align: center;
  padding: 16px;
  background: var(--bg-primary);
  border-radius: var(--border-radius-sm);
}

.env-item .material-icons {
  font-size: 32px;
  color: var(--accent-blue);
  margin-bottom: 8px;
}

.env-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.env-value.good {
  color: var(--accent-green);
}

.env-value.warning {
  color: var(--accent-yellow);
}

.env-value.danger {
  color: var(--accent-red);
}

.env-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ========================================
   Responsive Design
   ======================================== */

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

  .power-flow-card {
    grid-column: span 2;
  }
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 16px;
  }

  .power-flow-card {
    grid-column: span 1;
    grid-row: span 1;
  }

  .power-flow {
    height: 280px;
  }

  .pf-solar { left: 20px; }
  .pf-grid { right: 20px; }
  .pf-battery { left: 20px; }
  .pf-load { right: 20px; }

  .env-grid {
    grid-template-columns: 1fr;
  }

  .battery-visual {
    flex-direction: column;
    align-items: center;
  }
}
