:root {
  --primary-50: #f0f9ff;
  --primary-100: #e0f2fe;
  --primary-200: #bae6fd;
  --primary-300: #7dd3fc;
  --primary-400: #38bdf8;
  --primary-500: #0ea5e9;
  --primary-600: #0284c7;
  --primary-700: #0369a1;
  --primary-800: #075985;
  --primary-900: #0c4a6e;

  --neutral-50: #fafafa;
  --neutral-100: #f5f5f5;
  --neutral-200: #e5e5e5;
  --neutral-300: #d4d4d4;
  --neutral-400: #a3a3a3;
  --neutral-500: #737373;
  --neutral-600: #525252;
  --neutral-700: #404040;
  --neutral-800: #262626;
  --neutral-900: #171717;

  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --info: #3b82f6;
  --info-light: #dbeafe;

  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  color: var(--neutral-800);
  background: linear-gradient(135deg, var(--neutral-50) 0%, var(--neutral-100) 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 120rem;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--neutral-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: var(--transition-base);
}

header:hover {
  box-shadow: var(--shadow-md);
}

.header-left h1 {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--neutral-900);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left h1 i {
  color: var(--primary-600);
  font-size: 1.5rem;
}

.header-left .subtitle {
  color: var(--neutral-500);
  font-size: 0.875rem;
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--neutral-600);
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background-color: var(--success);
  transition: var(--transition-fast);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-dot.offline {
  background-color: var(--error);
  animation: none;
}

#current-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.875rem;
  color: var(--neutral-600);
  padding: 0.5rem 1rem;
  background: var(--neutral-50);
  border-radius: var(--radius-md);
  border: 1px solid var(--neutral-200);
}

.btn-logout {
  background: var(--neutral-200);
  color: var(--neutral-700);
}

.btn-logout:hover {
  background: var(--error);
  color: white;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--neutral-200);
  margin-bottom: 2rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 0 0.5rem;
  box-shadow: var(--shadow-sm);
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 1rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--neutral-500);
  white-space: nowrap;
  transition: var(--transition-base);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tab-btn:hover {
  color: var(--neutral-700);
  background: var(--neutral-50);
}

.tab-btn.active {
  color: var(--primary-600);
  border-bottom-color: var(--primary-600);
  background: var(--primary-50);
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--neutral-200);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-500), var(--primary-300));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.card-span-2 {
  grid-column: span 2;
}

.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--neutral-200);
  gap: 1rem;
}

.card-title h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--neutral-900);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title h3 i {
  color: var(--primary-500);
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 260px;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.hint {
  color: var(--neutral-500);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--neutral-700);
}

.form-actions label {
  opacity: 0;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  background: white;
  color: var(--neutral-800);
  transition: var(--transition-base);
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.textarea {
  min-height: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.4;
  resize: vertical;
}

.info-box {
  background: var(--primary-50);
  border: 1px solid var(--primary-200);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  transition: var(--transition-base);
}

.info-box:hover {
  background: var(--primary-100);
  border-color: var(--primary-300);
}

.info-box i {
  color: var(--primary-500);
  font-size: 1.25rem;
  margin-top: 0.125rem;
  flex-shrink: 0;
}

.info-box p {
  font-size: 0.875rem;
  color: var(--neutral-700);
  line-height: 1.5;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  background: var(--primary-600);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-base);
  text-decoration: none;
  line-height: 1;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: currentColor;
  opacity: 0;
  transition: var(--transition-base);
}

.btn:hover::before {
  opacity: 0.1;
}

.btn:active {
  transform: scale(0.98);
}

