    :root {
      --tuya: #ff5a1f;
      --bg: #f4f4f7;
      --card: #ffffff;
      --muted: #7a7a85;
      --text: #2e2e33;
      --line: #e7e7ee;
      --ok: #16a34a;
      --warn: #d97706;
      --err: #dc2626;
      --shadow: 0 12px 35px rgba(0, 0, 0, 0.08);
      --radius: 28px;
    }

    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    .hidden {
      display: none !important;
    }

    .toast-container {
      position: fixed;
      top: 24px;
      right: 24px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      z-index: 9999;
    }

    .toast {
      padding: 14px 20px;
      border-radius: 16px;
      font-size: 14px;
      font-weight: 700;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
      animation: toastIn 0.3s forwards;
      opacity: 0;
      transform: translateX(100%);
      max-width: 320px;
    }

    .toast.hide {
      animation: toastOut 0.3s ease-in forwards;
    }

    .toast.ok {
      background: #f0fff4;
      color: #166534;
      border: 1px solid #86efac;
    }

    .toast.err {
      background: #fff1f0;
      color: #cf1322;
      border: 1px solid #ffa39e;
    }

    @keyframes toastIn {
      to {
        opacity: 1;
        transform: translateX(0);
      }
    }

    @keyframes toastOut {
      to {
        opacity: 0;
        transform: translateX(100%);
      }
    }

    .center-screen {
      min-height: 100vh;
      display: grid;
      place-items: center;
      padding: 24px;
    }

    .auth-wrap {
      width: 100%;
      max-width: 440px;
      background: var(--card);
      border-radius: 30px;
      box-shadow: var(--shadow);
      padding: 34px 28px;
    }

    .logo {
      text-align: center;
      color: var(--tuya);
      font-size: 42px;
      font-weight: 800;
      margin: 0 0 6px;
    }

    .subtitle {
      text-align: center;
      color: var(--muted);
      margin: 0 0 28px;
      line-height: 1.4;
    }

    .tabs {
      display: flex;
      gap: 8px;
      margin-bottom: 22px;
      background: #f7f7fb;
      border-radius: 16px;
      padding: 6px;
    }

    .tab {
      flex: 1;
      border: 0;
      background: transparent;
      border-radius: 12px;
      padding: 12px 14px;
      font-weight: 700;
      cursor: pointer;
    }

    .tab.active {
      background: white;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
      color: var(--tuya);
    }

    .field label {
      display: block;
      font-size: 13px;
      font-weight: 700;
      margin-bottom: 7px;
      color: #5d5d67;
    }

    .field input,
    .field select {
      width: 100%;
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: 14px 15px;
      font-size: 15px;
      background: white;
      outline: none;
    }

    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      border: 0;
      border-radius: 18px;
      padding: 14px 18px;
      cursor: pointer;
      font-weight: 800;
      font-size: 15px;
      text-decoration: none;
      transition: all 0.2s;
    }

    .btn:active {
      transform: scale(0.96);
    }

    .btn-tuya {
      background: var(--tuya);
      color: #fff;
      box-shadow: 0 10px 20px rgba(255, 90, 31, 0.2);
    }

    .btn-tuya:hover {
      background: #e8521a;
    }

    .btn-secondary {
      background: #fff;
      color: #333;
      border: 1px solid var(--line);
    }

    .btn-danger {
      background: #fff1f2;
      color: #be123c;
      border: 1px solid #fecdd3;
    }

    .btn-small {
      padding: 10px 14px;
      border-radius: 14px;
      font-size: 13px;
    }

    .full {
      width: 100%;
    }

    #appScreen {
      display: none;
      min-height: 100vh;
    }

    header {
      background: #fff;
      padding: 18px 28px;
      border-bottom: 3px solid var(--tuya);
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: sticky;
      top: 0;
      z-index: 100;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    }

    header h1 {
      margin: 0;
      font-size: 26px;
      color: var(--tuya);
      font-weight: 900;
    }

    .user-pill {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 6px 16px;
      background: #fdfdfd;
      border-radius: 40px;
      cursor: pointer;
      border: 1px solid var(--line);
      transition: all 0.2s;
    }

    .user-pill:hover {
      background: #fff;
      border-color: var(--tuya);
      box-shadow: 0 4px 12px rgba(255, 90, 31, 0.1);
    }

    .avatar-thumb {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      object-fit: cover;
      border: 2px solid #fff;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    }

    .layout {
      padding: 28px;
      max-width: 1500px;
      margin: 0 auto;
    }

    .toolbar {
      display: flex;
      gap: 14px;
      margin-bottom: 28px;
      flex-wrap: wrap;
      align-items: center;
    }

    .toolbar .field {
      flex: 1 1 320px;
    }

    .grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
      gap: 24px;
    }

    .device {
      background: #fff;
      border-radius: var(--radius);
      padding: 24px;
      box-shadow: var(--shadow);
      cursor: pointer;
      transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
      position: relative;
      border: 1px solid transparent;
      display: flex;
      flex-direction: column;
      gap: 18px;
    }

    .device:hover {
      transform: translateY(-6px);
      box-shadow: 0 20px 45px rgba(0, 0, 0, 0.12);
    }

    .device.is-on {
      background: linear-gradient(135deg, #fff, #fffaf5);
      border-color: #ffd6ad;
    }

    .device-top {
      display: flex;
      gap: 16px;
      align-items: center;
    }

    .icon {
      width: 68px;
      height: 68px;
      border-radius: 20px;
      background: #f8f8fb;
      display: grid;
      place-items: center;
      border: 1px solid var(--line);
      flex-shrink: 0;
      transition: all 0.3s;
    }

    .icon img {
      width: 54px;
      height: 54px;
      object-fit: contain;
    }

    .device.is-on .icon {
      background: #fff0eb;
      border-color: var(--tuya);
      box-shadow: 0 0 20px rgba(255, 90, 31, 0.15);
    }

    .device-info {
      flex: 1;
      min-width: 0;
    }

    .device-name {
      margin: 0;
      font-size: 17px;
      font-weight: 800;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: var(--text);
    }

    .device-cat {
      font-size: 12px;
      color: var(--muted);
      margin-top: 4px;
      font-weight: 600;
      text-transform: uppercase;
    }

    .device-params {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 4px;
    }

    .param-pill {
      padding: 5px 12px;
      border-radius: 99px;
      background: #f1f1f6;
      font-size: 13px;
      font-weight: 700;
      color: #52525b;
      display: flex;
      align-items: center;
      gap: 5px;
    }

    .param-pill.accent {
      background: #fff1eb;
      color: var(--tuya);
    }

    .device-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: auto;
      padding-top: 14px;
      border-top: 1px solid var(--line);
    }

    .online-blob {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      display: inline-block;
      margin-right: 6px;
    }

    .modal-bg {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.55);
      display: none;
      place-items: center;
      padding: 20px;
      z-index: 2000;
      backdrop-filter: blur(4px);
    }

    .modal-card {
      background: #fff;
      width: 100%;
      max-width: 540px;
      border-radius: 36px;
      padding: 34px;
      position: relative;
      animation: modalIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes modalIn {
      from {
        opacity: 0;
        transform: translateY(15px) scale(0.98);
      }

      to {
        opacity: 1;
        transform: translateY(0) scale(1);
      }
    }

    .close-modal {
      position: absolute;
      top: 22px;
      right: 22px;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: #f1f1f5;
      display: grid;
      place-items: center;
      cursor: pointer;
      color: var(--muted);
      font-size: 24px;
      transition: all 0.2s;
    }

    .close-modal:hover {
      background: #eaeaef;
      color: var(--text);
    }

    /* Gauge styles */
    .gauge-container {
      position: relative;
      width: 340px;
      height: 340px;
      margin: 10px auto;
    }

    .gauge-svg {
      width: 100%;
      height: 100%;
      transform: rotate(-225deg);
    }

    .gauge-bg {
      fill: none;
      stroke: #f0f0f5;
      stroke-width: 20;
      stroke-linecap: round;
    }

    .gauge-value {
      fill: none;
      stroke: var(--tuya);
      stroke-width: 22;
      stroke-linecap: round;
      transition: stroke-dashoffset 0.6s cubic-bezier(0.16, 1, 0.3, 1);
      filter: drop-shadow(0 0 8px rgba(255, 90, 31, 0.25));
    }

    .gauge-center {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      pointer-events: none;
    }

    .gauge-center .val {
      font-size: 88px;
      font-weight: 900;
      line-height: 1;
      letter-spacing: -4px;
      color: var(--text);
    }

    .gauge-center .label {
      font-size: 15px;
      font-weight: 700;
      color: var(--muted);
      text-transform: uppercase;
      margin-top: 6px;
      letter-spacing: 1px;
    }

    .panel {
      background: #f8f8fb;
      border-radius: 24px;
      padding: 22px;
      margin-bottom: 22px;
    }

    /* Premium Sliders */
    .control-row {
      margin-bottom: 26px;
      padding: 18px;
      background: #fff;
      border-radius: 20px;
      border: 1px solid #eeeff4;
    }

    .control-label {
      display: flex;
      justify-content: space-between;
      margin-bottom: 14px;
      font-weight: 800;
      font-size: 14px;
      color: var(--text);
    }

    .control-label span {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 16px;
    }

    .slider {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 12px;
      border-radius: 10px;
      background: #f0f0f5;
      outline: none;
      transition: all 0.2s;
      position: relative;
    }

    /* Brightness Gradient */
    .slider.bright-slider {
      background: linear-gradient(to right, #444, #f8f8fb 20%, var(--tuya));
    }

    /* Temp Gradient: Warm to Cool */
    .slider.temp-slider {
      background: linear-gradient(to right, #ffcc33, #ffffff, #99ccff);
    }

    .slider::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background: #fff;
      cursor: pointer;
      border: 4px solid var(--tuya);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
      transition: transform 0.2s;
    }

    .slider::-webkit-slider-thumb:hover {
      transform: scale(1.15);
      box-shadow: 0 6px 18px rgba(255, 90, 31, 0.3);
    }

    .generic-list {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      margin-top: 20px;
    }

    .generic-btn {
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: 12px;
      font-weight: 700;
      font-size: 13px;
      text-align: left;
      transition: all 0.2s;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .generic-btn.active {
      border-color: var(--tuya);
      background: #fff9f2;
      color: var(--tuya);
    }

    .generic-btn:hover {
      border-color: var(--tuya);
      transform: translateY(-2px);
    }

    .panel h3 {
      margin: 0 0 16px;
      font-size: 18px;
      font-weight: 800;
    }

    .statline {
      display: flex;
      justify-content: space-between;
      padding: 12px 0;
      border-bottom: 1px solid var(--line);
      font-size: 14px;
      font-weight: 600;
    }

    .statline:last-child {
      border-bottom: 0;
    }

    .badge {
      padding: 6px 12px;
      border-radius: 12px;
      font-size: 12px;
      font-weight: 800;
    }

    .badge.ok {
      background: #dcfce7;
      color: #15803d;
    }

    .badge.err {
      background: #fee2e2;
      color: #b91c1c;
    }

    .badge.warn {
      background: #fef3c7;
      color: #9a3412;
    }

    /* Camera Styles */
    .video-wrap {
      width: 100%;
      border-radius: 24px;
      overflow: hidden;
      background: #000;
      position: relative;
      aspect-ratio: 16/9;
      margin: 0 0 20px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    }

    #videoPlayer {
      width: 100%;
      height: 100%;
      display: block;
    }

    .video-placeholder {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #fff;
      background: #1a1a1e;
      gap: 14px;
    }

    .btn-circle {
      width: 58px;
      height: 58px;
      border-radius: 50%;
      background: #fff;
      border: 1px solid var(--line);
      display: grid;
      place-items: center;
      font-size: 26px;
      font-weight: 600;
      cursor: pointer;
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
      transition: all 0.2s;
    }

    .btn-circle:hover {
      transform: scale(1.08);
      box-shadow: 0 8px 18px rgba(0, 0, 0, 0.1);
      border-color: var(--tuya);
    }

/* FOUC Loader Prevence */
#auth, #appScreen { display: none; }
#globalLoader { position: fixed; inset: 0; display: grid; place-items: center; background: #f4f4f7; z-index: 99999; font-weight: bold; font-size: 18px; color: #ff5a1f; }
.spinner { width: 40px; height: 40px; border: 4px solid #ffebb5; border-top-color: #ff5a1f; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 16px; }
@keyframes spin { 100% { transform: rotate(360deg); } }
