:root {
  color-scheme: dark;
  --bg: #080b17;
  --panel: #101624;
  --panel-2: #151d2d;
  --text: #f4f7fb;
  --muted: #8f9db5;
  --line: rgba(255, 255, 255, .10);
  --primary: #40c6f0;
  --primary-strong: #25aee0;
  --danger: #ff6174;
  --ok: #45d4a0;
  --warn: #f8b44c;
  --shadow: 0 24px 80px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 0%, rgba(64, 198, 240, .22), transparent 28rem),
    radial-gradient(circle at 82% 10%, rgba(236, 84, 193, .16), transparent 26rem),
    linear-gradient(180deg, #0b1020 0%, #080b17 100%);
}

button { font: inherit; }
[hidden] { display: none !important; }

.shell {
  width: min(1160px, calc(100% - 36px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  margin-bottom: 18px;
  backdrop-filter: blur(18px);
}

.home-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--text);
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  padding: 7px;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
}

h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
  font-weight: 850;
}

.sub {
  margin-top: 4px;
  color: #93a6c4;
  font-size: 14px;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 8px 6px 6px;
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font-size: 14px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #40c6f0, #ec54c1 58%, #4c168d);
  color: white;
  font-size: 13px;
  font-weight: 850;
  flex: 0 0 auto;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.logout {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  text-decoration: none;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}

.toolbar h2 {
  margin: 0;
  font-size: 16px;
  color: #dfe8f7;
}

.ghost {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, .07);
  color: #dfe8f7;
  cursor: pointer;
  font-weight: 700;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.device-card {
  min-height: 112px;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .095), rgba(255, 255, 255, .045));
  box-shadow: 0 18px 48px rgba(0, 0, 0, .22);
  padding: 14px;
  cursor: pointer;
  color: var(--text);
  display: grid;
  gap: 14px;
  transition: .16s ease;
}

.device-card:hover,
.device-card.selected {
  border-color: rgba(64, 198, 240, .65);
  box-shadow: 0 18px 54px rgba(64, 198, 240, .16);
  transform: translateY(-2px);
}

.device-card.offline {
  opacity: .72;
  background: rgba(255, 255, 255, .04);
}

.device-head,
.device-card-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.device-copy { min-width: 0; }

.device-ac-badge,
.ac-icon,
.mode-icon,
.wind-icon {
  display: grid;
  place-items: center;
  color: var(--primary);
  background: rgba(64, 198, 240, .12);
  border: 1px solid rgba(64, 198, 240, .24);
}

.device-ac-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  flex: 0 0 auto;
}