.btn:hover {
  background: var(--primary-700);
  box-shadow: 0 4px 6px -1px rgba(14, 165, 233, 0.2);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.btn-danger {
  background: var(--error);
}

.btn-danger:hover {
  background: rgb(220, 38, 38);
  box-shadow: 0 4px 6px -1px rgba(220, 38, 38, 0.2);
}

.btn-success {
  background: var(--success);
}

.btn-success:hover {
  background: rgb(5, 150, 105);
  box-shadow: 0 4px 6px -1px rgba(5, 150, 105, 0.2);
}

.btn-warning {
  background: var(--warning);
}

.btn-warning:hover {
  background: rgb(217, 119, 6);
  box-shadow: 0 4px 6px -1px rgba(217, 119, 6, 0.2);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.condition-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.conditions {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.condition-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 1rem;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
}

.condition-row .btn-sm {
  justify-self: end;
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
}

.sensor-item {
  background: var(--neutral-50);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  text-align: center;
  border: 1px solid var(--neutral-200);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.sensor-item:hover {
  background: var(--primary-50);
  border-color: var(--primary-200);
  transform: translateY(-2px);
}

.sensor-item::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary-500), var(--primary-300));
  opacity: 0;
  transition: var(--transition-base);
}

.sensor-item:hover::after {
  opacity: 1;
}

.sensor-icon {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--primary-500);
  transition: var(--transition-base);
}

.sensor-item:hover .sensor-icon {
  transform: scale(1.1);
}

.sensor-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--neutral-900);
  margin: 0.5rem 0;
  font-variant-numeric: tabular-nums;
}

.sensor-label {
  font-size: 0.75rem;
  color: var(--neutral-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.sensor-unit {
  font-size: 0.75rem;
  color: var(--neutral-400);
  margin-top: 0.25rem;
}

.relay-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.relay-btn {
  padding: 1rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
  font-size: 0.875rem;
  font-family: inherit;
}

.relay-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: currentColor;
  opacity: 0.1;
  transition: var(--transition-base);
}

.relay-btn:hover::before {
  opacity: 0.2;
}

.relay-btn i {
  font-size: 1.25rem;
  transition: var(--transition-base);
}

.relay-btn:hover i {
  transform: scale(1.1);
}

.relay-btn.on {
  background: var(--success);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}

.relay-btn.off {
  background: var(--neutral-200);
  color: var(--neutral-700);
  box-shadow: var(--shadow-sm);
}

.relay-btn.off:hover {
  background: var(--neutral-300);
  color: var(--neutral-800);
}

.relay-meta {
  font-size: 0.75rem;
  opacity: 0.85;
}

.chart-container {
  height: 320px;
  margin-top: 1rem;
  position: relative;
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--neutral-200);
  padding: 1rem;
}

.video-container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--neutral-200);
  background: var(--neutral-900);
}

.video-container img {
  width: 100%;
  height: auto;
  display: block;
  transition: var(--transition-base);
  min-height: 240px;
  object-fit: contain;
}

.video-container:hover img {
  transform: scale(1.01);
}

.video-overlay {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  backdrop-filter: blur(4px);
}

.alert-list {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.alert-list::-webkit-scrollbar {
  width: 4px;
}

.alert-list::-webkit-scrollbar-track {
  background: var(--neutral-100);
  border-radius: 999px;
}

.alert-list::-webkit-scrollbar-thumb {
  background: var(--neutral-300);
  border-radius: 999px;
}

.alert-item {
  padding: 1rem;
  margin: 0.5rem 0;
  background: var(--neutral-50);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  border: 1px solid var(--neutral-200);
  transition: var(--transition-base);
  animation: slideIn 0.3s ease;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.alert-item:hover {
  background: var(--neutral-100);
  transform: translateX(2px);
}

.alert-item.critical {
  background: rgba(239, 68, 68, 0.05);
  border-left-color: var(--error);
  border-color: rgba(239, 68, 68, 0.2);
}

.alert-item.critical:hover {
  background: rgba(239, 68, 68, 0.1);
}

.alert-item.info {
  border-left-color: var(--info);
}

.alert-item.read {
  opacity: 0.6;
}

.alert-content {
  flex: 1;
}

.alert-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.alert-severity {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.alert-severity.warning {
  background: var(--warning-light);
  color: var(--warning);
}

.alert-severity.critical {
  background: var(--error-light);
  color: var(--error);
}

.alert-severity.info {
  background: var(--info-light);
  color: var(--info);
}

.alert-message {
  color: var(--neutral-700);
}

.alert-time {
  font-size: 0.75rem;
  color: var(--neutral-500);
  margin-top: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.alert-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.alert-actions button {
  background: none;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  color: var(--neutral-500);
  font-size: 0.75rem;
  transition: var(--transition-base);
}

.alert-actions button:hover {
  background: var(--neutral-100);
  color: var(--neutral-700);
}

.kv {
  color: var(--neutral-600);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  white-space: pre-wrap;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 1rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--neutral-200);
  background: white;
}

thead {
  background: var(--neutral-50);
}

th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--neutral-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--neutral-200);
  white-space: nowrap;
}

td {
  padding: 1rem;
  font-size: 0.875rem;
  color: var(--neutral-700);
  border-bottom: 1px solid var(--neutral-200);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: var(--transition-base);
}

tbody tr:hover {
  background: var(--neutral-50);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--neutral-200);
  color: var(--neutral-600);
  font-size: 0.75rem;
  background: var(--neutral-50);
  font-weight: 500;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
  border-color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
  border-color: var(--warning);
}

