/* Global Variables and Theming */
:root {
  --bg-color: #0d0f14;
  --panel-bg: rgba(22, 28, 41, 0.65);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --theme-accent: #3b82f6; /* Default Blue */
  --theme-accent-glow: rgba(59, 130, 246, 0.35);

  /* Battery status level colors */
  --energized: #10b981;
  --energized-glow: rgba(16, 185, 129, 0.25);
  --balanced: #3b82f6;
  --balanced-glow: rgba(59, 130, 246, 0.25);
  --drained: #f59e0b;
  --drained-glow: rgba(245, 158, 11, 0.25);
  --depleted: #ef4444;
  --depleted-glow: rgba(239, 68, 68, 0.25);

  --font-display: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
  --radius: 16px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-body);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding: 2rem 1.5rem;
}

/* Ambient backdrop blur circles */
.ambient-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  z-index: -1;
  opacity: 0.45;
  pointer-events: none;
}

.glow-1 {
  width: 400px;
  height: 400px;
  background: var(--theme-accent);
  top: -100px;
  right: -50px;
}

.glow-2 {
  width: 500px;
  height: 500px;
  background: #6366f1;
  bottom: -150px;
  left: -100px;
}

/* Layout Grid */
.dashboard-container {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.5rem;
  align-items: start;
}

/* Typography styling */
h1 {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #ffffff 30%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 1.25rem;
  color: #ffffff;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--theme-accent);
  margin-bottom: 0.25rem;
}

/* Cards (Glassmorphism design) */
.card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: var(--transition);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.4);
}

.glass {
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Headers */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--theme-accent);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 15px var(--theme-accent-glow);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px var(--theme-accent-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-accent {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.btn-accent:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.refresh-btn .icon {
  width: 16px;
  height: 16px;
  transition: var(--transition);
}

.refresh-btn:hover .icon {
  transform: rotate(180deg);
}

/* Grids */
.grid {
  display: grid;
  gap: 1.5rem;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.gap-small {
  gap: 0.75rem;
}

/* Main Dashboard Elements */
.main-content {
  display: grid;
  gap: 1.5rem;
}

/* Radial Gauge Styling */
.meter-card {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 1.5rem;
}

.meter-radial {
  position: relative;
  width: 160px;
  height: 160px;
}

.meter-radial svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.meter-radial circle {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
}

.meter-radial .meter-bg {
  stroke: rgba(255, 255, 255, 0.04);
}

.meter-radial .meter-fg {
  stroke: var(--theme-accent);
  stroke-dasharray: 251.2; /* 2 * pi * r = 2 * 3.14159 * 40 */
  stroke-dashoffset: 251.2;
  transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1), stroke var(--transition);
  filter: drop-shadow(0 0 8px var(--theme-accent-glow));
}

.meter-text-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.meter-percentage {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1;
}

.meter-status {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.reason-box {
  flex: 1;
}

.reason-box .label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  letter-spacing: 0.05em;
}

.reason-text {
  font-size: 1.05rem;
  font-weight: 500;
  color: #ffffff;
  line-height: 1.4;
}

/* Stats balance grid breakdown */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.stat-pill {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.15rem;
  letter-spacing: 0.02em;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: #ffffff;
}

/* History Chart Styling */
.timeline-card {
  padding: 1.5rem;
}

.chart-container {
  display: flex;
  flex-direction: column;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  position: relative;
}

.chart-tooltip {
  position: absolute;
  top: -40px;
  right: 0;
  background: #1f2937;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #ffffff;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: opacity 0.15s ease;
  z-index: 10;
}

.chart-tooltip.hidden {
  opacity: 0;
}

.chart-wrapper {
  position: relative;
  height: 180px;
  width: 100%;
}

.chart-wrapper svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-line {
  fill: none;
  stroke: url(#chart-line-grad);
  stroke-width: 3.5;
  stroke-linecap: round;
  filter: drop-shadow(0 4px 10px var(--theme-accent-glow));
}

.chart-area {
  fill: url(#chart-fill-grad);
}

.gridlines line {
  stroke: rgba(255, 255, 255, 0.04);
  stroke-width: 1;
}

.hover-line {
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.hover-point {
  fill: var(--theme-accent);
  stroke: #ffffff;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px var(--theme-accent-glow));
}

.chart-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  z-index: 5;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 0.25rem;
}

/* Recent Events Log */
.events-log-container {
  max-height: 280px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

/* Custom Scrollbar for Events */
.events-log-container::-webkit-scrollbar {
  width: 6px;
}
.events-log-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
}
.events-log-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
.events-log-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.events-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.event-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  transition: var(--transition);
}

.event-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.06);
}

.event-item.empty-state {
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1.5rem;
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.08);
  background: transparent;
}

