@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-color: #0a0f1e;
  --bg-panel: rgba(22, 33, 62, 0.75);
  --bg-panel-hover: rgba(30, 45, 80, 0.85);
  --text-main: #f0f4ff;
  --text-muted: #7b8bb2;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.2);
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(99, 102, 241, 0.3);
  --glass-blur: blur(16px);
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body.dark-theme {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  background-image:
    radial-gradient(ellipse at 10% 0%, rgba(99, 102, 241, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 100%, rgba(34, 197, 94, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(139, 92, 246, 0.05) 0%, transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }
.text-green { color: var(--success) !important; }
.text-red { color: var(--danger) !important; }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-muted); }
.small-text { font-size: 0.82rem; }
.full-width { width: 100%; }

/* ── Glass Panel ── */
.glass-panel {
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

/* ── Auth Overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.4s ease;
}
.auth-panel {
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.auth-logo {
  margin-bottom: 25px;
}
.auth-icon {
  font-size: 48px;
  margin-bottom: 10px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}
.auth-logo h2 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.auth-step-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 15px;
}
.auth-panel input {
  width: 100%;
  padding: 14px 16px;
  margin: 8px 0;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
}
.auth-panel input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.otp-input {
  text-align: center;
  font-size: 1.8rem !important;
  letter-spacing: 12px;
  font-weight: 700;
}
.separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 15px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.separator::before,
.separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.error-msg {
  color: var(--danger);
  margin-top: 12px;
  font-size: 0.88rem;
  font-weight: 500;
}

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

.sidebar {
  width: 260px;
  min-width: 260px;
  border-radius: 0;
  border-left: none;
  border-top: none;
  border-bottom: none;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.logo h2 {
  font-size: 1.2rem;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--success);
}
.pulse-dot.active {
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.nav-links {
  list-style: none;
  flex-grow: 1;
  padding: 8px 0;
}
.nav-links li {
  padding: 11px 14px;
  margin-bottom: 3px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.nav-links li:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}
.nav-links li.active {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.nav-icon { font-size: 1.1rem; }
.notif-badge {
  position: absolute;
  right: 10px;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding-top: 15px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.devices-indicator {
  text-align: center;
}

.content {
  flex-grow: 1;
  padding: 30px;
  overflow-y: auto;
  max-height: 100vh;
}

section { display: none; }
section.active {
  display: block;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

section > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
section > header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.status-badge {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.status-badge.live {
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ── KPIs ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.kpi-card {
  transition: var(--transition);
}
.kpi-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-2px);
}
.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}
.kpi-value {
  font-size: 2rem;
  margin-top: 6px;
  font-weight: 700;
}

/* ── Chart ── */
.chart-container {
  height: 380px;
  position: relative;
}

/* ── Tables ── */
.table-container {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
th {
  color: var(--text-muted);
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
td {
  padding: 13px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.9rem;
}
tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ── Buttons ── */
.btn {
  padding: 11px 22px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn.secondary {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
  border: 1px solid var(--border-accent);
}
.btn.danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn.danger:hover {
  background: rgba(239, 68, 68, 0.25);
}
.btn.outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn.outline:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.15);
}

/* ── Chat ── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px);
  max-height: 700px;
}
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}
.suggestion {
  font-size: 0.8rem !important;
  padding: 7px 14px !important;
  white-space: nowrap;
}
.suggestion:hover {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}
.chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 15px 5px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeIn 0.25s ease;
}
.msg.agent { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
}
.msg.user .msg-avatar { background: var(--accent-glow); }

.msg-content {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 0.92rem;
}
.msg-content strong {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.msg.agent .msg-content {
  background: rgba(255, 255, 255, 0.04);
  border-top-left-radius: 4px;
}
.msg.user .msg-content {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  border-top-right-radius: 4px;
}
.msg.user .msg-content strong { color: rgba(255,255,255,0.7); }

.chat-input-area {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-area input {
  flex-grow: 1;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-family: 'Inter', sans-serif;
  font-size: 0.92rem;
  transition: var(--transition);
}
.chat-input-area input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.chat-input-area .btn {
  padding: 13px 18px;
}

/* ── Typing indicator ── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Notifications ── */
.notifications-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.notif-item {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  transition: var(--transition);
  cursor: pointer;
  align-items: flex-start;
}
.notif-item:hover {
  border-color: var(--border-accent);
  background: var(--bg-panel-hover);
}
.notif-item.unread {
  border-left: 3px solid var(--accent);
}
.notif-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.notif-body { flex-grow: 1; }
.notif-body h4 {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 3px;
}
.notif-body p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.notif-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Config ── */
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.form-group input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  transition: var(--transition);
}
.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Devices ── */
.devices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.device-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.device-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.device-icon { font-size: 1.5rem; }
.device-details h4 { font-size: 0.88rem; }
.device-details p { font-size: 0.75rem; color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 768px) {
  #app-container { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    position: static;
    border-radius: 0;
  }
  .nav-links {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding: 5px 0;
  }
  .nav-links li { white-space: nowrap; font-size: 0.82rem; }
  .sidebar-footer { display: none; }
  .content { padding: 15px; max-height: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .config-grid { grid-template-columns: 1fr; }
  .chat-container { height: calc(100vh - 200px); }
}
