:root {
  --primary-color: #f59e0b;
  --primary-hover: #d97706;
  --secondary-color: #3b82f6;
  --secondary-hover: #2563eb;
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  /* Display serif for headings (matches the hero), readable serif for body */
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Lora", Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-optical-sizing: auto;
  font-weight: normal;
  font-style: normal;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.04em;
}

h3 {
  font-size: 1.35rem;
  line-height: 1.25;
}

/* Small uppercase labels get the spaced-caps look from the header */
h4, label {
  letter-spacing: 0.08em;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  padding-bottom: 40px;
}

/* Slim dark top bar, pinned while the page scrolls */
.navbar {
  --nav-text: #e2e8f0;
  --nav-muted: #94a3b8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 2rem;
  background-color: #111318;
  color: var(--nav-text);
  border-bottom: 1px solid #000;
  position: sticky;
  top: 0;
  z-index: 50;
}

.navbar .logo h2 {
  font-size: 1.3rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
}

.navbar .badge {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--nav-text);
}

.navbar .nav-btn { color: var(--nav-muted); }
/* Hover and the current page both use the accent color (Settings > Accent),
   with a light tint of it behind */
.navbar .nav-btn:hover,
.navbar .nav-btn.active {
  color: var(--primary-color);
  background-color: rgba(245, 158, 11, 0.15); /* fallback for older browsers */
  background-color: color-mix(in srgb, var(--primary-color) 15%, transparent);
}
.navbar .nav-btn.active:hover {
  background-color: color-mix(in srgb, var(--primary-color) 25%, transparent);
}

html { scroll-behavior: smooth; }
#dashboard { scroll-margin-top: 64px; }

/* Hero banner: eclipse photo as the background, text centered on top */
.hero {
  /* Fixed light-on-black colors, so it looks the same in light and dark mode */
  --hero-text: #f1f5f9;
  --hero-muted: #a3acb9;
  background-color: #000;
  /* Even dark tint over the photo keeps the centered text readable */
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.55)),
    var(--hero-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: var(--hero-text);
  padding: 6rem 2rem;
}

.hero-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  text-align: center;
}

.hero-text {
  max-width: 560px;
}

.hero-text p { margin-left: auto; margin-right: auto; }

.hero-text h1 {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.25;
  margin-bottom: 1rem;
}

.hero-text p {
  color: var(--hero-muted);
  line-height: 1.7;
  max-width: 46ch;
  margin-bottom: 1.5rem;
}

.hero-btn {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  border: 1px solid var(--hero-text);
  border-radius: 999px;
  color: var(--hero-text);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-decoration: none;
  transition: background-color 0.2s, color 0.2s;
}

.hero-btn:hover {
  background-color: var(--hero-text);
  color: #000;
}

@media (max-width: 760px) {
  .hero { padding: 4rem 16px; }
  .hero-text h1 { font-size: 1.5rem; }
}

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

/* Logo is a link home: keep the plain heading look, no link color/underline */
a.logo {
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 50%;
  background-color: #111;
}

.logo h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.tag {
  background-color: #fef3c7;
  color: #b45309;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  font-weight: 700;
}

.badge {
  background-color: #e2e8f0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  max-width: 1440px;
  margin: 0 auto;
}

.sidebar, .content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Left column scrolls with the page until its last item is visible, then
   stops while the graphs keep scrolling. --sidebar-top is set by
   sticky-sidebar.js: the header height when the sidebar fits on screen,
   or a negative offset so it sticks by its bottom edge when it is taller. */
.sidebar {
  position: sticky;
  top: var(--sidebar-top, 88px);
  align-self: start;
}

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
}

.card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

input[type="text"], input[type="number"], input[type="email"], input[type="password"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--secondary-color);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary-color);
}

