:root {
  --success: #10b981;
  --warning: #f59e0b;
  --neutral: #94a3b8;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f3fbfa 0%, #eef4fb 55%, #f6f3fb 100%);
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ================= BACKGROUND ORBS ================= */
.bg-effects {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}
.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.35;
  animation: float 22s infinite alternate ease-in-out;
}
.orb-1 { width: 420px; height: 420px; background: #60a5fa; top: -120px; left: -100px; }
.orb-2 { width: 480px; height: 480px; background: #a78bfa; bottom: -150px; right: -100px; animation-delay: -6s; }
.orb-3 { width: 320px; height: 320px; background: #2dd4bf; top: 40%; left: 45%; animation-delay: -12s; opacity: 0.25; }
@keyframes float {
  0% { transform: translate(0,0) scale(1); }
  100% { transform: translate(60px, 40px) scale(1.12); }
}

/* ================= GLASS PANEL ================= */
.glass-panel {
  background: rgba(255,255,255,0.62);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 8px 32px rgba(15,118,110,0.10);
}
.glass-panel h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #0f172a;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; gap: 12px; flex-wrap: wrap; }
.panel-header h2 { margin-bottom: 0; }

/* ================= LOGIN SCREEN ================= */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2.25rem 2rem;
  animation: rise 0.5s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 8px 20px rgba(13,148,136,0.35);
}
.input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.8);
  border: 1px solid rgba(15,118,110,0.15);
  border-radius: 10px;
  padding: 0 12px;
  transition: border-color .2s, box-shadow .2s;
}
.input-wrap:focus-within {
  border-color: #0d9488;
  box-shadow: 0 0 0 3px rgba(13,148,136,0.15);
}
.input-wrap i { color: #64748b; font-size: 1.1rem; }
.input-wrap input {
  border: none;
  background: transparent;
  outline: none;
  padding: 11px 4px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.92rem;
  color: #0f172a;
  width: 100%;
}
.login-error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--danger);
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
}

/* ================= APP SHELL ================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255,255,255,0.7);
  padding: 2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}
.brand-icon {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 6px 14px rgba(13,148,136,0.3);
}
.nav-links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  padding: 11px 14px;
  border-radius: 10px;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.92rem;
  transition: all 0.2s ease;
}
.nav-item i { font-size: 1.1rem; }
.nav-item:hover { background: rgba(13,148,136,0.08); color: #0f766e; }
.nav-item.active {
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: white;
  box-shadow: 0 6px 16px rgba(13,148,136,0.3);
}
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px;
  background: rgba(15,118,110,0.06);
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(13,148,136,0.15); color: #0f766e;
  display: flex; align-items: center; justify-content: center;
}
.logout-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; border-radius: 10px;
  background: rgba(239,68,68,0.08);
  color: #dc2626;
  font-weight: 500; font-size: 0.85rem;
}
.logout-btn:hover { background: rgba(239,68,68,0.16); }

/* Content */
.content {
  flex: 1;
  padding: 2rem 2.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  min-width: 0;
}
header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
header h1 { font-size: 1.6rem; font-weight: 600; margin: 0; color: #0f172a; }
header p { color: #64748b; margin: 4px 0 0; font-size: 0.9rem; }
.status-indicator {
  display: flex; align-items: center; gap: 8px;
  background: rgba(16,185,129,0.1); color: #059669;
  padding: 8px 16px; border-radius: 99px;
  font-size: 0.85rem; font-weight: 500;
  border: 1px solid rgba(16,185,129,0.25);
}
.pulse {
  width: 8px; height: 8px; background: var(--success); border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.7);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.7); }
  70% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* Grid Layout */
