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

:root {
  /* --- Primitive Colors --- */
  --ag-color-white: #ffffff;
  --ag-color-black: #000000;

  /* Brand Colors (Premium Teal & Purple) */
  --ag-primary-50: #eff6ff;
  --ag-primary-100: #dbeafe;
  --ag-primary-500: #3b82f6;
  /* Vivid Blue */
  --ag-primary-600: #2563eb;
  --ag-primary-700: #1d4ed8;

  --ag-neutral-50: #f8fafc;
  --ag-neutral-100: #f1f5f9;
  --ag-neutral-200: #e2e8f0;
  --ag-neutral-300: #cbd5e1;
  --ag-neutral-800: #1e293b;
  --ag-neutral-900: #0f172a;

  --ag-success: #10b981;
  --ag-warning: #f59e0b;
  --ag-danger: #ef4444;

  /* --- Semantic Tokens (Light Mode) --- */
  --ag-bg-page: var(--ag-neutral-50);
  --ag-bg-card: rgba(255, 255, 255, 0.9);
  /* Glass effect base */
  --ag-text-main: var(--ag-neutral-900);
  --ag-text-muted: var(--ag-neutral-300);
  --ag-border: var(--ag-neutral-200);

  --ag-primary: var(--ag-primary-600);
  --ag-primary-hover: var(--ag-primary-700);
  --ag-primary-text: var(--ag-color-white);

  /* --- Spacing & Radius --- */
  --ag-radius-sm: 8px;
  --ag-radius-md: 16px;
  --ag-radius-lg: 24px;
  --ag-space-xs: 4px;
  --ag-space-sm: 8px;
  --ag-space-md: 16px;
  --ag-space-lg: 24px;
  --ag-space-xl: 32px;

  /* --- Effects --- */
  --ag-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --ag-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --ag-shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.01);
  --ag-glass: blur(12px) saturate(180%);
  --ag-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Dark Mode Support --- */
@media (prefers-color-scheme: dark) {
  :root {
    --ag-bg-page: #0f172a;
    --ag-bg-card: rgba(30, 41, 59, 0.85);
    /* Dark Glass */
    --ag-text-main: #f8fafc;
    --ag-text-muted: #94a3b8;
    --ag-border: #334155;

    --ag-primary: #3b82f6;
    --ag-primary-hover: #60a5fa;
    --ag-primary-text: #ffffff;
  }
}

/* --- Base --- */
.ag-checkin-container *,
.ag-checkin-container *::before,
.ag-checkin-container *::after {
  box-sizing: border-box;
}

.ag-checkin-container {
  max-width: 600px;
  margin: 0 auto;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ag-text-main);
  padding: var(--ag-space-md);
  position: relative;
}

/* --- Header Row (Greeting + Actions) --- */
.ag-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--ag-space-lg);
  gap: var(--ag-space-md);
}

.ag-greeting h1 {
  color: var(--ag-text-main);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 4px;
}

.ag-greeting p.ag-date {
  color: var(--ag-text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ag-icon-btn {
  background: var(--ag-bg-card);
  border: 1px solid var(--ag-border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--ag-text-main);
  transition: var(--ag-transition);
  text-decoration: none;
  box-shadow: var(--ag-shadow-sm);
}

.ag-icon-btn:hover {
  background: var(--ag-primary);
  color: var(--ag-color-white);
  border-color: transparent;
  transform: translateY(-2px) rotate(5deg);
  box-shadow: var(--ag-shadow-md);
}

/* --- Layout adjustments --- */
.ag-checkin-container {
  margin: 40px auto;
  min-height: 80vh;
}

@media (min-width: 640px) {
  .ag-checkin-container {
    border-radius: var(--ag-radius-lg);
    box-shadow: var(--ag-shadow-lg);
    padding: 50px;
    background: var(--ag-bg-card);
    backdrop-filter: var(--ag-glass);
    border: 1px solid rgba(255, 255, 255, 0.2);
  }

  body {
    background-color: var(--ag-neutral-100);
    background-image:
      radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
      radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
      radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
    background-attachment: fixed;
    background-size: cover;
  }
}

/* Leaves Widget */
.ag-leaves-container .ag-card-header {
  background: var(--ag-primary-50);
}

.ag-leaves-container .ag-card-header h2 {
  color: var(--ag-primary-700);
}

/* Modal Improvements */
.ag-modal-content {
  border-radius: var(--ag-radius-lg);
  box-shadow: var(--ag-shadow-lg);
  padding: var(--ag-space-lg);
  position: relative;
}

.ag-close-modal {
  position: absolute;
  top: 15px;
  right: 15px;
}

/* --- Action Buttons (Tabs) --- */
.ag-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--ag-space-md);
  margin-bottom: var(--ag-space-lg);
}