.input-row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover {
  background-color: var(--primary-hover); /* fallback for older browsers */
  /* A slightly darker shade of whatever accent color is chosen */
  background-color: color-mix(in srgb, var(--primary-color) 85%, black);
}
.btn-secondary { background-color: #f1f5f9; color: var(--text-main); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: #e2e8f0; }
.btn-sm { width: auto; padding: 6px 12px; font-size: 0.85rem; }
/* Text follows the theme like the rest of the page (dark in light mode,
   off-white in dark mode) instead of the browser's default black */
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-link { background: none; border: none; color: var(--secondary-color); cursor: pointer; font-size: 0.85rem; }

/* Device List in Sidebar */
.device-list {
  list-style: none;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}

.device-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background-color: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.device-actions-icons {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 4px;
}

.icon-btn.delete { color: var(--danger); }
.icon-btn.edit { color: var(--secondary-color); }

/* KPI Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

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

.stat-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.stat-card h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-card.highlight {
  background: #ecfdf5;
  border-color: #a7f3d0;
}
.stat-card.highlight .stat-value { color: var(--success); }

/* Chart */
.chart-card { min-height: 420px; } /* grows when the "estimate" note shows */
.chart-wrapper { position: relative; height: 330px; width: 100%; }

/* Hover tooltips on the chart: one box per series (see splitTooltip in script.js) */
.chart-tip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  padding: 8px 12px;
  border-radius: 10px;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: opacity 0.15s;
  z-index: 2;
}
.chart-tip-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }

/* Table & Sorting */
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.table-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-top: 3px;
}

.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

th, td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

th {
  background-color: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s;
}

th.sortable:hover {
  background-color: #edf2f7;
  color: var(--text-main);
}

.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.75rem;
  color: var(--secondary-color);
}

/* In-Table Device Action Pills & Controls */
.table-actions-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.action-pill {
  display: inline-flex;
  align-items: center;
  background-color: #fef3c7;
  color: #92400e;
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #fde68a;
}

