:root {
  color-scheme: dark;
  --hs-bg: #040704;
  --hs-bg-2: #071008;
  --hs-panel: rgba(9, 17, 12, 0.78);
  --hs-panel-strong: rgba(12, 24, 16, 0.92);
  --hs-card: rgba(8, 14, 10, 0.78);
  --hs-card-2: rgba(14, 26, 17, 0.68);
  --hs-border: rgba(127, 242, 55, 0.16);
  --hs-border-strong: rgba(149, 242, 15, 0.38);
  --hs-text: #f2f8ef;
  --hs-muted: #93a891;
  --hs-dim: #657363;
  --hs-green: #95f20f;
  --hs-green-2: #00e676;
  --hs-blue: #55aeff;
  --hs-orange: #f2b84b;
  --hs-red: #ff626f;
  --hs-shadow: 0 28px 110px rgba(0, 0, 0, 0.48);
  --hs-glow: 0 0 34px rgba(0, 230, 118, 0.16);
  --hs-radius: 8px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--hs-bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(149, 242, 15, 0.09), transparent 26%),
    radial-gradient(circle at 92% 8%, rgba(0, 230, 118, 0.06), transparent 28%),
    linear-gradient(145deg, #020402 0%, #071008 46%, #020402 100%);
  color: var(--hs-text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button, input, textarea, select {
  font: inherit;
}

button, a.button {
  min-height: 36px;
  border: 1px solid var(--hs-border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(21, 38, 24, 0.92), rgba(8, 16, 10, 0.92));
  color: var(--hs-text);
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
  transition: 160ms ease;
}

button:hover, a.button:hover {
  border-color: var(--hs-border-strong);
  color: var(--hs-green);
  box-shadow: var(--hs-glow);
}

button.primary {
  color: #031307;
  border-color: rgba(149, 242, 15, 0.72);
  background: linear-gradient(180deg, #a9ff2d, #43d763);
  font-weight: 800;
}

button.danger {
  border-color: rgba(255, 98, 111, 0.34);
  color: #ffbac0;
}

button.ghost {
  background: rgba(255, 255, 255, 0.03);
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--hs-border);
  background: rgba(3, 7, 4, 0.82);
  color: var(--hs-text);
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--hs-border-strong);
  box-shadow: 0 0 0 3px rgba(149, 242, 15, 0.1);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: var(--hs-muted);
  font-size: 13px;
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.15; }
h1 { font-size: clamp(26px, 4vw, 40px); margin-bottom: 6px; }
h2 { font-size: 22px; margin-bottom: 8px; }
h3 { font-size: 15px; margin-bottom: 8px; }

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: #000;
  transition: opacity 280ms ease, visibility 280ms ease;
}

.loading-screen.ready {
  opacity: 0;
  visibility: hidden;
}

.loading-logo {
  width: min(320px, 68vw);
  aspect-ratio: 1;
  object-fit: contain;
}

.loading-status {
  min-height: 28px;
  color: var(--hs-green);
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.hidden { display: none !important; }
.muted { color: var(--hs-muted); }
.dim { color: var(--hs-dim); }
.good { color: var(--hs-green); }
.bad { color: var(--hs-red); }
.warn { color: var(--hs-orange); }
.blue { color: var(--hs-blue); }

.page-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.dashboard-shell {
  min-height: calc(100vh - 36px);
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--hs-border);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(7, 13, 9, 0.9), rgba(3, 7, 4, 0.92)),
    radial-gradient(circle at top left, rgba(149, 242, 15, 0.08), transparent 34%);
  box-shadow: var(--hs-shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  border-right: 1px solid var(--hs-border);
  background: rgba(2, 7, 4, 0.46);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.brand-title {
  font-weight: 850;
  letter-spacing: 0;
}

.brand-subtitle {
  color: var(--hs-muted);
  font-size: 11px;
}

.side-nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--hs-muted);
  text-align: left;
}

.nav-item:hover {
  color: var(--hs-green);
  border-color: var(--hs-border);
  background: rgba(149, 242, 15, 0.06);
  box-shadow: none;
}

.nav-item.active {
  color: #051206;
  border-color: rgba(149, 242, 15, 0.58);
  background: linear-gradient(180deg, rgba(149, 242, 15, 0.95), rgba(43, 160, 58, 0.92));
  font-weight: 800;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 8px;
  font-size: 12px;
  color: var(--hs-muted);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.online-badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  border: 1px solid var(--hs-border);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(149, 242, 15, 0.06);
  color: var(--hs-muted);
  font-size: 12px;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.lang-wrap {
  position: relative;
  display: inline-flex;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  width: 170px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--hs-border);
  border-radius: 10px;
  background: rgba(4, 9, 5, 0.98);
  box-shadow: var(--hs-shadow);
}

.lang-menu button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--hs-green);
  box-shadow: 0 0 14px rgba(149, 242, 15, 0.8);
}

.dot.offline {
  background: var(--hs-red);
  box-shadow: 0 0 14px rgba(255, 98, 111, 0.55);
}

.content-grid {
  display: grid;
  gap: 14px;
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.glass-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--hs-border);
  border-radius: var(--hs-radius);
  background:
    linear-gradient(180deg, rgba(18, 31, 20, 0.72), rgba(5, 10, 7, 0.86));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 14px 34px rgba(0, 0, 0, 0.28);
}

.glass-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(130deg, rgba(149, 242, 15, 0.07), transparent 36%);
}

.card-pad {
  position: relative;
  padding: 14px;
}

.sensor-card {
  min-height: 128px;
}