/* ... keep existing buttons ... */
.ag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ag-space-sm);
  padding: var(--ag-space-md);
  border: none;
  border-radius: var(--ag-radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--ag-transition);
  text-decoration: none;
}

.ag-tab-trigger {
  background: var(--ag-bg-card);
  color: var(--ag-text-main);
  border: 1px solid var(--ag-border);
  box-shadow: var(--ag-shadow-sm);
}

.ag-tab-trigger:hover {
  transform: translateY(-2px);
  box-shadow: var(--ag-shadow-md);
}

.ag-tab-trigger.active {
  background: var(--ag-primary);
  color: var(--ag-primary-text);
  border-color: transparent;
}

/* --- Cards --- */
.ag-card {
  background: var(--ag-bg-card);
  border-radius: var(--ag-radius-md);
  border: 1px solid var(--ag-border);
  box-shadow: var(--ag-shadow-sm);
  overflow: hidden;
  margin-bottom: var(--ag-space-lg);
}

.ag-card-header {
  padding: var(--ag-space-md) var(--ag-space-lg);
  border-bottom: 1px solid var(--ag-border);
  background: rgba(0, 0, 0, 0.02);
}

.ag-card-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ag-text-main);
}

.ag-card-body {
  padding: var(--ag-space-lg);
}

/* --- Forms --- */
.ag-form-group {
  margin-bottom: var(--ag-space-md);
}

.ag-form-label {
  display: block;
  margin-bottom: var(--ag-space-sm);
  font-weight: 500;
  color: var(--ag-text-main);
}

.ag-form-control {
  width: 100%;
  padding: var(--ag-space-md);
  background: var(--ag-bg-page);
  border: 1px solid var(--ag-border);
  border-radius: var(--ag-radius-sm);
  font-size: 1rem;
  color: var(--ag-text-main);
  transition: var(--ag-transition);
}

.ag-form-control:focus {
  outline: none;
  border-color: var(--ag-primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

/* --- Buttons --- */
.ag-btn-primary {
  background: var(--ag-primary);
  color: var(--ag-primary-text);
}

.ag-btn-primary:hover {
  background: var(--ag-primary-hover);
  transform: translateY(-1px);
}

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

.ag-btn-danger:hover {
  background: #dc2626;
}

.ag-btn-secondary {
  background: var(--ag-neutral-200);
  color: var(--ag-text-main);
}

.ag-btn-secondary:hover {
  background: var(--ag-neutral-300);
}

.ag-btn-success {
  background: var(--ag-success);
  color: var(--ag-color-white);
}

.ag-btn-success:hover {
  background: #059669;
  /* darker emerald */
}

.ag-btn-full {
  width: 100%;
}

.ag-mt-4 {
  margin-top: var(--ag-space-md);
}

.ag-mt-8 {
  margin-top: var(--ag-space-xl);
}

/* --- Status Box --- */
.ag-status-box {
  padding: var(--ag-space-md);
  border-radius: var(--ag-radius-sm);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: var(--ag-space-sm);
  margin-bottom: var(--ag-space-md);
}

/* ... keep rest ... */
.ag-status-info {
  background: var(--ag-primary-50);
  color: var(--ag-neutral-900);
  border-left: 4px solid var(--ag-primary-500);
}

@media (prefers-color-scheme: dark) {
  .ag-status-info {
    background: rgba(14, 165, 233, 0.1);
    color: var(--ag-primary);
  }
}

/* --- Loading Spinner --- */
.ag-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ag-spin 0.75s linear infinite;
}

@keyframes ag-spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- QR Reader --- */
.ag-qr-reader {
  width: 100%;
  border-radius: var(--ag-radius-sm);
  overflow: hidden;
  background: #000;
}

/* --- Toast Notifications --- */
.ag-toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.ag-toast {
  background: var(--ag-bg-card);
  color: var(--ag-text-main);
  padding: 16px 20px;
  border-radius: var(--ag-radius-md);
  box-shadow: var(--ag-shadow-lg);
  border-left: 4px solid transparent;
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
}

.ag-toast.show {
  opacity: 1;
  transform: translateX(0);
}

.ag-toast-success {
  border-left-color: var(--ag-success);
}

.ag-toast-error {
  border-left-color: var(--ag-danger);
}

.ag-toast-info {
  border-left-color: var(--ag-primary);
}

/* --- Modal --- */
.ag-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.ag-modal.hidden {
  display: none;
}

.ag-modal-content {
  background: var(--ag-bg-card);
  width: 90%;
  max-width: 400px;
  padding: 30px;
  border-radius: var(--ag-radius-lg);
  box-shadow: var(--ag-shadow-lg);
  position: relative;
  /* animation: ag-fade-in 0.2s ease-out; */
}

.ag-close-modal {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ag-text-muted);
  cursor: pointer;
}

