:root {
  --primary: #00594C;
  --primary-dark: #003D33;
  --accent: #00BFA5;
  --bg-sidebar: #002B24;
  --bg-main: #F4F7F6;
  --text-main: #333;
  --text-light: #fff;
  --text-muted: #757575;
  --card-bg: #ffffff;
  --border-color: #E0E0E0;
  --sidebar-width: 260px;
  --header-height: 60px;
  --danger: #d32f2f;
  --success: #388e3c;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative; /* Trigger area pozícionáláshoz */
}

/* --- Layout --- */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 1000;
  transform: translateX(-100%); /* Alapból rejtve */
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 5px 0 15px rgba(0,0,0,0.3);
}

.sidebar.visible {
  transform: translateX(0); /* Megjelenik */
}

/* Láthatatlan trigger zóna a bal szélen */
.sidebar-trigger {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 15px; /* Csak 15px széles sáv */
  z-index: 999;
  background: transparent;
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 20px;
  background-color: rgba(0, 0, 0, 0.2);
}

.sidebar-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.nav-menu {
  flex: 1;
  padding: 20px 0;
  list-style: none;
}

.nav-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.7);
  transition: all 0.2s;
  font-weight: 500;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-light);
}

.nav-item.active {
  background-color: var(--primary);
  color: var(--text-light);
  border-left: 4px solid var(--accent);
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-open .main-wrapper {
  margin-left: var(--sidebar-width);
}

header {
  height: var(--header-height);
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow);
  z-index: 90;
  overflow-x: auto; /* Vízszintes görgetés engedélyezése */
  white-space: nowrap; /* Ne törjenek meg az elemek */
  -webkit-overflow-scrolling: touch; /* Sima görgetés mobilokon */
  gap: 20px;
}

header::-webkit-scrollbar {
  display: none; /* Rejtsük el a csúnya görgetősávot */
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0; /* Ne engedjük összepréselni az elemeket */
}

.header-left {
  gap: 15px;
}

.device-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #eee;
  padding: 5px 12px;
  border-radius: 20px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  position: relative;
  padding: 5px 10px;
  border-radius: 4px;
}

.user-profile:hover {
  background: #f0f0f0;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.8rem;
}

/* --- Dashboard Tabs --- */
#connectionStatus.offline {
  color: #f44336 !important;
}

#connectionStatus.offline span {
  animation: pulse 1.5s infinite;
}

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

.dashboard-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  border-radius: 0;
}

.tab-btn:hover {
  color: var(--primary);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* --- Live Data Log --- */
.live-log {
  background: #1e1e1e;
  color: #00ff00;
  font-family: 'Courier New', Courier, monospace;
  padding: 15px;
  border-radius: 4px;
  height: 400px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.4;
}

.log-entry {
  margin-bottom: 5px;
  border-bottom: 1px solid #333;
  padding-bottom: 5px;
}

.log-time { color: #888; margin-right: 10px; }

/* --- Content --- */

main {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
}

.page-section {
  display: none;
  /* JS váltogatja */
}

.page-section.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 25px;
}

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

.card h3 {
  margin-bottom: 20px;
  font-size: 1.1rem;
  color: var(--primary);
  border-bottom: 1px solid #863737;
  padding-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* --- Forms & Buttons --- */

button {
  padding: 8px 16px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.2s;
}

button.primary {
  background: var(--primary);
  color: white;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.danger-outline {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

button.danger-outline:hover {
  background: var(--danger);
  color: white;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* --- Auth Pages --- */
.auth-wrapper {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.auth-card {
  background: rgb(71, 153, 84);
  padding: 40px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

/* --- Utilities --- */
.text-center {
  text-align: center;
}

.mt-4 {
  margin-top: 20px;
}

.sensor {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  background: #e9e6e6;
  border-radius: 4px;
  margin-bottom: 8px;
  position: relative;
}

.sensor-label {
  font-weight: 600;
  color: #666;
}

.sensor-value {
  font-weight: 700;
  color: var(--primary);
}

/* --- Toggle Switch --- */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

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

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

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

input:checked + .slider-round { background-color: var(--primary); }
input:checked + .slider-round:before { transform: translateX(26px); }

/* --- Gauge Widget --- */
.gauge-container {
  position: relative;
  width: 150px;
  height: 80px;
  margin: 10px auto;
  overflow: hidden;
  text-align: center;
}

.gauge-bg {
  fill: none;
  stroke: #eee;
  stroke-width: 10;
}

.gauge-value-arc {
  fill: none;
  stroke: var(--primary);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dasharray 0.5s ease;
}

.gauge-text {
  font-family: inherit;
  font-weight: 700;
  fill: var(--text-main);
}

/* --- Range Slider --- */
input[type=range] {
  width: 100%;
  margin: 10px 0;
}

/* --- Mini Select & Schema Fixes --- */
.widget-mini-select {
  font-size: 0.65rem;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid #ddd;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.2s;
  height: 22px;
}

.sensor:hover .widget-mini-select,
.card:hover .widget-mini-select {
  opacity: 1;
}

.widget-mini-select:focus {
  opacity: 1;
}

/* Modal szélesség növelése a sémához */
#section_schema .card {
  max-width: 1000px;
  width: 100%;
}

@media (max-width: 1100px) {
  #section_schema .card {
    overflow-x: auto;
  }
}