.badge-error {
  background: var(--error-light);
  color: var(--error);
  border-color: var(--error);
}

.badge-info {
  background: var(--info-light);
  color: var(--info);
  border-color: var(--info);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding: 1rem 0;
}

.pagination button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--neutral-200);
  background: white;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--neutral-600);
  transition: var(--transition-base);
}

.pagination button:hover {
  background: var(--primary-50);
  border-color: var(--primary-200);
  color: var(--primary-600);
}

.pagination button.active {
  background: var(--primary-600);
  color: white;
  border-color: var(--primary-600);
}

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

.pagination .page-info {
  font-size: 0.875rem;
  color: var(--neutral-500);
}

#notification-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 24rem;
  width: 100%;
  pointer-events: none;
}

.notification {
  background: white;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--info);
  animation: slideInRight 0.3s ease;
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  border: 1px solid var(--neutral-200);
  position: relative;
  overflow: hidden;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.notification::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: currentColor;
  opacity: 0.05;
}

.notification i {
  font-size: 1.25rem;
  color: var(--info);
  margin-top: 0.125rem;
}

.notification > div {
  flex: 1;
}

.notification strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--neutral-900);
  margin-bottom: 0.25rem;
}

.notification small {
  display: block;
  font-size: 0.75rem;
  color: var(--neutral-600);
  line-height: 1.4;
}

.notification button {
  background: none;
  border: none;
  color: var(--neutral-400);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-base);
  align-self: flex-start;
  font-size: 0.75rem;
}

.notification button:hover {
  color: var(--neutral-600);
  background: var(--neutral-100);
}

.notification.success {
  border-left-color: var(--success);
}

.notification.success i {
  color: var(--success);
}

.notification.error {
  border-left-color: var(--error);
}

.notification.error i {
  color: var(--error);
}

.notification.warning {
  border-left-color: var(--warning);
}

.notification.warning i {
  color: var(--warning);
}

.recordings {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.recording-item {
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--neutral-200);
  transition: var(--transition-base);
  background: white;
}

.recording-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.recording-item img,
.recording-item video {
  width: 100%;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: block;
}

.recording-item .recording-info {
  padding: 0.75rem;
  font-size: 0.75rem;
  color: var(--neutral-600);
}

.recording-item .recording-actions {
  padding: 0 0.75rem 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--neutral-400);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state p {
  font-size: 0.875rem;
}

.ai-floating-button {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
  z-index: 10000;
  transition: all 0.3s ease;
  user-select: none;
  border: none;
  padding: 0;
}

.ai-floating-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6);
}

.ai-floating-button .ai-logo-img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
}

.ai-chat-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 380px;
  height: 520px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--neutral-200);
  display: none;
  flex-direction: column;
  z-index: 10001;
  overflow: hidden;
}

.ai-chat-window.active {
  display: flex;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-chat-header {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: white;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.ai-chat-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-400), var(--primary-300));
}

.ai-chat-header h3 {
  margin: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat-header .ai-logo-header {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.ai-chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  padding: 5px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background: var(--neutral-50);
}

.ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: var(--neutral-100);
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--neutral-300);
  border-radius: 3px;
}

.ai-message {
  margin-bottom: 15px;
  display: flex;
  gap: 10px;
}

