* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --primary: #3b82f6;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #334155;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
header {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 600;
  background: linear-gradient(90deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 2s infinite;
}

.dot.online { background: var(--success); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: #f1f5f9;
}

.card h3 {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin: 16px 0 12px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .row-2 { grid-template-columns: 1fr; }
}

/* Device Grid */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.device-item {
  background: var(--card-2);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.2s;
  border-left: 4px solid var(--danger);
}

.device-item.online { border-left-color: var(--success); }

.device-item .dev-icon { font-size: 1.8rem; }
.device-item .dev-info { flex: 1; }
.device-item .dev-name { font-weight: 600; font-size: 0.9rem; }
.device-item .dev-loc { font-size: 0.75rem; color: var(--text-dim); }
.device-item .dev-status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(239,68,68,0.2);
  color: #fca5a5;
}
.device-item.online .dev-status {
  background: rgba(34,197,94,0.2);
  color: #86efac;
}

/* Sensor Display */
.sensor-display {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.sensor-box {
  padding: 20px;
  border-radius: 12px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.sensor-box.temp { background: linear-gradient(135deg, #dc2626, #991b1b); }
.sensor-box.humi { background: linear-gradient(135deg, #0284c7, #075985); }

.sensor-icon { font-size: 2rem; margin-bottom: 8px; }
.sensor-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: white;
}
.sensor-value small { font-size: 1rem; opacity: 0.8; }
.sensor-label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.8);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Power Grid */
.power-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.power-box {
  background: var(--card-2);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
}

.power-box.highlight {
  background: linear-gradient(135deg, #f59e0b, #b45309);
}

.power-box label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.power-box.highlight label { color: rgba(255,255,255,0.8); }

.power-box div {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f1f5f9;
}

/* Relay Grid */
.relay-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.relay-item {
  background: var(--card-2);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.relay-item.on {
  border-color: var(--warning);
  box-shadow: 0 0 20px rgba(245,158,11,0.3);
}

.relay-info { flex: 1; }
.relay-name {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.relay-status {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
}
.relay-item.on .relay-status { color: var(--warning); }

/* Toggle Switch */
.switch {
  position: relative;
  width: 50px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { display: none; }

.switch .slider {
  position: absolute;
  inset: 0;
  background: #475569;
  border-radius: 26px;
  transition: 0.3s;
  cursor: pointer;
}

.switch .slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: white;
  top: 3px; left: 3px;
  transition: 0.3s;
}

.switch input:checked + .slider {
  background: var(--success);
}
.switch input:checked + .slider::before {
  transform: translateX(24px);
}

/* Door */
.door-visual {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px;
  background: var(--card-2);
  border-radius: 12px;
  margin-bottom: 16px;
}

.door-icon {
  font-size: 4rem;
  transition: all 0.3s;
}

.door-icon.open {
  animation: doorShake 0.5s;
}

@keyframes doorShake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-15deg); }
  75% { transform: rotate(15deg); }
}

.door-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.door-state {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--danger);
  margin-top: 4px;
}
.door-state.open { color: var(--success); }

.door-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Buttons */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  color: white;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-open { background: var(--success); }
.btn-close { background: var(--danger); }
.btn-primary { background: var(--primary); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* Access Log */
.access-log {
  max-height: 180px;
  overflow-y: auto;
}

.log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--card-2);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.log-item .log-info { display: flex; align-items: center; gap: 8px; }
.log-item .badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge.granted { background: rgba(34,197,94,0.2); color: #86efac; }
.badge.denied { background: rgba(239,68,68,0.2); color: #fca5a5; }

/* RFID */
.rfid-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 16px;
}

@media (max-width: 700px) {
  .rfid-form { grid-template-columns: 1fr; }
}

input[type="text"] {
  padding: 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

.rfid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.rfid-item {
  background: var(--card-2);
  padding: 12px 16px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.rfid-item.inactive { opacity: 0.5; }

.rfid-info .rfid-uid {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  color: #60a5fa;
}
.rfid-info .rfid-owner {
  font-size: 0.8rem;
  color: var(--text-dim);
}
.rfid-info .rfid-date {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.rfid-actions {
  display: flex;
  gap: 6px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 14px 24px;
  background: var(--card);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  transform: translateX(400px);
  transition: transform 0.3s;
  z-index: 9999;
  font-size: 0.9rem;
}

.toast.show { transform: translateX(0); }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--card-2); }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

canvas { max-height: 200px; }