/* ==========================================================================
   Home Assistant 1:1 Pixel-Perfect Lovelace Dashboard Stylesheet
   Matches demo.home-assistant.io/#/lovelace/home
   ========================================================================== */

:root, [data-theme="light"] {
  --ha-bg: #fafafa;
  --ha-header-bg: #ffffff;
  --ha-header-text: #212121;
  --ha-sidebar-bg: #ffffff;
  --ha-card-bg: #ffffff;
  --ha-card-radius: 12px;
  --ha-card-border: 1px solid rgba(0, 0, 0, 0.08);
  --ha-text-primary: #212121;
  --ha-text-secondary: #727272;
  --ha-primary-color: #03a9f4;
  --ha-primary-rgb: 3, 169, 244;
  --ha-active-tile-bg: #f5f5f5;
  --ha-badge-bg: #ffffff;
  --ha-badge-text: #212121;
  --ha-icon-inactive: #727272;
  --ha-icon-bg-inactive: rgba(0, 0, 0, 0.06);
  --ha-slider-track: #e0e0e0;
  --ha-slider-fill: #ffb300;
  --ha-divider: rgba(0, 0, 0, 0.08);
  --ha-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --ha-bg: #111111;
  --ha-header-bg: #111111;
  --ha-header-text: #ffffff;
  --ha-sidebar-bg: #111111;
  --ha-card-bg: #1c1c1c;
  --ha-card-radius: 12px;
  --ha-card-border: none;
  --ha-text-primary: #e1e1e1;
  --ha-text-secondary: #9b9b9b;
  --ha-primary-color: #03a9f4;
  --ha-primary-rgb: 3, 169, 244;
  --ha-active-tile-bg: #282828;
  --ha-badge-bg: #1f1f1f;
  --ha-badge-text: #e1e1e1;
  --ha-icon-inactive: #9b9b9b;
  --ha-icon-bg-inactive: rgba(255, 255, 255, 0.08);
  --ha-slider-track: #2e2e2e;
  --ha-slider-fill: #ffb300;
  --ha-divider: rgba(255, 255, 255, 0.08);
  --ha-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="gavasah"] {
  --ha-bg: #070a0f;
  --ha-header-bg: #0a0f17;
  --ha-header-text: #00e5ff;
  --ha-sidebar-bg: #080d14;
  --ha-card-bg: #0f1724;
  --ha-card-radius: 14px;
  --ha-card-border: 1px solid rgba(0, 229, 255, 0.18);
  --ha-text-primary: #f8fafc;
  --ha-text-secondary: #94a3b8;
  --ha-primary-color: #00e5ff;
  --ha-primary-rgb: 0, 229, 255;
  --ha-active-tile-bg: #142033;
  --ha-badge-bg: #111a29;
  --ha-badge-text: #00e5ff;
  --ha-icon-inactive: #64748b;
  --ha-icon-bg-inactive: rgba(0, 229, 255, 0.08);
  --ha-slider-track: #1e293b;
  --ha-slider-fill: #00e5ff;
  --ha-divider: rgba(0, 229, 255, 0.15);
  --ha-shadow: 0 4px 20px rgba(0, 229, 255, 0.1);
}

[data-theme="oled"] {
  --ha-bg: #000000;
  --ha-header-bg: #000000;
  --ha-header-text: #ffffff;
  --ha-sidebar-bg: #000000;
  --ha-card-bg: #121212;
  --ha-card-radius: 12px;
  --ha-card-border: 1px solid #242424;
  --ha-text-primary: #ffffff;
  --ha-text-secondary: #888888;
  --ha-primary-color: #38bdf8;
  --ha-primary-rgb: 56, 189, 248;
  --ha-active-tile-bg: #1c1c1c;
  --ha-badge-bg: #181818;
  --ha-badge-text: #ffffff;
  --ha-icon-inactive: #666666;
  --ha-icon-bg-inactive: rgba(255, 255, 255, 0.08);
  --ha-slider-track: #262626;
  --ha-slider-fill: #38bdf8;
  --ha-divider: #242424;
  --ha-shadow: 0 0 20px rgba(0, 0, 0, 0.9);
}

/* Reset & Global */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--ha-bg);
  color: var(--ha-text-primary);
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Shell Layout */
.ha-app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Left Icon Rail Sidebar */
.ha-rail {
  width: 56px;
  height: 100vh;
  background-color: var(--ha-sidebar-bg);
  border-right: 1px solid var(--ha-divider);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  flex-shrink: 0;
  z-index: 100;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.ha-rail.expanded {
  width: 240px;
  align-items: stretch;
}

.ha-rail-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 8px;
}

.ha-rail.expanded .ha-rail-top {
  align-items: stretch;
}