.ai-message.user {
  flex-direction: row-reverse;
}

.ai-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.ai-message.user .ai-message-avatar {
  background: var(--primary-500);
  color: white;
}

.ai-message.assistant .ai-message-avatar {
  background: var(--success);
  color: white;
}

.ai-message-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.ai-message.user .ai-message-content {
  background: var(--primary-500);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.ai-message.assistant .ai-message-content {
  background: white;
  color: var(--neutral-800);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--neutral-200);
}

.ai-message.loading .ai-message-content {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--neutral-500);
}

.ai-message.loading .ai-message-content::after {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--neutral-400);
  border-radius: 50%;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.ai-thinking-section {
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.08) 0%, rgba(16, 185, 129, 0.08) 100%);
  border: 1px solid rgba(14, 165, 233, 0.25);
}

.ai-thinking-header {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--primary-600);
  font-weight: 600;
  user-select: none;
  transition: background 0.2s;
  background: rgba(14, 165, 233, 0.1);
}

.ai-thinking-header:hover {
  background: rgba(14, 165, 233, 0.15);
}

.ai-thinking-header .thinking-arrow {
  margin-left: auto;
  font-size: 11px;
  transition: transform 0.2s;
  color: var(--primary-500);
}

.ai-thinking-header .thinking-arrow.collapsed {
  transform: rotate(-90deg);
}

.ai-thinking-content {
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--neutral-600);
  border-top: 1px solid rgba(14, 165, 233, 0.15);
  background: rgba(255, 255, 255, 0.5);
  max-height: 300px;
  overflow-y: auto;
  word-break: break-word;
}

.ai-thinking-content::-webkit-scrollbar {
  width: 4px;
}

.ai-thinking-content::-webkit-scrollbar-track {
  background: transparent;
}

.ai-thinking-content::-webkit-scrollbar-thumb {
  background: rgba(14, 165, 233, 0.3);
  border-radius: 2px;
}

.ai-thinking-text {
  white-space: pre-wrap;
}

.ai-response {
  line-height: 1.6;
}

.ai-response p {
  margin: 0 0 8px 0;
}

.ai-response p:last-child {
  margin-bottom: 0;
}

.ai-response ul, .ai-response ol {
  margin: 8px 0;
  padding-left: 20px;
}

.ai-response code {
  background: var(--neutral-100);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.ai-response pre {
  background: var(--neutral-100);
  padding: 12px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 8px 0;
}

.ai-response pre code {
  background: none;
  padding: 0;
}

.ai-response table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12px;
}

.ai-response th, .ai-response td {
  border: 1px solid var(--neutral-200);
  padding: 6px 10px;
  text-align: left;
}

.ai-response th {
  background: var(--neutral-50);
  font-weight: 600;
}

.ai-command-action {
  margin-top: 12px;
  padding: 12px;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
}

.ai-command-action .confirm-message {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--neutral-700);
}

.ai-command-action .action-buttons {
  display: flex;
  gap: 8px;
}

.ai-command-action .executing {
  color: var(--primary-500);
  font-size: 14px;
}

.ai-command-action .execute-result {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.ai-command-action .execute-result.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.ai-command-action .execute-result.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
}

.ai-command-action .execute-cancelled {
  color: var(--neutral-500);
  font-size: 14px;
  font-style: italic;
}

.ai-chat-input-area {
  padding: 15px;
  background: white;
  border-top: 1px solid var(--neutral-200);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-chat-input-area textarea {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid var(--neutral-300);
  border-radius: 20px;
  resize: none;
  font-size: 14px;
  font-family: inherit;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s;
}

.ai-chat-input-area textarea:focus {
  border-color: var(--primary-500);
}

.ai-chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.ai-chat-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.ai-chat-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.scheduled-task-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  transition: var(--transition-base);
}

.scheduled-task-item:hover {
  background: var(--neutral-100);
  transform: translateX(2px);
}

.task-info {
  flex: 1;
}

.task-name {
  font-weight: 600;
  color: var(--neutral-900);
  margin-bottom: 0.25rem;
}