.grid-container { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.span-full { grid-column: 1 / -1; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 1rem; }

/* Scroll list */
.scroll-container { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 6px; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(15,118,110,0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(15,118,110,0.35); }

/* Cards */
.card {
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(15,118,110,0.1);
  border-radius: 14px;
  padding: 1rem;
  transition: transform 0.2s, background 0.2s, box-shadow .2s;
}
.card:hover { background: rgba(255,255,255,0.85); transform: translateY(-2px); box-shadow: 0 10px 24px rgba(15,118,110,0.12); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; gap: 8px; }
.card-title { font-weight: 600; font-size: 1rem; color: #0f172a; }
.card-details { font-size: 0.82rem; color: #64748b; display: flex; flex-direction: column; gap: 5px; font-family: 'IBM Plex Mono', monospace; }
.card-details b { color: #0f172a; }

/* Patient card actions */
.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(15,23,42,0.06);
}

/* Device card w/ gauge */
.device-card { display: flex; gap: 10px; align-items: center; position: relative; }
.device-card .device-body { flex: 1; min-width: 0; }
.assign-btn {
  align-self: flex-start;
  background: rgba(13,148,136,0.08);
  color: #0f766e;
}
.assign-btn:hover { background: rgba(13,148,136,0.18); color: #0f766e; }
.gauge {
  --pct: 0;
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--gauge-color, #0d9488) calc(var(--pct)*1%), rgba(15,23,42,0.08) 0);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.gauge::before {
  content: '';
  position: absolute; inset: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
}
.gauge span {
  position: relative; z-index: 1;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem; font-weight: 600; color: #0f172a;
}

/* Badges */
.badge { padding: 4px 9px; border-radius: 6px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.badge.online { background: rgba(16,185,129,0.15); color: #059669; }
.badge.dispensing { background: rgba(245,158,11,0.15); color: #b45309; }
.badge.idle { background: rgba(148,163,184,0.2); color: #475569; }
.badge.tuntas { background: rgba(16,185,129,0.15); color: #059669; }
.badge.pending { background: rgba(13,148,136,0.15); color: #0f766e; }
.badge.bolos { background: rgba(239,68,68,0.15); color: #dc2626; }

/* Chart */
.chart-wrap { position: relative; height: 280px; }

/* Table */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid rgba(15,23,42,0.06); font-size: 0.88rem; }
th { color: #64748b; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
td { font-family: 'IBM Plex Mono', monospace; color: #1e293b; }
td strong { font-family: 'Poppins', sans-serif; }
tbody tr { transition: background 0.2s; }
tbody tr:hover { background: rgba(15,118,110,0.04); }

/* Buttons */
button { cursor: pointer; border: none; outline: none; font-family: 'Poppins', sans-serif; font-size: 0.88rem; font-weight: 500; border-radius: 10px; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-primary { background: linear-gradient(135deg, #0d9488, #14b8a6); color: white; padding: 9px 16px; box-shadow: 0 6px 16px rgba(13,148,136,0.25); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(13,148,136,0.4); transform: translateY(-1px); }
.btn-secondary { background: rgba(15,23,42,0.06); color: #334155; padding: 9px 16px; }
.btn-secondary:hover { background: rgba(15,23,42,0.1); }
.btn-icon { background: transparent; color: #64748b; padding: 6px; font-size: 1.05rem; border-radius: 8px; }
.btn-icon:hover { color: #0f172a; background: rgba(15,23,42,0.06); }
.btn-icon.delete:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.35);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
  padding: 1.5rem;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-content { width: 100%; max-width: 440px; transform: translateY(16px); transition: transform 0.3s; }
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.4rem; }
.modal-header h3 { font-size: 1.1rem; margin: 0; }
.btn-close { background: transparent; color: #64748b; font-size: 1.1rem; padding: 4px; }
.btn-close:hover { color: #0f172a; }

/* Forms */
.form-group { margin-bottom: 1.1rem; display: flex; flex-direction: column; gap: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
label { font-size: 0.8rem; color: #64748b; font-weight: 500; }
input, select {
  background: rgba(255,255,255,0.75);
  border: 1px solid rgba(15,23,42,0.1);
  color: #0f172a;
  padding: 10px 12px;
  border-radius: 9px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
input:focus, select:focus { outline: none; border-color: #0d9488; box-shadow: 0 0 0 3px rgba(13,148,136,0.12); }
option { background: white; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 1.8rem; }

.text-center { text-align: center; }
.loading { color: #94a3b8; font-style: italic; }

/* Responsive */
@media (max-width: 980px) {
  .grid-container { grid-template-columns: 1fr; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; padding: 1rem 1.25rem; gap: 1rem; }
  .nav-links { flex-direction: row; flex: 1; overflow-x: auto; }
  .sidebar-footer { flex-direction: row; margin-top: 0; }
  .content { padding: 1.5rem; }
}