* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #ef4444;
  --primary-hover: #dc2626;
  --bg-dark: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222222;
  --bg-elevated: #252525;
  --text: #ffffff;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: #2a2a2a;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
  --gradient-1: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
  --gradient-2: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --gradient-3: linear-gradient(135deg, #22c55e 0%, #14b8a6 100%);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Screen Management */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hidden {
  display: none !important;
}

/* ==================== LOGIN SCREEN ==================== */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
}

.login-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 1000px;
  width: 100%;
  min-height: 600px;
  margin: 20px;
  background: var(--bg-card);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-left {
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  background: var(--gradient-1);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.login-card h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-hint {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.code-input-wrapper {
  position: relative;
  margin-bottom: 24px;
}

#access-code {
  width: 100%;
  padding: 16px 20px;
  font-size: 1.5rem;
  font-weight: 600;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.5em;
  text-align: center;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  outline: none;
  transition: all 0.2s;
  text-transform: uppercase;
}

#access-code:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15);
}

#access-code::placeholder {
  color: var(--text-muted);
  letter-spacing: 0.3em;
}

.btn-login {
  width: 100%;
  padding: 16px 24px;
  background: var(--gradient-1);
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
}

.btn-login:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 40px -10px rgba(239, 68, 68, 0.5);
}

.btn-login:active {
  transform: translateY(0);
}

.btn-arrow {
  width: 20px;
  height: 20px;
  transition: transform 0.2s;
}

.btn-login:hover .btn-arrow {
  transform: translateX(4px);
}

.btn-loader .spinner {
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-message {
  margin-top: 16px;
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 0.875rem;
  text-align: center;
}

.login-footer {
  margin-top: 32px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.login-right {
  background: linear-gradient(135deg, #1f1f1f 0%, #0f0f0f 100%);
  padding: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--border);
}

.feature-showcase {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: all 0.3s;
}

.feature-item:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(8px);
}

.feature-icon {
  font-size: 2rem;
}

.feature-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.feature-text strong {
  font-weight: 600;
}

.feature-text span {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ==================== DASHBOARD SCREEN ==================== */
#dashboard-screen {
  min-height: 100vh;
  background: var(--bg-dark);
}

.dashboard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.nav-icon {
  width: 32px;
  height: 32px;
  background: var(--gradient-1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  color: white;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-logout svg {
  width: 18px;
  height: 18px;
}

.dashboard-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.dashboard-header {
  margin-bottom: 32px;
}

.dashboard-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.header-subtitle {
  color: var(--text-secondary);
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
}

.stat-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.stat-icon-bg {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon-bg svg {
  width: 24px;
  height: 24px;
}

.stat-alerts .stat-icon-bg {
  background: rgba(239, 68, 68, 0.15);
  color: var(--primary);
}

.stat-photos .stat-icon-bg {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
}

.stat-locations .stat-icon-bg {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

/* Alerts Container */
.alerts-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.alerts-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.alerts-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.alerts-list {
  max-height: 500px;
  overflow-y: auto;
}

.alert-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}

.alert-item:last-child {
  border-bottom: none;
}

.alert-item:hover {
  background: var(--bg-elevated);
}

.alert-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.alert-icon.wrong-pin {
  background: rgba(239, 68, 68, 0.15);
}

.alert-icon.motion {
  background: rgba(245, 158, 11, 0.15);
}

.alert-thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.alert-info {
  flex: 1;
  min-width: 0;
}

.alert-type {
  font-weight: 500;
  margin-bottom: 2px;
}

.alert-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.alert-badges {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.badge.has-photo {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
}

.badge.has-location {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.125rem;
  margin-bottom: 4px;
}

.empty-state p {
  color: var(--text-muted);
}

/* ==================== MODAL ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 10;
}

.modal-close:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

#modal-body {
  padding: 24px;
}

.modal-header {
  margin-bottom: 20px;
  padding-right: 40px;
}

.modal-header h3 {
  font-size: 1.25rem;
  margin-bottom: 4px;
}

.modal-time {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.modal-photo {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 20px;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.map-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(59, 130, 246, 0.15);
  border-radius: 10px;
  color: var(--info);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.map-link:hover {
  background: rgba(59, 130, 246, 0.25);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
  .login-container {
    grid-template-columns: 1fr;
    max-width: 400px;
  }

  .login-right {
    display: none;
  }

  .login-left {
    padding: 32px 24px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 16px 20px;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .alert-item {
    padding: 12px 16px;
  }

  .alert-badges {
    display: none;
  }

  .btn-logout span {
    display: none;
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