.sensor-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--hs-muted);
  font-size: 12px;
}

.sensor-value {
  margin-top: 10px;
  font-size: 26px;
  line-height: 1;
  font-weight: 850;
}

.sensor-sub {
  margin-top: 7px;
  color: var(--hs-muted);
  font-size: 12px;
}

.micro-line {
  width: 100%;
  height: 30px;
  margin-top: 11px;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 300px;
  gap: 12px;
}

.chart-card {
  min-height: 236px;
}

.chart {
  width: 100%;
  height: 156px;
  margin-top: 12px;
}

.device-list {
  display: grid;
  gap: 11px;
  margin-top: 14px;
}

.device-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.plant-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hs-border);
  border-radius: 10px;
  background: rgba(149, 242, 15, 0.08);
  color: var(--hs-green);
}

.table-grid {
  display: grid;
  gap: 12px;
}

.device-card, .plant-card, .rule-card, .setting-card {
  display: grid;
  gap: 12px;
}

.device-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.badge-stack {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.support-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(85, 174, 255, 0.34);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(85, 174, 255, 0.08);
  color: #b9ddff;
  font-size: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.meta-box {
  border: 1px solid var(--hs-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  padding: 10px;
}

.meta-box span {
  display: block;
  color: var(--hs-muted);
  font-size: 11px;
  margin-bottom: 5px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.device-actions {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--hs-border);
}

.support-form {
  margin-bottom: 12px;
}

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

.empty-state, .chart-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--hs-muted);
  text-align: center;
  border: 1px dashed var(--hs-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  padding: 16px;
}

.chart-empty {
  height: 156px;
  margin-top: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(14px);
}

.confirm-dialog {
  width: min(520px, 100%);
  border: 1px solid var(--hs-border-strong);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(13, 28, 17, 0.96), rgba(4, 8, 5, 0.98));
  box-shadow: var(--hs-shadow), var(--hs-glow);
  padding: 22px;
}

.confirm-dialog p {
  color: var(--hs-muted);
  line-height: 1.55;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.spinner {
  width: 14px;
  height: 14px;
  display: inline-block;
  margin-right: 7px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--hs-green);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.cards-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cards-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.toggle {
  width: 46px;
  height: 26px;
  border: 1px solid var(--hs-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  padding: 3px;
}

.toggle span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--hs-muted);
  transition: 160ms ease;
}

.toggle.on {
  border-color: rgba(149, 242, 15, 0.58);
  background: rgba(149, 242, 15, 0.12);
}

.toggle.on span {
  transform: translateX(18px);
  background: var(--hs-green);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-row button.active {
  color: #051206;
  background: var(--hs-green);
  border-color: var(--hs-green);
  font-weight: 800;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  border-left: 1px solid var(--hs-border);
  padding-left: 12px;
}

.chat-shell {
  display: grid;
  grid-template-rows: minmax(320px, 1fr) auto;
  min-height: 560px;
}

.messages {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  overflow: auto;
}

.msg {
  max-width: min(720px, 82%);
  border-radius: 14px;
  padding: 11px 13px;
  font-size: 14px;
  line-height: 1.45;
}

.msg.user {
  justify-self: end;
  color: #041307;
  background: var(--hs-green);
  border-top-right-radius: 4px;
}

.msg.assistant {
  justify-self: start;
  border: 1px solid var(--hs-border);
  background: rgba(255, 255, 255, 0.035);
  color: #d7e8d2;
  border-top-left-radius: 4px;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--hs-border);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  max-width: 360px;
  border: 1px solid var(--hs-border-strong);
  border-radius: 10px;
  background: rgba(7, 14, 9, 0.96);
  box-shadow: var(--hs-shadow);
  padding: 13px 14px;
  color: var(--hs-text);
}

.auth-wrap, .landing {
  min-height: 100vh;
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.55fr);
  gap: 24px;
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.hero-title {
  font-size: clamp(42px, 7vw, 82px);
  margin: 0 0 14px;
}

.hero-title span { color: var(--hs-green); }

.hero-lead {
  max-width: 760px;
  color: #d7e8d2;
  font-size: 18px;
  line-height: 1.55;
}

.form {
  display: grid;
  gap: 12px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.tabs button.active {
  color: #051206;
  background: var(--hs-green);
  border-color: var(--hs-green);
  font-weight: 800;
}

.notice {
  min-height: 22px;
  color: var(--hs-orange);
  overflow-wrap: anywhere;
}

.qr-video {
  width: 100%;
  max-width: 460px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #000;
  border: 1px solid var(--hs-border);
  border-radius: 8px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.7fr) minmax(0, 1.3fr);
  gap: 14px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 660px;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--hs-border);
  padding: 10px 8px;
  text-align: left;
}

th {
  color: var(--hs-muted);
  font-size: 12px;
  text-transform: uppercase;
}

@media (max-width: 1180px) {
  .sensor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lower-grid { grid-template-columns: 1fr; }
  .cards-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .page-shell { padding: 10px; }
  .dashboard-shell { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--hs-border);
  }
  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sidebar-foot { display: none; }
  .main { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .auth-wrap, .landing { grid-template-columns: 1fr; padding: 14px; }
  .admin-layout, .cards-2, .cards-3, .support-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .sensor-grid, .meta-grid { grid-template-columns: 1fr; }
  .side-nav { grid-template-columns: 1fr; }
  .chat-form { grid-template-columns: 1fr; }
  button, a.button { width: 100%; }
  .action-row button, .filter-row button { width: auto; }
}
