/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
  --sidebar-bg:       #0f172a;
  --sidebar-hover:    #1e293b;
  --sidebar-active:   #2563eb;
  --sidebar-text:     #94a3b8;
  --sidebar-text-act: #ffffff;
  --sidebar-width:    240px;

  --bg:               #f1f5f9;
  --card-bg:          #ffffff;
  --border:           #e2e8f0;
  --border-focus:     #2563eb;

  --primary:          #2563eb;
  --primary-dark:     #1d4ed8;
  --primary-light:    #eff6ff;
  --success:          #16a34a;
  --success-light:    #f0fdf4;
  --danger:           #dc2626;
  --danger-light:     #fef2f2;
  --warning:          #d97706;
  --warning-light:    #fffbeb;
  --muted:            #64748b;

  --text:             #0f172a;
  --text-secondary:   #475569;

  --radius:           8px;
  --radius-sm:        6px;
  --radius-lg:        12px;
  --shadow:           0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

  --transition:       150ms ease;
  --font:             'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
img { display: block; max-width: 100%; }

/* ── App Shell ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid #1e293b;
}
.sidebar-brand svg { flex-shrink: 0; }
.sidebar-brand-text { color: #fff; font-weight: 700; font-size: .95rem; line-height: 1.3; }
.sidebar-brand-sub  { color: var(--sidebar-text); font-size: .7rem; font-weight: 400; }

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}
.sidebar-nav-label {
  color: #475569;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 12px 10px 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.nav-link:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}
.nav-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-act);
}
.nav-link svg { flex-shrink: 0; opacity: .8; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--sidebar-active);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .875rem;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta-name { color: #e2e8f0; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta-role { color: var(--sidebar-text); font-size: .7rem; }
.logout-btn {
  color: var(--sidebar-text);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  display: flex;
}
.logout-btn:hover { color: #ef4444; background: rgba(239,68,68,.1); }

/* ── Content Wrapper ────────────────────────────────────────────────────────── */
.content-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ────────────────────────────────────────────────────────────────── */
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
  flex: 1;
}
.mobile-toggle {
  display: none;
  padding: 6px;
  color: var(--muted);
}

.mqtt-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.mqtt-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  transition: background .3s;
}
.mqtt-dot.connected  { background: var(--success); box-shadow: 0 0 0 2px rgba(22,163,74,.2); }
.mqtt-dot.connecting { background: var(--warning); animation: pulse 1.2s infinite; }
.mqtt-dot.error      { background: var(--danger); }

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

/* ── Main Content ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 28px;
}

/* ── Panels ─────────────────────────────────────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.panel-header h2 { font-size: 1.25rem; font-weight: 700; }

/* ── Stat Cards ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; color: var(--primary); }
.stat-icon.green  { background: #f0fdf4; color: var(--success); }
.stat-icon.orange { background: #fff7ed; color: #ea580c; }
.stat-icon.purple { background: #faf5ff; color: #7c3aed; }
.stat-label { font-size: .78rem; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text); line-height: 1.1; margin-top: 2px; }

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

/* ── Device Card ────────────────────────────────────────────────────────────── */
.device-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.device-card:hover { box-shadow: var(--shadow-md); }