.task-detail {
  font-size: 0.875rem;
  color: var(--neutral-500);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.task-detail span {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.task-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.rule-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  transition: var(--transition-base);
}

.rule-item:hover {
  background: var(--neutral-100);
  transform: translateX(2px);
}

.rule-item.inactive {
  opacity: 0.6;
}

.rule-info {
  flex: 1;
}

.rule-name {
  font-weight: 600;
  color: var(--neutral-900);
  margin-bottom: 0.25rem;
}

.rule-condition {
  font-size: 0.875rem;
  color: var(--neutral-500);
}

.rule-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.ota-upload-area {
  border: 2px dashed var(--neutral-300);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition-base);
  background: var(--neutral-50);
}

.ota-upload-area:hover {
  border-color: var(--primary-400);
  background: var(--primary-50);
}

.ota-upload-area i {
  font-size: 2rem;
  color: var(--neutral-400);
  margin-bottom: 0.5rem;
}

.ota-upload-area p {
  color: var(--neutral-500);
  font-size: 0.875rem;
}

.ota-upload-area.dragover {
  border-color: var(--primary-500);
  background: var(--primary-100);
}

.knowledge-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  transition: var(--transition-base);
}

.knowledge-item:hover {
  background: var(--neutral-100);
}

.knowledge-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.knowledge-info i {
  color: var(--primary-500);
}

.knowledge-info .filename {
  font-weight: 500;
  color: var(--neutral-800);
}

.knowledge-info .upload-time {
  font-size: 0.75rem;
  color: var(--neutral-500);
}

.boards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.board-item {
  padding: 1rem;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  text-align: center;
  transition: var(--transition-base);
}

.board-item.online {
  border-color: var(--success);
  background: var(--success-light);
}

.board-item .board-name {
  font-weight: 600;
  color: var(--neutral-900);
  margin-bottom: 0.5rem;
}

.board-item .board-status {
  font-size: 0.75rem;
  color: var(--neutral-500);
}

.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--neutral-200);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-500), var(--primary-300));
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header i {
  font-size: 3rem;
  color: var(--primary-600);
  margin-bottom: 1rem;
  display: block;
}

.login-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--neutral-900);
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--neutral-500);
  font-size: 0.875rem;
}

.login-error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--error-light);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  color: var(--error);
  font-size: 0.875rem;
  text-align: center;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10002;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal-dialog {
  background: white;
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--neutral-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--neutral-900);
}

.modal-close {
  background: none;
  border: none;
  color: var(--neutral-400);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-base);
  font-size: 1rem;
}

.modal-close:hover {
  color: var(--neutral-600);
  background: var(--neutral-100);
}

.modal-body {
  padding: 1.5rem;
  font-size: 0.875rem;
  color: var(--neutral-700);
  line-height: 1.6;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--neutral-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 10003;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}

.loading-spinner {
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--neutral-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

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

.loading-spinner p {
  color: var(--neutral-600);
  font-size: 0.875rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--neutral-700);
  margin-bottom: 1rem;
}

@media (max-width: 980px) {
  .condition-row {
    grid-template-columns: 1fr 1fr;
  }

  .card-span-2 {
    grid-column: 1;
  }

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

  .inline-actions {
    min-width: auto;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  header {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
    padding: 1.5rem;
  }

  .header-right {
    width: 100%;
    justify-content: center;
  }

  .sensor-grid,
  .relay-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab-btn {
    padding: 0.875rem 1rem;
    font-size: 0.75rem;
  }

  .ai-chat-window {
    width: calc(100% - 20px);
    right: 10px;
    bottom: 90px;
    height: 60vh;
  }

  .ai-floating-button {
    right: 20px;
    bottom: 20px;
    width: 50px;
    height: 50px;
  }

  .ai-floating-button .ai-logo-img {
    width: 40px;
    height: 40px;
  }

  .condition-content {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100%;
  }

  .rule-item,
  .scheduled-task-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .rule-actions,
  .task-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .sensor-grid,
  .relay-grid {
    grid-template-columns: 1fr;
  }

  .header-left h1 {
    font-size: 1.5rem;
  }

  .card {
    padding: 1.25rem 1rem;
  }

  .login-card {
    padding: 1.5rem;
  }

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