.device-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.device-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 27px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(69, 212, 160, .12);
  color: var(--ok);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.off { background: rgba(255, 255, 255, .08); color: #98a6bb; }
.status-pill.offline { background: rgba(248, 180, 76, .12); color: var(--warn); }
.status-pill.sending { background: rgba(64, 198, 240, .14); color: var(--primary); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.empty {
  border: 1px dashed rgba(255, 255, 255, .18);
  border-radius: 8px;
  padding: 22px;
  background: rgba(255, 255, 255, .055);
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
}

.remote {
  max-width: 820px;
  justify-self: center;
  width: 100%;
  background: rgba(12, 18, 32, .86);
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.remote-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
  background:
    radial-gradient(circle at 22% 16%, rgba(64, 198, 240, .20), transparent 16rem),
    linear-gradient(135deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .035));
}

.chosen-device {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ac-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex: 0 0 auto;
}

.device-name-line {
  font-size: 19px;
  line-height: 1.2;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.device-subline {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: grid;
  padding: 26px;
  gap: 20px;
}

.climate-board {
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

.dial-zone {
  display: grid;
  justify-items: center;
  gap: 16px;
}

.temp-dial {
  --temp-angle: 172deg;
  --temp-color: #40c6f0;
  width: min(290px, 100%);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    conic-gradient(from -145deg, var(--temp-color) 0deg var(--temp-angle), rgba(255, 255, 255, .09) var(--temp-angle) 360deg);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 24px 66px rgba(0, 0, 0, .34);
  position: relative;
}

.temp-dial::before {
  content: "";
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 255, 255, .12), transparent 8rem),
    linear-gradient(180deg, #111b2c, #0d1322);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}

.temp-center {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
}

.temp {
  color: white;
  font-size: 74px;
  line-height: .9;
  font-weight: 900;
  letter-spacing: 0;
}

.degree,
.mode-readout {
  color: #93a6c4;
  font-weight: 800;
}

.mode-readout {
  font-size: 14px;
}

.temp-actions {
  display: grid;
  grid-template-columns: 58px 110px 58px;
  gap: 10px;
  align-items: center;
}

.quick-actions {
  display: grid;
  gap: 14px;
}

.btn {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, .10);
  background: rgba(255, 255, 255, .07);
  color: #eef5ff;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: .16s ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .52;
}

.btn:hover { border-color: rgba(64, 198, 240, .55); }

.btn.active {
  border-color: rgba(64, 198, 240, .75);
  color: white;
  background: rgba(64, 198, 240, .16);
}

.btn.primary {
  background: linear-gradient(135deg, #40c6f0, #0f73e6);
  border-color: rgba(64, 198, 240, .65);
  color: white;
}

.btn.danger {
  color: #ffd7dd;
  border-color: rgba(255, 97, 116, .38);
  background: rgba(255, 97, 116, .10);
}

.power,
.mode-grid,
.wind-grid {
  display: grid;
  gap: 10px;
}

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

.power .btn {
  min-height: 58px;
  font-size: 16px;
}

.control-group {
  padding: 16px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 8px;
}

.label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.mode-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.wind-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.mode-btn,
.wind-btn {
  min-height: 78px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
  padding: 10px 8px;
}

.mode-icon,
.wind-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.mode-btn.active .mode-icon,
.wind-btn.active .wind-icon {
  color: white;
  background: linear-gradient(135deg, #40c6f0, #ec54c1);
}

.mode-btn span:last-child,
.wind-btn span:last-child {
  font-size: 13px;
  line-height: 1.1;
}

.temp-pill {
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .10);
  background: rgba(255, 255, 255, .07);
  color: white;
  font-size: 22px;
  font-weight: 850;
}

.lucide {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.toast-host {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 100;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  background: rgba(13, 20, 35, .94);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .34);
  color: white;
  animation: toast-in .18s ease-out;
  backdrop-filter: blur(16px);
}

.toast.success { border-color: rgba(69, 212, 160, .34); }
.toast.error { border-color: rgba(255, 97, 116, .42); }
.toast.warning { border-color: rgba(248, 180, 76, .38); }
.toast.loading { border-color: rgba(64, 198, 240, .34); }

.toast.leaving {
  opacity: 0;
  transform: translateY(-6px);
  transition: .18s ease;
}

.toast-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.toast.success .toast-icon { color: var(--ok); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warn); }
.toast.loading .toast-icon { color: var(--primary); }

.toast-text {
  font-size: 14px;
  font-weight: 750;
  line-height: 1.3;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(64, 198, 240, .22);
  border-top-color: var(--primary);
  animation: spin .74s linear infinite;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-box {
  width: min(440px, 100%);
  background: rgba(12, 18, 32, .90);
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.auth-box p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.auth-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 8px;
  background: linear-gradient(135deg, #40c6f0, #0f73e6);
  color: white;
  text-decoration: none;
  font-weight: 800;
}

.auth-error {
  margin: 16px 0;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 97, 116, .10);
  color: #ff8a99;
  border: 1px solid rgba(255, 97, 116, .38);
  font-size: 14px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .user {
    width: 100%;
    justify-content: space-between;
  }

  .climate-board {
    grid-template-columns: 1fr;
  }

  .remote {
    max-width: none;
  }

  .remote-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .device-grid {
    grid-template-columns: 1fr;
  }

  .temp {
    font-size: 62px;
  }

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

  .toast-host {
    top: 14px;
    right: 16px;
    left: 16px;
    width: auto;
  }
}