.ha-rail-btn {
  background: transparent;
  border: none;
  color: var(--ha-text-primary);
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.ha-rail.expanded .ha-rail-btn {
  width: calc(100% - 16px);
  margin: 0 8px;
  justify-content: flex-start;
  padding: 0 12px;
  gap: 16px;
}

.ha-rail-btn .btn-label {
  display: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.ha-rail.expanded .ha-rail-btn .btn-label {
  display: inline;
}

.ha-rail-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.ha-rail-btn.active {
  background-color: rgba(3, 169, 244, 0.2);
  color: var(--ha-primary-color);
}

.ha-rail-btn.active-square {
  background-color: rgba(3, 169, 244, 0.25);
  color: #03a9f4;
}

.ha-rail-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 8px;
}

.ha-rail.expanded .ha-rail-bottom {
  align-items: stretch;
}

.ha-badge-counter {
  position: absolute;
  top: 6px;
  right: 6px;
  background-color: #ff9800;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ha-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #b0bec5;
  color: #263238;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Main View Frame */
.ha-main-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Top App Header */
.ha-top-header {
  height: 56px;
  background-color: var(--ha-header-bg);
  border-bottom: 1px solid var(--ha-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.ha-title {
  font-size: 20px;
  font-weight: 500;
  color: var(--ha-header-text);
  letter-spacing: -0.01em;
}

.ha-back-brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--ha-divider);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ha-header-text);
  text-decoration: none;
  transition: all 0.2s ease;
}

.ha-back-brand-btn:hover {
  background: var(--ha-accent);
  color: #fff;
  border-color: var(--ha-accent);
}

.ha-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ha-action-btn {
  background: transparent;
  border: none;
  color: var(--ha-header-text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.ha-action-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Theme Selector Pill */
.ha-theme-pill-select {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--ha-divider);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
}

.ha-theme-select-input {
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.ha-theme-select-input option {
  background: #1c1c1c;
  color: #fff;
}

/* Lovelace Dashboard Scroll Container */
.ha-lovelace-view {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 60px 24px;
}

/* Sub-Header Tabs & Badges Row */
.ha-badges-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.ha-view-chip {
  background: rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ha-text-primary);
  display: inline-flex;
  align-items: center;
}

.ha-badges-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ha-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ha-badge-bg);
  border: 1px solid var(--ha-divider);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ha-badge-text);
  box-shadow: var(--ha-shadow);
  cursor: pointer;
}

.ha-header-badge.person {
  gap: 8px;
}

/* Sections Grid (2 Columns on Desktop) */
.ha-sections-columns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 1024px) {
  .ha-sections-columns {
    grid-template-columns: 1fr;
  }
}

.ha-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Section Container */
.ha-section-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ha-sec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.ha-sec-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ha-sec-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--ha-text-primary);
}

.ha-sec-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--ha-text-secondary);
}

/* Cards Grid inside Section */
.ha-cards-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .ha-cards-2col {
    grid-template-columns: 1fr;
  }
}

/* Base Card Style */
.ha-c-card {
  background-color: var(--ha-card-bg);
  border-radius: var(--ha-card-radius);
  border: var(--ha-card-border);
  box-shadow: var(--ha-shadow);
  overflow: hidden;
  transition: background-color 0.2s, box-shadow 0.2s;
}

/* Welcome Announcement Card */
.ha-welcome-announcement {
  background-color: var(--ha-card-bg);
  border-radius: var(--ha-card-radius);
  padding: 16px;
  box-shadow: var(--ha-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ha-welcome-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.ha-welcome-heading {
  font-size: 16px;
  font-weight: 600;
  color: #03a9f4;
}

.ha-welcome-sub {
  font-size: 12px;
  color: var(--ha-text-secondary);
  margin-top: 2px;
}

.ha-btn-next-demo {
  background-color: #03a9f4;
  color: #ffffff;
  border: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.ha-btn-next-demo:hover {
  opacity: 0.9;
}

.ha-welcome-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ha-text-primary);
}

.ha-welcome-link {
  color: #03a9f4;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.ha-welcome-link:hover {
  text-decoration: underline;
}

/* Tile Cards */
.ha-t-tile {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.ha-t-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ha-t-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--ha-icon-bg-inactive);
  color: var(--ha-icon-inactive);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.ha-t-tile.active .ha-t-icon {
  background-color: rgba(255, 179, 0, 0.2);
  color: #ffb300;
}

.ha-t-tile.active.climate .ha-t-icon {
  background-color: rgba(255, 112, 67, 0.2);
  color: #ff7043;
}

.ha-t-tile.active.energy .ha-t-icon {
  background-color: rgba(76, 175, 80, 0.2);
  color: #4caf50;
}

.ha-t-tile.active.media .ha-t-icon {
  background-color: rgba(3, 169, 244, 0.2);
  color: #03a9f4;
}

.ha-t-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.ha-t-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--ha-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ha-t-state {
  font-size: 12px;
  color: var(--ha-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Slider Box in Tile */
.ha-t-slider-wrap {
  position: relative;
  width: 100%;
  height: 40px;
  background-color: var(--ha-slider-track);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.ha-t-slider-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background-color: #fbc02d;
  pointer-events: none;
  transition: width 0.1s linear;
}

.ha-t-slider-thumb-bar {
  position: absolute;
  top: 4px;
  width: 4px;
  height: 32px;
  background-color: #ffffff;
  border-radius: 2px;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.ha-t-slider-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 5;
  margin: 0;
}

/* Action Buttons (Blinds, Thermostat) */
.ha-btn-group-right {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.ha-mini-btn {
  background: var(--ha-icon-bg-inactive);
  border: none;
  color: var(--ha-text-primary);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ha-mini-btn:hover {
  background-color: var(--ha-primary-color);
  color: #fff;
}

/* Floating Bottom Shield */
.ha-floating-shield {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background-color: #1e3a8a;
  color: #60a5fa;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s;
}

.ha-floating-shield:hover {
  transform: scale(1.08);
}

/* Docked KNX Bus Live Log Bar */
.ha-live-knx-dock {
  position: fixed;
  bottom: 0;
  left: 56px;
  right: 0;
  background-color: #000000;
  border-top: 1px solid #222222;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #888888;
  z-index: 999;
}

.ha-knx-pulse-dot {
  width: 6px;
  height: 6px;
  background-color: #10b981;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  box-shadow: 0 0 6px #10b981;
}

.ha-live-knx-dock .telegram-highlight {
  color: #00e5ff;
}
