/* ===================================================
   Dropbox Green Energy Solutions — EMS Cloud Dashboard
   Brand-aligned dark theme — green energy palette
   =================================================== */

/* --- Theme Variables --- */
:root {
  --bg-void: #050709;
  --bg-primary: #080b10;
  --bg-elevated: #0e1318;
  --bg-card: rgba(12, 16, 22, 0.65);
  --bg-card-hover: rgba(16, 22, 30, 0.75);

  /* Brand greens */
  --brand-green: #0c9447;
  --accent-green: #10b461;
  --accent-green-bright: #00e06a;

  /* Functional colours */
  --accent-charge: #10b461;
  --accent-discharge: #ff4466;
  --accent-battery: #ffaa22;
  --accent-fault: #ff2244;
  --accent-success: #10b461;

  /* Brand neutrals */
  --brand-charcoal: #38383B;
  --brand-grey: #A8A6A1;
  --brand-light: #F7F7F7;

  --text-bright: #eff2f5;
  --text-primary: #b8c4d0;
  --text-secondary: #5f7282;
  --text-dim: #2d3a48;

  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-light: rgba(255, 255, 255, 0.07);
  --border-accent: rgba(16, 180, 97, 0.2);

  --font-body: 'Roboto', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
}

/* --- Base & Background --- */
body {
  background: var(--bg-void);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.015) 1px, transparent 0);
  background-size: 28px 28px;
  font-family: var(--font-body);
  min-height: 100vh;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* --- Noise Grain Overlay --- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.015;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(16, 180, 97, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(16, 180, 97, 0.3); }

/* --- Header --- */
.ems-header {
  background: rgba(8, 11, 16, 0.88);
  backdrop-filter: blur(20px) saturate(1.2);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 50;
}

.ems-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brand-green), transparent);
  opacity: 0.4;
}

/* --- Navigation --- */
.ems-nav {
  background: rgba(8, 12, 18, 0.7);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}

.ems-nav-tab {
  position: relative;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 8px;
  transition: all 0.25s ease;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.ems-nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.ems-nav-tab.active {
  color: var(--accent-green);
  background: rgba(16, 180, 97, 0.08);
}

.ems-nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent-green);
  border-radius: 1px;
  box-shadow: 0 0 8px var(--accent-green);
}

/* --- Cards --- */
.ems-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.ems-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.ems-metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 20px 24px;
  backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.ems-metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ems-metric-card:hover::before { opacity: 1; }
.ems-metric-card:hover { border-color: rgba(255, 255, 255, 0.1); }

.ems-metric-card.status::before { background: linear-gradient(90deg, transparent, var(--accent-green), transparent); }
.ems-metric-card.soc::before { background: linear-gradient(90deg, transparent, var(--brand-green), transparent); }
.ems-metric-card.ess::before { background: linear-gradient(90deg, transparent, var(--accent-charge), transparent); }
.ems-metric-card.grid::before { background: linear-gradient(90deg, transparent, var(--accent-battery), transparent); }

.ems-metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.ems-metric-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}

.ems-metric-unit {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* --- SOC Gauge --- */
.soc-gauge-ring {
  transition: stroke-dasharray 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Power Flow --- */
.power-flow-container {
  position: relative;
}

.flow-path-bg {
  stroke: rgba(255, 255, 255, 0.04);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.flow-path-active {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 6 14;
}

.flow-forward {
  animation: flowForward 1.2s linear infinite;
}

.flow-reverse {
  animation: flowReverse 1.2s linear infinite;
}

.flow-idle {
  stroke-dasharray: 2 18;
  opacity: 0.3;
}

@keyframes flowForward {
  from { stroke-dashoffset: 40; }
  to { stroke-dashoffset: 0; }
}

@keyframes flowReverse {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: 40; }
}

.flow-node {
  transition: all 0.3s ease;
}

.flow-node-glow {
  animation: nodeGlow 3s ease-in-out infinite;
}

@keyframes nodeGlow {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.3; }
}

/* --- Live Badge --- */
.ems-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-green-bright);
  background: rgba(16, 180, 97, 0.08);
  border: 1px solid rgba(16, 180, 97, 0.2);
  border-radius: 20px;
}

