/* =========================================
   SolVerde PWA — Dark Solar Theme
   ========================================= */

:root {
  --bg-primary: #0a0e14;
  --bg-secondary: #111927;
  --bg-card: #172033;
  --bg-input: #1e293b;
  --border: #1e3a5f;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-green: #4ade80;
  --accent-yellow: #facc15;
  --accent-orange: #fb923c;
  --accent-red: #f87171;
  --accent-blue: #38bdf8;
  --accent-cyan: #22d3ee;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --radius: 12px;
  --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

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

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

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
}

.nav-list {
  list-style: none;
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  margin-bottom: 2px;
  transition: all 0.2s;
  font-size: 0.9rem;
}

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

.nav-link.active {
  background: rgba(74, 222, 128, 0.1);
  color: var(--accent-green);
}

.nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }

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

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.status-dot.offline { background: var(--text-muted); }

.btn-logout {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-logout:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* ---- Sidebar Overlay ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active {
  display: block;
}

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.topbar h1 {
  font-size: 1.2rem;
  font-weight: 600;
  flex: 1;
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  cursor: pointer;
}

.device-selector {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ---- Cards ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}

.card-unit {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-left: 4px;
}

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

/* ---- Gauge (SVG-based) ---- */
.gauge-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
}

.gauge-svg {
  width: 100%;
  max-width: 160px;
  height: auto;
}

.circle-svg {
  width: 100%;
  max-width: 120px;
  height: auto;
}

/* ---- Chart Container ---- */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.chart-area {
  width: 100%;
  min-height: 120px;
  height: 25vw;
  max-height: 200px;
  position: relative;
}

.chart-area canvas,
.chart-area .chart-svg {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ---- Bars (for garden moisture, energy) ---- */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.bar-track {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.bar-fill.green { background: var(--accent-green); }
.bar-fill.yellow { background: var(--accent-yellow); }
.bar-fill.orange { background: var(--accent-orange); }
.bar-fill.red { background: var(--accent-red); }
.bar-fill.blue { background: var(--accent-blue); }

/* ---- States ---- */
.state-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}

.state-bulk { background: rgba(250,204,21,0.15); color: var(--accent-yellow); }
.state-absorption { background: rgba(251,146,60,0.15); color: var(--accent-orange); }
.state-float { background: rgba(74,222,128,0.15); color: var(--accent-green); }
.state-off { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.state-error { background: rgba(248,113,113,0.15); color: var(--accent-red); }

/* ---- Online/Offline ---- */
.online-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
}

.online-badge.online { background: rgba(74,222,128,0.15); color: var(--accent-green); }
.online-badge.offline { background: rgba(100,116,139,0.15); color: var(--text-muted); }

/* ---- Table ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(30,58,95,0.3);
}

/* ---- Forms ---- */
.form-group {
  margin-bottom: 16px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent-green);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-green), #22c55e);
  color: #0a0e14;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-block { width: 100%; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--accent-green);
  color: var(--accent-green);
}

/* ---- Login ---- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-overlay.hidden { display: none; }
.hidden { display: none !important; }

.login-form {
  width: 100%;
  max-width: 360px;
  padding: 32px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h2 {
  margin-top: 12px;
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.error-msg {
  color: var(--accent-red);
  font-size: 0.85rem;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(248,113,113,0.1);
  border-radius: 6px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.6);
  }

  .sidebar-close {
    display: block;
  }

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

  .menu-btn {
    display: block;
  }

  .content {
    padding: 16px;
  }

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

@media (max-width: 480px) {
  .card-value {
    font-size: 1.5rem;
  }

  .topbar {
    padding: 12px 16px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .card {
    padding: 14px;
  }

  .chart-card {
    padding: 14px;
  }

  .gauge-container {
    padding: 4px 0;
  }

  .card-grid {
    gap: 10px;
    margin-bottom: 16px;
  }

  .content {
    padding: 10px;
  }

  .data-table td,
  .data-table th {
    padding: 8px 8px;
    font-size: 0.8rem;
  }
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.content > * {
  animation: fadeIn 0.3s ease-out;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
