:root {
  --bg: #0A0A0B;
  --card: #141416;
  --border: #232326;
  --text: #EDEDEF;
  --text-secondary: #8A8A8F;
  --accent: #6366F1;
  --accent-hover: #5253d6;
  --accent-glow: rgba(99, 102, 241, 0.08);
  --green: #22C55E;
  --red: #EF4444;
  --yellow: #EAB308;
  --orange: #F97316;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

.bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(99,102,241,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99,102,241,.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center top, black 0%, transparent 70%);
  pointer-events: none; z-index: 0;
}

.header-glow {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 800px; height: 400px;
  background: radial-gradient(ellipse at center top, var(--accent-glow) 0%, transparent 60%);
  pointer-events: none; z-index: 0;
}

.shell { max-width: 960px; margin: 0 auto; padding: 2rem 1.25rem 3rem; position: relative; z-index: 1; }

.top-bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text-secondary); text-decoration: none; font-size: 0.85rem; transition: color 0.2s; }
.back-link:hover { color: var(--accent); }
.back-link svg { width: 16px; height: 16px; }

.status-badge { display: flex; align-items: center; gap: 0.5rem; background: var(--card); border: 1px solid var(--border); padding: 0.45rem 0.875rem; border-radius: 999px; font-size: 0.75rem; color: var(--text-secondary); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-secondary); }
.dot.online { background: var(--green); animation: pulse 2s ease-in-out infinite; }
.dot.offline { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }

header { text-align: center; margin-bottom: 1.5rem; }
.header-icon { width: 56px; height: 56px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 0.75rem; color: var(--yellow); }
.header-icon svg { width: 28px; height: 28px; }
header h1 { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em; }
header .sub { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.25rem; }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.65rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem; }
.stat-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 0.25rem; }
.stat-value { font-size: 1.2rem; font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.15rem; margin-bottom: 0.85rem; }
.card-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 0.85rem; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.card-title svg { width: 14px; height: 14px; }

.master { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.master-label { font-weight: 600; font-size: 0.95rem; }
.master-btns { display: flex; gap: 0.5rem; }

.btn { background: var(--bg); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 0.82rem; font-weight: 500; padding: 0.6rem 1rem; border-radius: 10px; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; gap: 0.35rem; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); color: #fff; }
.btn.green { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.3); color: var(--green); }
.btn.red { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.25); color: var(--red); }
.btn.sm { padding: 0.4rem 0.7rem; font-size: 0.75rem; }

.scenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 0.55rem; }
.scene { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem 0.5rem; text-align: center; cursor: pointer; transition: all 0.15s; font-size: 0.78rem; color: var(--text-secondary); }
.scene:hover { border-color: var(--accent); color: var(--text); transform: translateY(-1px); }
.scene .icon { font-size: 1.35rem; display: block; margin-bottom: 0.25rem; }

.light { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 0.65rem; }
.light-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.85rem; }
.light-name { font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 0.45rem; }
.light-dot { width: 8px; height: 8px; border-radius: 50%; background: #3a3a3f; }
.light-dot.on { background: var(--green); box-shadow: 0 0 8px rgba(34,197,94,.5); }

.toggle { position: relative; width: 48px; height: 26px; background: var(--border); border-radius: 999px; cursor: pointer; border: none; padding: 0; transition: background 0.2s; }
.toggle.on { background: var(--accent); }
.toggle .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.2s; }
.toggle.on .knob { transform: translateX(22px); }

.slider-row { margin-bottom: 0.75rem; }
.slider-row label { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.slider-row label .val { color: var(--text); font-weight: 500; }
input[type=range] { width: 100%; appearance: none; height: 5px; border-radius: 99px; background: var(--border); outline: none; }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid var(--bg); }

.color-row { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.color-row label { font-size: 0.75rem; color: var(--text-secondary); }
input[type=color] { width: 40px; height: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; padding: 2px; }
.presets { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: transform 0.1s; }
.swatch:hover { transform: scale(1.1); border-color: #fff; }

.tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tab { background: transparent; border: 1px solid transparent; color: var(--text-secondary); font-family: inherit; font-size: 0.78rem; font-weight: 500; padding: 0.4rem 0.75rem; border-radius: 999px; cursor: pointer; }
.tab:hover { color: var(--text); background: var(--card); }
.tab.active { background: rgba(99,102,241,.15); border-color: rgba(99,102,241,.3); color: #C7D2FE; }

.panel { display: none; }
.panel.active { display: block; }

.schedule-list { display: flex; flex-direction: column; gap: 0.5rem; }
.schedule-item { display: flex; align-items: center; gap: 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 0.875rem; }
.schedule-item.disabled { opacity: 0.5; }
.schedule-time { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); min-width: 52px; }
.schedule-info { flex: 1; min-width: 0; }
.schedule-info h4 { font-size: 0.85rem; font-weight: 600; }
.schedule-info p { font-size: 0.72rem; color: var(--text-secondary); margin-top: 0.1rem; }
.schedule-actions { display: flex; gap: 0.35rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 0.72rem; color: var(--text-secondary); }
.form-group input, .form-group select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.65rem; color: var(--text); font-family: inherit; font-size: 0.85rem; outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }

.days-row { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.day-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-secondary); font-family: inherit;
  font-size: 0.68rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.day-btn.active { background: rgba(99,102,241,.15); border-color: var(--accent); color: #C7D2FE; }

.config-grid { display: grid; gap: 0.75rem; }
.config-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.config-row:last-child { border-bottom: none; }
.config-row label { font-size: 0.85rem; }
.config-row span { font-size: 0.75rem; color: var(--text-secondary); display: block; margin-top: 0.1rem; }
.config-row input, .config-row select { width: 140px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem 0.6rem; color: var(--text); font-family: inherit; font-size: 0.82rem; }

.switch { position: relative; width: 44px; height: 24px; background: var(--border); border-radius: 999px; cursor: pointer; border: none; padding: 0; }
.switch.on { background: var(--accent); }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.2s; }
.switch.on .knob { transform: translateX(20px); }

.activity-list { display: flex; flex-direction: column; gap: 0.45rem; max-height: 220px; overflow-y: auto; }
.activity-item { font-size: 0.75rem; color: var(--text-secondary); padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-item strong { color: var(--text); font-weight: 500; }
.activity-time { font-size: 0.65rem; color: #555; margin-top: 0.1rem; }

.empty { text-align: center; padding: 1.5rem; color: var(--text-secondary); font-size: 0.82rem; }

.alert { padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.85rem; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.25); color: #FCA5A5; display: none; }
.alert.show { display: block; }

.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 0.7rem 1.1rem; font-size: 0.85rem; z-index: 200; opacity: 0; transform: translateY(10px); transition: all 0.3s; pointer-events: none; }
.toast.visible { opacity: 1; transform: translateY(0); }

footer { margin-top: 2rem; padding-top: 1.25rem; border-top: 1px solid var(--border); text-align: center; font-size: 0.65rem; color: #555; text-transform: uppercase; letter-spacing: 0.04em; }

@media (max-width: 640px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