.event-details {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.event-badge {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: rgba(255, 255, 255, 0.04);
}

.event-text-meta {
  display: flex;
  flex-direction: column;
}

.event-reason-display {
  font-size: 0.9rem;
  font-weight: 500;
  color: #ffffff;
}

.event-timestamp-display {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.event-action-block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.event-value {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
}

.event-value.val-positive {
  color: var(--energized);
}

.event-value.val-negative {
  color: var(--depleted);
}

.event-value.val-excluded {
  color: var(--text-muted);
  text-decoration: line-through;
}

.event-item.event-excluded {
  opacity: 0.45;
}

.event-item.event-excluded .event-reason-display {
  text-decoration: line-through;
}

.excluded-badge {
  font-size: 0.68rem;
  color: #6b7280;
  font-style: italic;
}

.btn-exclude-event {
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.3rem;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1;
  transition: var(--transition);
}

.btn-exclude-event:hover {
  color: var(--depleted);
  background: rgba(239, 68, 68, 0.08);
}

.btn-exclude-event.btn-restore {
  color: var(--energized);
}

.btn-exclude-event.btn-restore:hover {
  background: rgba(16, 185, 129, 0.08);
}

.btn-delete-event {
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-delete-event:hover {
  color: var(--depleted);
  background: rgba(239, 68, 68, 0.08);
}

.btn-delete-event svg {
  width: 15px;
  height: 15px;
}

/* Sidebar styling */
.sidebar-controls {
  display: grid;
  gap: 1.5rem;
}

.panel-card {
  padding: 1.25rem;
}

/* Form Styles */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.label-text {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

input[type="number"],
input[type="text"] {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: #ffffff;
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: var(--transition);
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--theme-accent);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.15);
}

/* Event Types Segmented Radio Controls */
.event-types-segmented {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.2rem;
  gap: 0.2rem;
}

.event-types-segmented input[type="radio"] {
  display: none;
}

.event-types-segmented label {
  flex: 1;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.45rem 0.25rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
  white-space: nowrap;
}

.event-types-segmented input[type="radio"]:checked + label {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.event-types-segmented label:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
}

/* Presets Grid */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.preset-btn {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.45rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: var(--transition);
}

.preset-btn.val-drain {
  background: rgba(239, 68, 68, 0.05);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.1);
}

.preset-btn.val-drain:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.25);
  color: #ffffff;
}

.preset-btn.val-recharge {
  background: rgba(16, 185, 129, 0.05);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.1);
}

.preset-btn.val-recharge:hover {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.25);
  color: #ffffff;
}

/* Calendar Sync Status Box */
.sync-status-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
}

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

.status-indicator.sync-active {
  background: var(--balanced);
  animation: pulse 1.5s infinite;
}

.status-indicator.sync-success {
  background: var(--energized);
}

.status-indicator.sync-error {
  background: var(--depleted);
}

.sync-status-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Collapsible Settings Panel styling */
.collapsible-card {
  padding: 0;
  overflow: hidden;
}

.card-header-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem;
  cursor: pointer;
  user-select: none;
}

.card-header-toggle h2 {
  margin-bottom: 0;
}

.chevron-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transition: transform 0.3s ease;
}

.card-content-collapsible {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 1.25rem;
}

.collapsible-card.expanded .chevron-icon {
  transform: rotate(180deg);
}

.collapsible-card.expanded .card-content-collapsible {
  max-height: 380px;
  padding-bottom: 1.25rem;
}

/* Location GPS Status styles */
.location-status-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
}

.location-status-container.hidden {
  display: none;
}

.location-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--theme-accent);
  animation: pulse 1.5s infinite;
  display: inline-block;
}

.location-status-text {
  color: var(--text-muted);
  font-weight: 500;
}

/* Animations */
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.25); opacity: 1; box-shadow: 0 0 8px currentColor; }
  100% { transform: scale(1); opacity: 0.8; }
}

/* Responsive Media Queries */
@media (max-width: 900px) {
  .dashboard-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  body {
    padding: 1.5rem 1rem;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .meter-card {
    flex-direction: column;
    text-align: center;
    padding: 1.75rem;
  }
  .reason-box {
    margin-top: 0.5rem;
  }
  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .refresh-btn {
    width: 100%;
  }
}