.ems-live-dot {
  width: 6px;
  height: 6px;
  background: var(--accent-green-bright);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-green-bright);
  animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--accent-green-bright); }
  50% { opacity: 0.5; box-shadow: 0 0 12px var(--accent-green-bright), 0 0 24px rgba(0, 224, 106, 0.3); }
}

/* --- Connection Dot --- */
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.conn-dot.connected {
  background: var(--accent-green-bright);
  box-shadow: 0 0 8px rgba(0, 224, 106, 0.4);
}

.conn-dot.error {
  background: var(--accent-fault);
  box-shadow: 0 0 8px rgba(255, 34, 68, 0.4);
}

.conn-dot.idle {
  background: var(--text-dim);
}

/* --- Entrance Animations --- */
.ems-fade-in {
  animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.ems-stagger-1 { animation-delay: 0.05s; }
.ems-stagger-2 { animation-delay: 0.10s; }
.ems-stagger-3 { animation-delay: 0.15s; }
.ems-stagger-4 { animation-delay: 0.20s; }
.ems-stagger-5 { animation-delay: 0.25s; }
.ems-stagger-6 { animation-delay: 0.30s; }

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Alarm Item --- */
.ems-alarm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 34, 68, 0.06);
  border: 1px solid rgba(255, 34, 68, 0.12);
  border-radius: 10px;
  margin-bottom: 6px;
}

.ems-alarm-dot {
  width: 6px;
  height: 6px;
  background: var(--accent-fault);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-fault);
  animation: alarmPulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes alarmPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- Charts --- */
.ems-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 18px;
  backdrop-filter: blur(8px);
}

.ems-chart-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* --- Time Range Buttons --- */
.ems-range-btn {
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.ems-range-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-light);
}

.ems-range-btn.active {
  color: var(--accent-green);
  background: rgba(16, 180, 97, 0.08);
  border-color: rgba(16, 180, 97, 0.25);
  box-shadow: 0 0 12px rgba(16, 180, 97, 0.1);
}

/* --- Login Page --- */
.login-backdrop {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 30% 30%, rgba(12, 148, 71, 0.04) 0%, transparent 50%),
    var(--bg-void);
  position: relative;
  overflow: hidden;
}

.login-backdrop::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: gridSlide 20s linear infinite;
}

@keyframes gridSlide {
  from { transform: translate(0, 0); }
  to { transform: translate(60px, 60px); }
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  backdrop-filter: blur(24px);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  position: relative;
  animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-card::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--brand-green), transparent);
  opacity: 0.5;
  border-radius: 1px;
}

/* --- Section Divider --- */
.ems-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

/* --- Device Summary --- */
.ems-device-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
}

.ems-device-item label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.ems-device-item span {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* --- Company Switcher --- */
.ems-company-btn {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.ems-company-btn.active {
  background: rgba(16, 180, 97, 0.1);
  color: var(--accent-green);
  border-color: rgba(16, 180, 97, 0.2);
}

.ems-company-btn:not(.active) {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
}

.ems-company-btn:not(.active):hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

/* --- Disconnected State --- */
.ems-disconnected {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.ems-disconnected-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

/* --- Banner --- */
.ems-live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: rgba(16, 180, 97, 0.04);
  border: 1px solid rgba(16, 180, 97, 0.1);
  border-radius: 12px;
  margin-bottom: 24px;
}

/* --- Role Badge --- */
.ems-role-badge {
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 12px;
}

.ems-role-badge.super {
  background: rgba(16, 180, 97, 0.1);
  color: var(--accent-green);
  border: 1px solid rgba(16, 180, 97, 0.2);
}

.ems-role-badge.normal {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* --- Range Input --- */
input[type="range"] {
  -webkit-appearance: none;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-green);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(16, 180, 97, 0.3);
}

/* --- Time Input --- */
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(0.6);
}

/* --- Sign Out Button --- */
.ems-sign-out {
  font-size: 12px;
  color: var(--text-secondary);
  transition: color 0.2s ease;
  padding: 4px 8px;
}

.ems-sign-out:hover {
  color: var(--text-bright);
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .ems-metric-value { font-size: 22px; }
  .login-card { margin: 16px; padding: 28px 24px; }
}