.device-card-header {
  padding: 16px 18px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-location { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.device-token { font-size: .68rem; color: #94a3b8; font-family: monospace; margin-top: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-online  { background: var(--success-light); color: var(--success); }
.badge-online::before  { background: var(--success); }
.badge-offline { background: #f1f5f9; color: var(--muted); }
.badge-offline::before { background: #94a3b8; }

.device-card-controls {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

/* Multi-output rows / WiFi motor controls */
.device-outputs {
  border-bottom: 1px solid var(--border);
  max-height: 360px;
  overflow-y: auto;
}
.device-outputs.motor-controls {
  max-height: none;
}
.output-all-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: var(--surface-2, #f8fafc);
  border-bottom: 2px solid var(--border);
}
.output-all-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  flex: 1;
}
.output-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.output-row:last-child { border-bottom: none; }
.output-row.motor-row {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.06), transparent);
  padding: 14px 18px;
}
.output-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  width: 32px;
  flex-shrink: 0;
}
.output-label.motor-label {
  width: 88px;
  font-size: .82rem;
  color: var(--text, #0f172a);
}
.output-actions { margin-left: auto; display: flex; gap: 6px; }
.output-row.motor-row .output-actions .btn { min-width: 72px; }
.output-row.pulse-row {
  padding: 6px 18px 10px;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.03), transparent);
}
.pulse-actions { align-items: center; }
.pulse-input {
  width: 58px;
  padding: 4px 8px;
  font-size: .82rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  text-align: center;
}
.pulse-unit { font-size: .75rem; color: var(--muted); }
.btn-xs { padding: 2px 10px; font-size: .75rem; }
.state-label { font-size: .78rem; color: var(--muted); font-weight: 500; flex: 1; }
.state-value { font-weight: 700; font-size: .9rem; }
.state-value.on      { color: var(--success); }
.state-value.off     { color: var(--muted); }
.state-value.sending { color: var(--warning); }
.state-value.failed  { color: var(--danger); }
.state-value.unknown { color: #94a3b8; }

.device-card-sensors {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.sensor-item { }
.sensor-label { font-size: .68rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.sensor-value { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-top: 1px; }
.sensor-unit  { font-size: .7rem; color: var(--muted); font-weight: 400; }
.sensor-placeholder { color: #cbd5e1; font-size: .85rem; font-style: italic; }

.device-card-footer {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.device-actions { display: flex; gap: 8px; }
.last-seen { font-size: .68rem; color: #94a3b8; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 600;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

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

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

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

.btn-ghost    { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: #e2e8f0; }

.btn-sm { padding: 5px 10px; font-size: .75rem; }
.btn-icon { padding: 6px; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .855rem; }
thead tr { background: var(--bg); }
th {
  text-align: left;
  padding: 11px 16px;
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-badge.admin { background: #ede9fe; color: #6d28d9; }
.role-badge.user  { background: #eff6ff; color: #1d4ed8; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.active   { background: var(--success); }
.status-dot.inactive { background: #94a3b8; }

/* ── Forms & Modals ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0,0,0,.2);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in .15s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close {
  color: var(--muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body   { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 5px; color: var(--text-secondary); }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: .875rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-control::placeholder { color: #94a3b8; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Empty & Error States ───────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state svg { margin: 0 auto 14px; opacity: .3; }
.empty-state h3 { font-size: 1rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.empty-state p  { font-size: .85rem; }

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: .83rem;
  font-weight: 500;
  margin-bottom: 16px;
}
.alert-error   { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: #14532d; border: 1px solid #bbf7d0; }

/* ── Toast Notifications ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: .83rem;
  font-weight: 500;
  color: #fff;
  max-width: 320px;
  animation: slide-in .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: none; }
}

/* ── Loading ────────────────────────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: 20px;
}
.loading-brand { color: #fff; font-weight: 800; font-size: 1.4rem; }
.loading-brand span { color: var(--primary); }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Settings Panel ─────────────────────────────────────────────────────────── */
.settings-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  max-width: 480px;
}
.settings-card-header { padding: 18px 24px; border-bottom: 1px solid var(--border); }
.settings-card-header h3 { font-weight: 700; font-size: .95rem; }
.settings-card-body { padding: 24px; }

/* ── Login Page ─────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0,0,0,.4);
  overflow: hidden;
}
.login-header {
  background: var(--primary);
  padding: 32px 32px 28px;
  text-align: center;
  color: #fff;
}
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.login-logo-text { font-weight: 800; font-size: 1.25rem; }
.login-tagline { font-size: .8rem; opacity: .85; }
.login-body { padding: 32px; }
.login-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 6px; }
.login-subtitle { font-size: .82rem; color: var(--muted); margin-bottom: 24px; }

/* ── Utility ────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted  { color: var(--muted); }
.text-sm     { font-size: .8rem; }
.text-center { text-align: center; }
.fw-600      { font-weight: 600; }
.mt-4  { margin-top:    16px; }
.mb-4  { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ── Device Assignment Checkbox List ───────────────────────────────────────── */
.assign-device-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.assign-device-item:hover { background: var(--bg); }
.assign-device-item.checked { background: var(--primary-light); border-color: var(--primary); }
.assign-device-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.assign-device-info { flex: 1; min-width: 0; }
.assign-device-name { font-weight: 600; font-size: .875rem; }
.assign-device-meta { font-size: .72rem; color: var(--muted); font-family: monospace; margin-top: 1px; }

/* ── Schedule Components ───────────────────────────────────────────────────── */
.schedule-type-tabs {
  display: flex;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.schedule-type-tab {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  transition: all var(--transition);
}
.schedule-type-tab.active {
  background: var(--card-bg);
  color: var(--primary);
  box-shadow: var(--shadow);
}
.schedule-type-tab:hover:not(.active) { color: var(--text); }

.day-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.day-pill {
  width: 44px;
  height: 36px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.day-pill:hover { border-color: var(--primary); color: var(--primary); }
.day-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.schedule-panel { animation: fade-in .15s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.countdown-input-group { display: flex; gap: 10px; }

.schedules-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.schedule-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius);
}
.schedule-item-detail { flex: 1; min-width: 0; }
.schedule-item-detail .sched-main { font-size: .82rem; font-weight: 600; color: var(--text); }
.schedule-item-detail .sched-sub  { font-size: .72rem; color: var(--muted); margin-top: 1px; }

.sched-cmd {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}
.sched-cmd-on  { background: var(--success-light); color: var(--success); }
.sched-cmd-off { background: var(--danger-light); color: var(--danger); }

.schedule-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

.sched-delete-btn {
  color: var(--muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-shrink: 0;
}
.sched-delete-btn:hover { background: var(--danger-light); color: var(--danger); }

.seq-intro { margin-bottom: 12px; line-height: 1.45; }
.seq-default-row { align-items: flex-end; gap: 8px; }
.seq-relay-header,
.seq-relay-row {
  display: grid;
  grid-template-columns: 48px 56px 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: .75rem;
}
.seq-relay-header {
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.seq-relay-rows {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 10px;
}
.seq-relay-row {
  border-bottom: 1px solid var(--border);
}
.seq-relay-row:last-child { border-bottom: none; }
.seq-relay-row.is-skipped { opacity: .45; }
.seq-relay-row.is-skipped .seq-delay-input { pointer-events: none; background: var(--surface-2, #f1f5f9); }
.seq-relay-name { font-weight: 700; font-size: .82rem; }
.seq-skip-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  cursor: pointer;
}
.sequence-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: .78rem;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--surface-2, #f8fafc);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.sequence-summary strong { color: var(--text); }
.sched-cmd-seq { background: #f0fdf4; color: #15803d; }

.schedules-empty {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: .82rem;
}

.sched-auto-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 10px;
}
.sched-auto-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.sched-auto-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.sched-duration-hint {
  font-size: .7rem;
  color: var(--muted);
  margin-top: -6px;
  margin-bottom: 8px;
  font-style: italic;
}

/* ── Activity Log ──────────────────────────────────────────────────────────── */
.log-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}
.log-type-badge.command        { background: #eff6ff; color: #1d4ed8; }
.log-type-badge.command_result { background: #f0fdf4; color: #16a34a; }
.log-type-badge.command_failed { background: #fef2f2; color: #dc2626; }
.log-type-badge.schedule_create  { background: #faf5ff; color: #7c3aed; }
.log-type-badge.schedule_execute { background: #f0fdf4; color: #16a34a; }
.log-type-badge.schedule_delete  { background: #fff7ed; color: #ea580c; }
.log-type-badge.schedule_failed  { background: #fef2f2; color: #dc2626; }
.log-type-badge.device_online  { background: #f0fdf4; color: #16a34a; }
.log-type-badge.device_offline { background: #f1f5f9; color: #64748b; }
.log-type-badge.login          { background: #eff6ff; color: #1d4ed8; }
.log-type-badge.logout         { background: #f1f5f9; color: #64748b; }
.log-type-badge.user_action    { background: #fff7ed; color: #ea580c; }

.log-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  font-weight: 600;
}
.log-status.ok     { color: var(--success); }
.log-status.failed { color: var(--danger); }
.log-status.pending { color: var(--warning); }

.log-details {
  font-size: .78rem;
  color: var(--text-secondary);
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-time {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
}

.log-device {
  font-weight: 600;
  font-size: .82rem;
}
.log-device-token {
  font-size: .68rem;
  color: #94a3b8;
  font-family: monospace;
}

.log-user {
  font-weight: 600;
  font-size: .82rem;
}
.log-user-role {
  font-size: .68rem;
  color: var(--muted);
}

/* ── Device Filter Toolbar ──────────────────────────────────────────────────── */
.device-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.device-search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.device-search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}
.device-search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  font-size: .82rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.device-search-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  font-size: .82rem;
  color: var(--text);
  min-width: 130px;
}
.filter-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.device-count-label {
  font-size: .8rem;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .content-wrapper { margin-left: 0; }
  .mobile-toggle { display: flex; }
  .topbar { padding: 0 16px; }
  .main-content { padding: 16px; }
  .devices-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
