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

:root {
  --bg-main: #0a0e17;
  --bg-card: #131a2a;
  --bg-card-hover: #1a233a;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(59, 130, 246, 0.4);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;

  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, .brand-title {
  font-family: 'Outfit', sans-serif;
}

/* Glassmorphism & Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(19, 26, 42, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #ef4444, #f97316);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.4);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #93c5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.brand-badge.admin {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.brand-badge.client {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Main Container */
.main-content {
  flex: 1;
  padding: 1.25rem;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
}

/* Landing Portal Page */
.portal-hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
  max-width: 600px;
  margin: 0 auto;
}

.portal-hero h1 {
  font-size: 2.2rem;
  margin-bottom: 0.75rem;
  font-weight: 800;
}

.portal-hero p {
  color: var(--text-secondary);
  font-size: 1rem;
}

.role-selector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  max-width: 720px;
  margin: 2rem auto;
}

.role-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-card);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.role-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-highlight);
  box-shadow: 0 15px 30px -5px rgba(59, 130, 246, 0.3);
}

.role-card .icon-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
  font-size: 2rem;
}

.role-card.admin .icon-circle {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.role-card.client .icon-circle {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.role-card h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.role-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.role-card .btn-role {
  margin-top: auto;
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.role-card:hover .btn-role {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: white;
}

/* Admin Layout */
.admin-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  height: calc(100vh - 110px);
}

@media (max-width: 992px) {
  .admin-grid {
    grid-template-columns: 1fr;
    height: auto;
  }
}

/* Admin Sidebar */
.admin-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Master Control Switch */
.master-control {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.7), rgba(15, 23, 42, 0.8));
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.control-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
}

.control-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

/* Switch Toggle Component */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #334155;
  transition: .3s;
  border-radius: 26px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-green);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-blue);
  color: white;
}

.btn-primary:hover {
  background: #2563eb;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.5);
}

.btn-danger {
  background: var(--accent-red);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.6);
}

.btn-secondary {
  background: #334155;
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #475569;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

/* Device List Cards */
.device-item {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  margin-bottom: 0.75rem;
  transition: all 0.2s;
}

.device-item:hover {
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(15, 23, 42, 0.8);
}

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.device-name {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.offline {
  background: var(--text-muted);
}

.device-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.device-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Map Container */
.map-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  height: 100%;
  min-height: 480px;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 450px;
  background: #0d131f;
  z-index: 1;
}

.map-overlay-status {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* SOS Alert Banner Modal */
.sos-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.sos-banner.active {
  display: flex;
  animation: alertPulse 1.5s infinite alternate;
}

@keyframes alertPulse {
  0% { background: rgba(153, 27, 27, 0.85); }
  100% { background: rgba(69, 10, 10, 0.9); }
}

.sos-modal-content {
  background: #1e1b2e;
  border: 2px solid var(--accent-red);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 0 50px rgba(239, 68, 68, 0.6);
}

.sos-pulse-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.2);
  border: 2px solid var(--accent-red);
  color: var(--accent-red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin: 0 auto 1.5rem;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Client Mobile Page */
.client-container {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.identity-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
}

.select-identity {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1rem;
  margin-top: 0.5rem;
  outline: none;
}

.status-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.25rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.tracking-indicator {
  width: 110px;
  height: 110px;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  transition: all 0.5s ease;
}

.tracking-indicator.active {
  background: rgba(16, 185, 129, 0.15);
  border: 2px solid var(--accent-green);
  color: var(--accent-green);
  animation: radarPulse 2s infinite;
}

.tracking-indicator.standby {
  background: rgba(100, 116, 139, 0.15);
  border: 2px dashed var(--text-muted);
  color: var(--text-muted);
}

@keyframes radarPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  70% { box-shadow: 0 0 0 25px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.status-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.status-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Big SOS Panic Button on Mobile */
.sos-button-container {
  margin: 0.5rem 0;
  text-align: center;
}

.btn-sos-big {
  width: 100%;
  padding: 1.5rem 1rem;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: white;
  border-radius: var(--radius-lg);
  border: 2px solid rgba(255, 255, 255, 0.2);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(239, 68, 68, 0.4);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-sos-big:active {
  transform: scale(0.96);
  box-shadow: 0 5px 15px rgba(239, 68, 68, 0.6);
}

.btn-sos-sub {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.9;
  letter-spacing: normal;
}

/* Info Badges (Battery, GPS Accuracy) */
.metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
}

.metric-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-lbl {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Custom Marker styles for Leaflet */
.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: white;
  font-weight: 700;
  font-size: 12px;
  box-shadow: 0 0 12px rgba(0,0,0,0.5);
  border: 2px solid white;
}
.marker-istri { background: #ec4899; }
.marker-anak { background: #3b82f6; }
.marker-sos { background: #ef4444; animation: pulse 1s infinite; }