/* ... continue ... */
.ag-text-muted {
  color: var(--ag-text-muted);
}

/* --- Table --- */
.ag-table-responsive {
  overflow-x: auto;
  border-radius: var(--ag-radius-sm);
  border: 1px solid var(--ag-border);
}

.ag-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.ag-table th {
  background: var(--ag-bg-page);
  padding: var(--ag-space-md);
  font-weight: 600;
  border-bottom: 2px solid var(--ag-border);
  white-space: nowrap;
}

.ag-table td {
  padding: var(--ag-space-md);
  border-bottom: 1px solid var(--ag-border);
}

/* --- Active Session --- */
.ag-card-active {
  border: 2px solid var(--ag-success);
}

.ag-session-header {
  display: flex;
  align-items: center;
  gap: var(--ag-space-sm);
  margin-bottom: var(--ag-space-lg);
}

.ag-pulse-indicator {
  width: 12px;
  height: 12px;
  background: var(--ag-success);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: ag-pulse 2s infinite;
}

@keyframes ag-pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }

  70% {
    transform: scale(1);
    box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
  }

  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.ag-session-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--ag-space-md);
  background: var(--ag-bg-page);
  padding: var(--ag-space-md);
  border-radius: var(--ag-radius-md);
}

.ag-stat-item {
  display: flex;
  flex-direction: column;
}

.ag-stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ag-text-muted);
  margin-bottom: 4px;
}

.ag-stat-value {
  font-weight: 600;
  font-size: 1.1rem;
}

/* --- Helpers --- */
.hidden {
  display: none !important;
}

.ag-text-center {
  text-align: center;
}

.ag-badge-paused {
  background: var(--ag-warning);
  color: var(--ag-color-white);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8em;
  vertical-align: middle;
}

.ag-text-success {
  color: var(--ag-success);
}

.ag-font-bold {
  font-weight: 700;
}

/* Mobile Optimization */
@media (max-width: 480px) {
  .ag-actions {
    grid-template-columns: 1fr;
  }

  .ag-session-details {
    grid-template-columns: 1fr;
  }

  .ag-stat-item {
    padding: var(--ag-space-sm) 0;
    border-bottom: 1px solid var(--ag-border);
  }

  /* --- Auth UI --- */
  /* Main wrapper is .ag-checkin-container, so we target that or .ag-card inside it */
  .ag-checkin-container {
    padding: var(--ag-space-md);
    margin: 10px auto;
  }

  .ag-auth-tabs {
    display: flex;
    margin-bottom: var(--ag-space-md);
  }

  .ag-auth-tab {
    flex: 1;
    padding: var(--ag-space-md);
    font-size: 0.95rem;
    text-align: center;
  }

  .ag-auth-tab:hover {
    background: var(--ag-neutral-50);
  }

  .ag-auth-content {
    display: none;
    animation: ag-fade-in 0.3s ease-out;
  }

  .ag-auth-content.active {
    display: block;
  }

  @keyframes ag-fade-in {
    from {
      opacity: 0;
      transform: translateY(5px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  #ag-message-success,
  #ag-login-message {
    margin-top: 10px;
    font-size: 0.9em;
  }

  .ag-text-danger {
    color: var(--ag-danger);
  }

  .ag-text-success {
    color: var(--ag-success);
  }
}