/* ---------------------------------------------------
   1. BASE STYLES & VARIABLES
--------------------------------------------------- */
:root {
  --primary-color: #007bff;
  --primary-color-hover: #0056b3;
  --text-color-light: #fff;
  --text-color-dark: #333;
  --border-color: #e0e0e0;
  --background-color-chat: #f9f9f9;
  --bot-message-bg: #e9e9eb;
  --nav-width-desktop: 220px;
  --mobile-header-height: 60px;
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background: var(--text-color-light);
  color: var(--text-color-dark);
}

.main-wrapper { display: flex; flex-direction: row; }
.container { max-width: 800px; flex-grow: 1; padding: 1em 2em; }
section { border-bottom: 1px solid var(--border-color); padding: 1.5rem 0; scroll-margin-top: 70px; }
section:last-of-type { border-bottom: none; }
h1 { border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; }
h2 { margin-top: 0; }
a, a:visited { color: #0000EE; text-decoration: underline; }
a:hover { color: #551A8B; }
.video-container { position: relative; overflow: hidden; width: 100%; padding-top: 56.25%; margin: 1rem 0; border-radius: 8px; }
.video-container iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; }

/* ---------------------------------------------------
   2. SITE HEADER & NAVIGATION (Desktop)
--------------------------------------------------- */
.site-header { display: flex; justify-content: center; padding: .5em; border-bottom: 1px solid var(--border-color); }
.logo { height: 40px; width: auto; }
#table-of-contents { width: var(--nav-width-desktop); position: sticky; top: 0; height: 100vh; background: #f8f9fa; border-right: 1px solid var(--border-color); padding: 1rem; overflow-y: auto; flex-shrink: 0; }
#table-of-contents ul { list-style: none; padding: 0; margin: 0; }
#table-of-contents li a { display: block; padding: 0.5rem; text-decoration: none; color: var(--text-color-dark); border-radius: 4px; }
#table-of-contents li a:hover { background-color: #e9ecef; }

/* Sidebar group title (non-clickable divider) */
.toc-group-title {
  font-weight: bold;
  font-size: 0.85rem;
  color: #6c757d;
  padding: 0.75rem 0.5rem 0.25rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-color);
  letter-spacing: 0.02em;
}

/* **FIX: Styles for new desktop logos** */
.desktop-logo-container {
  display: none; /* Hide on mobile by default */
}

.main-content-logo {
  padding-bottom: 1rem;
  text-align: center;
}
.main-content-logo .logo {
  height: 50px;
}

/* ---------------------------------------------------
   3. INLINE AI CHAT CARD
--------------------------------------------------- */
.ai-chat-card {
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.ai-chat-title {
  font-weight: bold;
  font-size: 1.1rem;
  flex-grow: 1;
}

.ai-chat-body {
  padding: 1rem;
}

.ai-chat-feed {
  max-height: 450px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.ai-chat-feed p { margin: 0; line-height: 1.4; }

.ai-chat-input-area {
  border-top: 1px solid #eee;
  padding-top: 0.75rem;
  display: flex;
  gap: 8px;
}

.ai-chat-input-area #user-input {
  flex-grow: 1;
  border: 1px solid #ccc;
  border-radius: 20px;
  padding: 8px 15px;
  font-size: 0.9rem;
  margin: 0;
  outline: none;
}

.ai-chat-input-area #user-input:focus {
  border-color: var(--primary-color);
}

.ai-chat-input-area #send-btn {
  background: var(--primary-color);
  color: var(--text-color-light);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}

.ai-chat-input-area #send-btn:hover {
  background: var(--primary-color-hover);
}

#ai-chat {
  margin-bottom: 2rem;
  scroll-margin-top: 70px;
}

/* Guidebook section group */
#guidebook-group {
  margin-top: 2rem;
  padding-top: 0;
}

.guidebook-group-header {
  border-top: 2px solid var(--border-color);
  padding-top: 1.5rem;
  margin-bottom: 1.5rem;
}

.guidebook-group-header h2 {
  color: var(--text-color-dark);
  font-size: 1.4rem;
  margin: 0 0 0.25rem 0;
}