.action-pill .remove-action {
  margin-left: 6px;
  color: #b45309;
  cursor: pointer;
  font-weight: bold;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-pill .remove-action:hover {
  background-color: #b45309;
  color: #ffffff;
}

.inline-add-device {
  padding: 3px 8px;
  font-size: 0.78rem;
  border-radius: 6px;
  border: 1px dashed var(--border-color);
  background-color: transparent;
  cursor: pointer;
  color: var(--text-muted);
}

.inline-add-device:hover {
  border-color: var(--secondary-color);
  color: var(--secondary-color);
}

/* The list that opens from "+ Add". appearance: base-select lets browsers that
   support customizable selects (Chrome/Edge 135+) style it like a menu; other
   browsers ignore it and keep their native list. */
.inline-add-device,
.inline-add-device::picker(select) {
  appearance: base-select;
}

.inline-add-device::picker(select) {
  margin-top: 4px;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background-color: var(--surface-color);
  color: var(--text-main);
  font-family: inherit;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
}

.inline-add-device option {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
}

.inline-add-device option:hover,
.inline-add-device option:focus-visible {
  background-color: rgba(59, 130, 246, 0.12);
  color: var(--secondary-color);
  outline: none;
}

/* No checkmark next to the selected item: picking one adds it right away */
.inline-add-device option::checkmark { display: none; }

/* ==========================================================================
   DYNAMIC FONT SIZES
   ========================================================================== */
html[data-font-size="small"] { font-size: 14px; }
html[data-font-size="medium"] { font-size: 16px; }
html[data-font-size="large"] { font-size: 18px; }
html[data-font-size="xlarge"] { font-size: 20px; }

/* ==========================================================================
   DARK THEME VARIABLES
   ========================================================================== */
[data-theme="dark"] {
  --bg-color: #121212;            /* Near-black gray */
  --surface-color: #1e1e1e;       /* Card dark gray */
  --border-color: #2f2f2f;
  --text-main: #f1f5f9;           /* Clean Off-white */
  --text-muted: #a3a3a3;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] input, 
[data-theme="dark"] select {
  background-color: #171717;
  color: #f1f5f9;
  border-color: var(--border-color);
}

[data-theme="dark"] .stat-card.highlight {
  background: #064e3b;
  border-color: #059669;
}

[data-theme="dark"] .stat-card.highlight .stat-value {
  color: #34d399;
}

[data-theme="dark"] .device-item {
  background-color: #171717;
}
/* Light-gray secondary buttons (e.g. "+ Add Appliance") need a dark fill,
   since their text turns off-white in dark mode */
[data-theme="dark"] .btn-secondary {
  background-color: #2a2a2a;
  border-color: #3f3f3f;
  color: var(--text-main);
}

[data-theme="dark"] .btn-secondary:hover {
  background-color: #363636;
}

[data-theme="dark"] th {
  background-color: #191919;
  color: var(--text-muted);
}

[data-theme="dark"] th.sortable:hover {
  background-color: #2a2a2a;
  color: var(--text-main);
}

/* ==========================================================================
   NAVBAR LINKS & SETTINGS PAGE
   ========================================================================== */
.nav-links {
  display: flex;
  gap: 8px;
}

.nav-btn {
  text-decoration: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
}

.nav-btn-action {
  border: 0;
  background: none;
  cursor: pointer;
}

.nav-btn:hover {
  color: var(--text-main);
  background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .nav-btn:hover,
[data-theme="dark"] .nav-btn.active {
  color: var(--primary-color);
  background-color: rgba(245, 158, 11, 0.15); /* fallback for older browsers */
  background-color: color-mix(in srgb, var(--primary-color) 15%, transparent);
}

.nav-btn.active {
  color: var(--primary-color);
  background-color: #fef3c7; /* fallback for older browsers */
  background-color: color-mix(in srgb, var(--primary-color) 15%, transparent);
}

[data-theme="dark"] .nav-btn.active:hover {
  background-color: color-mix(in srgb, var(--primary-color) 25%, transparent);
}

/* Settings Container */
.settings-container {
  max-width: 850px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.settings-header h2 {
  font-size: 1.6rem;
  margin-bottom: 0.3rem;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.setting-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Theme Radio Tile Options */
.theme-picker {
  display: flex;
  gap: 8px;
}

.theme-option {
  cursor: pointer;
}

.theme-option input {
  display: none;
}

.theme-option span {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.theme-option input:checked + span {
  border-color: var(--primary-color);
  background-color: var(--primary-color);
  color: white;
}

/* Color Dot Picker */
.color-picker-row {
  display: flex;
  gap: 10px;
}

.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--surface-color);
  outline: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.15s;
}

.color-dot:hover {
  transform: scale(1.15);
}

/* Font Size Buttons & Select */
.font-size-buttons {
  display: flex;
  gap: 6px;
}

.select-inline {
  width: auto;
  min-width: 170px;
}

.settings-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}

.save-status {
  font-size: 0.9rem;
  color: var(--success);
  font-weight: 600;
  opacity: 0.4;
  transition: opacity 0.3s;
}

/* ==========================================================================
   FLOATING CHATBOT WIDGET (BOTTOM-RIGHT CORNER)
   ========================================================================== */
#chat-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* Floating Action Button (FAB) */
.chat-fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  transition: transform 0.2s, background-color 0.2s;
}

.chat-fab:hover {
  transform: scale(1.08);
}

.chat-fab .chat-close-icon {
  display: none;
  font-size: 2rem;
  line-height: 1;
}

.chat-fab .chat-icon { font-size: 0.95rem; font-weight: 600; }
#chat-container.open .chat-fab .chat-icon { display: none; }
#chat-container.open .chat-fab .chat-close-icon { display: block; }

/* Chat Window Box */
.chat-window {
  display: none;
  width: 360px;
  height: 480px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 12px;
  animation: slideUp 0.25s ease-out forwards;
}

#chat-container.open .chat-window {
  display: flex;
}

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

/* Chat Header */
.chat-header {
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  background-color: var(--success);
  border-radius: 50%;
}

.chat-header strong {
  display: block;
  font-size: 0.95rem;
}

.chat-header small {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.chat-min-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* Message Scroll Area */
.chat-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.88rem;
  background: var(--bg-color);
}

.message {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.4;
  word-wrap: break-word;
}

.bot-msg {
  background: var(--surface-color);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.user-msg {
  background: var(--primary-color);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.bot-msg.warning {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}

[data-theme="dark"] .bot-msg.warning {
  background: #450a0a;
  color: #fca5a5;
}

/* Input Bar */
.chat-input-bar {
  display: flex;
  padding: 10px;
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
  gap: 8px;
}

.chat-input-bar input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
  outline: none;
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}
/* Settings: dashboard graph color pickers */
.graph-color-pickers {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.graph-color-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.graph-color-option input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.graph-color-option input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.graph-color-option input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
.graph-color-option input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }
