/* Eight Monmouth Dashboard */
:root {
  --bg: #08080e;
  --surface: #111119;
  --card: #181824;
  --card-hover: #1e1e2e;
  --border: #2a2a3a;
  --primary: #4f8fff;
  --primary-hover: #3a7aee;
  --primary-dim: rgba(79, 143, 255, 0.12);
  --danger: #ff4f5e;
  --danger-hover: #e63e4c;
  --danger-dim: rgba(255, 79, 94, 0.12);
  --success: #34d399;
  --success-dim: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-dim: rgba(251, 191, 36, 0.12);
  --text: #e2e2ea;
  --text-muted: #787890;
  --text-dim: #50506a;
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }

/* ── Login ─────────────────────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, rgba(79,143,255,0.06) 0%, transparent 70%);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 380px;
  max-width: 90vw;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 20px;
}

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--card);
  color: var(--text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-block { width: 100%; }

.btn-icon {
  padding: 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { color: var(--text); background: var(--card); }

/* ── Layout ────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100%;
}

.sidebar {
  grid-row: 1 / -1;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand span {
  color: var(--primary);
  margin-right: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.nav-section {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 16px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}

.nav-item:hover {
  background: var(--card);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-dim);
  color: var(--primary);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-dim);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-email {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

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

.main {
  padding: 24px 28px;
  overflow-y: auto;
  background: var(--bg);
}

/* ── Mobile sidebar toggle ─────────────────────── */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

/* ── Cards ─────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Grid Layouts ──────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── Status Badge ──────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-success { background: var(--success-dim); color: var(--success); }
.badge-warning { background: var(--warning-dim); color: var(--warning); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }
.badge-info { background: var(--primary-dim); color: var(--primary); }

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

/* ── Stat Cards ────────────────────────────────── */
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -1px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Camera Grid ───────────────────────────────── */
.cam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.cam-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}

.cam-card:hover { border-color: var(--primary); }

.cam-thumb {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
}

.cam-thumb img, .cam-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cam-thumb .cam-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 12px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.cam-label {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.cam-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse 2s infinite;
}

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

.cam-actions {
  padding: 10px 12px;
  display: flex;
  gap: 8px;
}

/* ── Camera Modal (fullscreen player) ──────────── */
.cam-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cam-modal-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  z-index: 1;
}

.cam-modal-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

.cam-modal-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.cam-modal-close:hover { background: rgba(255,255,255,0.2); }

.cam-modal video, .cam-modal img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: var(--radius);
}

.cam-modal-controls {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

/* ── TV Section ────────────────────────────────── */
.tv-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
}

.tv-preview {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tv-preview .placeholder {
  color: var(--text-dim);
  font-size: 14px;
}

.tv-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Appliance Cards ───────────────────────────── */
.appliance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.appliance-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.appliance-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.appliance-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.appliance-icon.oven { background: var(--danger-dim); }
.appliance-icon.cooling { background: var(--primary-dim); }

.appliance-name {
  font-size: 16px;
  font-weight: 600;
}

.appliance-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.appliance-props {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.prop {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.prop-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.prop-value {
  font-size: 15px;
  font-weight: 600;
}

.appliance-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Schedule Exceptions ───────────────────────── */
.exception-list {
  margin-top: 16px;
}

.exception-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.exception-info {
  font-size: 13px;
}

.exception-date {
  font-weight: 500;
}

.exception-type {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Modal ─────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 420px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Loading & Empty States ────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.error-msg {
  background: var(--danger-dim);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

.success-msg {
  background: var(--success-dim);
  color: var(--success);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Section headers ───────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ── Misc utilities ────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ── Zone Editor ──────────────────────────────── */
.zones-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 20px;
}

.zones-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.zones-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.zones-cam-select {
  width: auto;
  min-width: 140px;
}

.zones-canvas-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.zones-canvas-wrap canvas {
  display: block;
  width: 100%;
}

.zones-drawing-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: var(--text);
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}

.zones-drawing-hint:empty { display: none; }

.zones-threshold {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}

.zones-threshold label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.zones-threshold input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
  padding: 0;
  border: none;
  background: transparent;
}

.zones-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  align-self: start;
}

.zones-panel-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.zone-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 4px;
}

.zone-item:hover { background: var(--surface); }

.zone-item-selected {
  background: var(--primary-dim) !important;
}

.zone-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.zone-item-label {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.zone-item-pts {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 800;
    left: -260px;
    top: 0;
    bottom: 0;
    width: 260px;
    transition: left 0.25s;
  }

  .sidebar.open { left: 0; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 799;
  }

  .menu-toggle { display: block; }

  .cam-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .tv-layout { grid-template-columns: 1fr; }
  .zones-layout { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .main { padding: 16px; }
  .login-card { padding: 28px 24px; }
  .appliance-props { grid-template-columns: 1fr; }
}