.guidebook-group-subtitle {
  color: #6c757d;
  font-size: 0.9rem;
  margin: 0;
}

.message-bubble { padding: 0.75rem; max-width: 80%; width: fit-content; font-size: 0.9rem; line-height: 1.4; }
.bot-message { background: #fff; border: 1px solid #eee; color: var(--text-color-dark); align-self: flex-start; border-radius: 8px 8px 8px 2px; }
.user-message { background: #e3f2fd; color: var(--text-color-dark); align-self: flex-end; border-radius: 8px 8px 2px 8px; }
.timestamp {
  font-size: 0.8rem;
  color: #999;
  margin: 0;
}
.user-message + .timestamp {
  align-self: flex-end;
}
.bot-message + .timestamp {
  align-self: flex-start;
}

/* ---------------------------------------------------
   4. RESPONSIVE & MOBILE STYLES
--------------------------------------------------- */
.mobile-header { display: none; }

@media (min-width: 769px) {
  .desktop-logo-container {
    display: block; /* Show on desktop */
  }

  #table-of-contents .desktop-logo-container {
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
  }

  #table-of-contents .desktop-logo-container .logo {
    max-width: 80%;
    height: auto;
  }
}

@media (max-width: 768px) {
  /* Scroll lock for modals on mobile */
  html.nav-open, body.nav-open {
    overflow: hidden;
  }

  .site-header { display: none; }
  .mobile-header { display: flex; justify-content: space-between; align-items: center; background: #fff; border-bottom: 1px solid var(--border-color); padding: 0 1rem; height: var(--mobile-header-height); position: sticky; top: 0; z-index: 999; }
  .main-wrapper { flex-direction: column; }
  .container { padding: 1em; }
  
  #table-of-contents { position: fixed; top: 0; left: 0; width: 250px; height: 100%; z-index: 1001; transform: translateX(-100%); transition: transform 0.3s ease-in-out; border-right: 1px solid var(--border-color); }
  #table-of-contents.nav-open { transform: translateX(0); }
  #nav-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; opacity: 0; visibility: hidden; transition: opacity 0.3s ease-in-out, visibility 0.3s; }
  #nav-overlay.nav-open { opacity: 1; visibility: visible; }
  #hamburger-btn { background: none; border: none; cursor: pointer; padding: 10px; display: flex; flex-direction: column; justify-content: space-around; width: 30px; height: 30px; }
  #hamburger-btn span { display: block; width: 100%; height: 2px; background-color: var(--text-color-dark); }

  /* **FIX: Center the logo in the mobile header** */
  .mobile-header > a {
    text-align: center;
    flex-grow: 1; /* Allows the logo's link to take up the middle space */
  }

}

/* ---------------------------------------------------
   5. PRINT STYLES
--------------------------------------------------- */
@media print {
  body { color: #000 !important; }
  .site-header, .mobile-header, #table-of-contents, #ai-chat, #nav-overlay { display: none !important; }
  .main-wrapper { display: block; }
  section { break-inside: avoid; page-break-inside: avoid; }
  a { text-decoration: none; }
}

/* ---------------------------------------------------
   6. HOME ASSISTANT DASHBOARD STYLES
--------------------------------------------------- */
#ha-dashboard {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 2rem;
  margin-top: 2rem;
}

.ha-card {
  flex: 1 1 180px; /* Flex-grow, flex-shrink, basis */
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.ha-card-title {
  font-size: 0.9rem;
  color: #6c757d;
  margin: 0 0 0.5rem 0;
  font-weight: bold;
}

.ha-card-status {
  font-size: 1.75rem;
  font-weight: bold;
  transition: color 0.3s ease-in-out;
  flex-grow: 1; /* Allows it to take up available vertical space */
  display: flex;
  align-items: center; /* Vertically centers the text */
  justify-content: center; /* Horizontally centers the text */
}

/* ---------------------------------------------------
   6. HOME ASSISTANT DASHBOARD STYLES
--------------------------------------------------- */
#ha-dashboard {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 2rem;
}

.ha-card {
  flex: 1 1 180px; /* Flex-grow, flex-shrink, basis */
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.ha-card-title {
  font-size: 0.9rem;
  color: #6c757d;
  margin: 0 0 0.5rem 0;
  font-weight: bold;
  text-align: center;
}

.ha-card-status {
  font-size: 1.75rem;
  font-weight: bold;
  text-align: center;
  margin-top: auto; /* Pushes status to bottom */
  transition: color 0.3s ease-in-out;
}



/* ---------------------------------------------------
   7. HOME ASSISTANT CLIMATE CONTROLS (v2 - Slider)
--------------------------------------------------- */
.climate-card {
  flex-basis: 100%;
  gap: 1rem;
}

.climate-entity {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.5rem 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}
.climate-card .climate-entity:first-of-type {
  border-top: none;
  padding-top: 0;
}

.climate-name {
  font-weight: bold;
  font-size: 1.1rem;
  grid-column: 1 / 2;
}

.climate-current-temp {
  font-size: 0.9rem;
  color: #6c757d;
  grid-column: 1 / 2;
}

.climate-set-temp-display {
  grid-row: 1 / 3;
  grid-column: 2 / 3;
  font-size: 2.25rem;
  font-weight: bold;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.climate-slider-container {
  grid-column: 1 / 3;
  width: 100%;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: #e9ecef;
  border-radius: 5px;
  outline: none;
  opacity: 0.7;
  transition: opacity .2s;
}
input[type="range"]:hover {
  opacity: 1;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: var(--primary-color);
  cursor: pointer;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 5px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  cursor: pointer;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

/* Style for the input container when the bot is replying */
#chat-input-container.loading #user-input,
#chat-input-container.loading #send-btn {
  opacity: 0.6;
  cursor: wait;
  pointer-events: none; /* This prevents clicks and taps */
}

/* ---------------------------------------------------
   8. HOME ASSISTANT LIGHT CONTROLS (v2.1 - Refined)
--------------------------------------------------- */
.light-control-card {
  flex: 1 1 220px;
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.light-control-header {
  display: flex;
  justify-content: space-between; /* Pushes name left, toggle right */
  align-items: center;
}

.light-control-name {
  font-weight: bold;
  font-size: 1.1rem;
}

/* --- The normally-proportioned switch --- */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 28px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
  -webkit-transform: translateX(22px);
  -ms-transform: translateX(22px);
  transform: translateX(22px);
}

input:disabled + .slider {
  cursor: not-allowed;
  opacity: 0.5;
}
/* --- End of switch styles --- */

.light-slider-group {
  display: none; /* Hidden by default, shown by JS */
  flex-direction: column;
  gap: 0.5rem;
}

.light-slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.light-slider-row .material-symbols-outlined {
  color: #6c757d;
  font-size: 20px;
}

.light-slider-row input[type="range"] {
  flex-grow: 1;
  height: 6px;
}

.light-slider-value {
  font-size: 0.8rem;
  color: #6c757d;
  min-width: 40px;
  text-align: right;
}

/* --- Add these styles to the end of the file --- */

.light-unavailable-notice {
  /* Hidden by default */
  display: none; 
  
  /* Styling for the notice */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  padding: 1rem 0;
  color: #6c757d;
  font-size: 0.9rem;
}

.light-unavailable-notice .material-symbols-outlined {
  font-size: 28px;
}

/* --- STATE-BASED VISIBILITY CONTROL --- */

/* When the card has the .is-unavailable class, HIDE the normal controls */
.light-control-card.is-unavailable .light-controls-wrapper {
  display: none;
}

/* When the card has the .is-unavailable class, SHOW the notice */
.light-control-card.is-unavailable .light-unavailable-notice {
  display: flex;
}

/* --- Styles for Light Refresh Button --- */
.light-header-controls {
  display: flex;
  align-items: center;
  gap: 12px; /* Space between refresh button and toggle */
}

.light-refresh-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c757d;
}

.light-refresh-btn:hover {
  background-color: rgba(0,0,0,0.05);
  color: #333;
}

/* Animation for the spinning icon */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.light-control-card.is-refreshing .light-refresh-btn .material-symbols-outlined {
  animation: spin 1s linear infinite;
}

.light-control-card.is-refreshing .light-refresh-btn {
  pointer-events: none; /* Disable clicking while refreshing */
}

/* --- 9. CHATBOT SUGGESTION CHIPS --- */

.suggestions-container {
  display: flex;
  flex-wrap: wrap; /* Allows buttons to wrap to the next line on small screens */
  gap: 8px; /* Space between buttons */
  justify-content: flex-start; /* Align buttons to the left */
  padding: 5px 0 10px 0; /* Some spacing around the container */
  max-width: 100%;
}

.suggestion-chip {
  background-color: #e3f2fd;
  border: 1px solid #bbdefb;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 0.9rem;
  color: var(--text-color-dark);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.suggestion-chip:hover {
  background-color: #bbdefb;
  border-color: #90caf9;
}

/* --- 10. LANGUAGE PICKER STYLES --- */

/* Container styles */
#language-picker-desktop-container {
  padding: 0 0.5rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

#language-picker-mobile-container {
  display: flex;
  align-items: center;
  margin-right: 0.5rem; /* Space between picker and hamburger */
}

/* Common select styles */
#language-picker-desktop-container select,
#language-picker-mobile-container select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27292.4%27%20height%3D%27292.4%27%3E%3Cpath%20fill%3D%27%23666%27%20d%3D%27M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%27%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7em top 50%, 0 0;
  background-size: 0.65em auto, 100%;
}

#language-picker-mobile-container select {
  font-size: 0.8rem;
  padding: 0.4rem 1.5rem 0.4rem 0.5rem; /* Make room for arrow */
  max-width: 120px;
}

/* ---------------------------------------------------
   11. NOTICEBOARD STYLES
--------------------------------------------------- */
#noticeboard {
  margin-bottom: 2rem;
}

.noticeboard-card {
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.noticeboard-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.noticeboard-title {
  font-weight: bold;
  font-size: 1.1rem;
  flex-grow: 1;
}

.noticeboard-badge {
  background-color: var(--primary-color);
  color: #fff;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
}

.noticeboard-body {
  padding: 1rem;
}

.noticeboard-description {
  font-size: 0.9rem;
  color: #6c757d;
  margin: 0 0 0.5rem 0;
  line-height: 1.4;
}

.noticeboard-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 8px;
}

.noticeboard-since {
  font-size: 0.8rem;
  color: #999;
}

.noticeboard-translate-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.noticeboard-translate-label {
  font-size: 0.8rem;
  color: #999;
}

.noticeboard-switch {
  transform: scale(0.75);
  transform-origin: right center;
}

.noticeboard-feed {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.noticeboard-empty {
  text-align: center;
  color: #999;
  padding: 1.5rem 0;
  margin: 0;
}

.noticeboard-post {
  padding: 0.75rem;
  max-width: 80%;
}

.noticeboard-post-own {
  align-self: flex-end;
  background: #e3f2fd;
  border-radius: 8px 8px 2px 8px;
}

.noticeboard-post-other {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 8px 8px 8px 2px;
}

.noticeboard-post-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.noticeboard-delete-btn {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.noticeboard-delete-btn:hover {
  color: #d9534f;
}

.noticeboard-post-message {
  margin: 0 0 4px 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.noticeboard-post-message.noticeboard-translating {
  color: #ccc;
  animation: noticeboardPulse 1.2s ease-in-out infinite;
}

@keyframes noticeboardPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.noticeboard-post-meta {
  margin: 0;
  font-size: 0.8rem;
  color: #999;
}

.noticeboard-post-own .noticeboard-post-meta {
  text-align: right;
}

.noticeboard-input-area {
  border-top: 1px solid #eee;
  padding-top: 0.75rem;
}

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

.noticeboard-input {
  flex-grow: 1;
  border: 1px solid #ccc;
  border-radius: 20px;
  padding: 8px 15px;
  font-size: 0.9rem;
  outline: none;
}

.noticeboard-input:focus {
  border-color: var(--primary-color);
}

.noticeboard-post-btn {
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}

.noticeboard-post-btn:hover {
  background: var(--primary-color-hover);
}

.noticeboard-post-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.noticeboard-input-hint {
  font-size: 0.8rem;
  color: #aaa;
  margin-top: 6px;
}