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

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

:root {
  /* Text */
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;

  /* Backgrounds */
  --bg-primary: #fafaf9;
  --bg-secondary: #f5f5f4;
  --bg-card: #ffffff;

  /* Recency dots */
  --dot-green: #22c55e;
  --dot-yellow: #eab308;
  --dot-orange: #f97316;
  --dot-red: #ef4444;

  /* Accents */
  --accent-available: #22c55e;
  --accent-match: #f59e0b;
  --accent-match-bg: #fef3c7;
  --accent-primary: #2563eb;

  /* States */
  --bg-error: #fef2f2;
  --text-error: #dc2626;
  --bg-success: #f0fdf4;
  --text-success: #16a34a;

  /* Borders */
  --border-light: #e5e5e4;
  --border-focus: #2563eb;

  /* Typography */
  --font-family: 'Nunito', system-ui, sans-serif;
  --font-weight-normal: 400;
  --font-weight-bold: 700;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.75rem;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Corners */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

html, body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--font-weight-normal);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* App shell */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.app-content {
  flex: 1;
  padding: var(--space-4);
  padding-bottom: calc(60px + var(--space-4) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}

/* Screens */
.screen { display: none; }
.screen.active { display: block; }

/* Header */
.header {
  padding: var(--space-4) var(--space-4) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header h1 {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-secondary);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.streak-badge .number {
  font-weight: var(--font-weight-bold);
  font-size: var(--text-lg);
  color: var(--text-primary);
}

/* Available toggle */
/* Availability bar — always visible */
.availability-bar {
  padding: 0 var(--space-4);
  margin-bottom: var(--space-3);
}

.availability-toggle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) 0;
}

/* Toggle switch */
.free-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.free-toggle-track {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--border-light);
  border-radius: 14px;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.free-toggle-track .free-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.free-toggle.active .free-toggle-track {
  background: var(--accent-available);
}

.free-toggle.active .free-toggle-thumb {
  transform: translateX(24px);
}

.free-toggle-label {
  font-family: var(--font-family);
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-secondary);
  transition: color 0.3s ease;
}

.free-toggle.active .free-toggle-label {
  color: var(--accent-available);
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

.free-toggle.active .free-toggle-track {
  animation: pulse-dot 2s infinite;
}

#availability-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.btn-schedule {
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--accent-primary);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
  color: var(--accent-primary);
}

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

/* Schedule for later */
.later-pending {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-success);
  color: var(--text-success);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}

.btn-cancel-later {
  background: none;
  border: none;
  color: var(--text-error);
  font-family: var(--font-family);
  font-size: var(--text-xs);
  cursor: pointer;
  text-decoration: underline;
}

/* Match card */
.match-card {
  background: var(--accent-match-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
  text-align: center;
  margin: var(--space-4) 0;
  animation: matchSlide 0.4s ease;
}

@keyframes matchSlide {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.match-card .match-name {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-1);
}

.match-card .match-context {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-bottom: var(--space-5);
}

.match-actions {
  display: flex;
  gap: var(--space-3);
}

.match-actions .btn-call {
  flex: 1;
  padding: var(--space-3) var(--space-6);
  background: var(--accent-match);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  min-height: 48px;
}

.match-actions .btn-dismiss {
  padding: var(--space-3) var(--space-4);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  cursor: pointer;
  min-height: 48px;
}

/* Group section */
.group-section {
  margin-bottom: var(--space-6);
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
  padding: 0 var(--space-1);
}

.group-header h2 {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
}

.group-health-bar {
  display: flex;
  gap: 2px;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.group-health-bar span {
  flex: 1;
  border-radius: 2px;
}

/* Contact row */
.contact-row {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  min-height: 56px;
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: var(--shadow-sm);
}

.contact-row:active { background: var(--bg-secondary); }

.recency-dot {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  margin-right: var(--space-3);
}

.recency-dot.green { background: var(--dot-green); }
.recency-dot.yellow { background: var(--dot-yellow); }
.recency-dot.orange { background: var(--dot-orange); }
.recency-dot.red { background: var(--dot-red); }

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-weight: var(--font-weight-bold);
  font-size: var(--text-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.available-badge {
  font-size: var(--text-xs);
  color: var(--accent-available);
  font-weight: var(--font-weight-bold);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-success);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.sleep-badge {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
}

/* Floating action button */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  border: none;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 10;
}

.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.45);
}

/* Tab bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

.tab-bar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-family: var(--font-family);
  font-size: var(--text-xs);
  cursor: pointer;
  min-height: 48px;
  justify-content: center;
  transition: color 0.15s;
}

.tab-bar button.active {
  color: var(--accent-primary);
}

.tab-bar button svg {
  width: 24px;
  height: 24px;
  stroke-width: 1.5;
}

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

.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-card);
  min-height: 44px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.btn-primary {
  width: 100%;
  padding: var(--space-3) var(--space-6);
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  min-height: 48px;
  transition: opacity 0.15s;
}

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary:active:not(:disabled) { opacity: 0.8; }

.btn-secondary {
  width: 100%;
  padding: var(--space-3) var(--space-6);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  min-height: 48px;
}

/* Auth screen */
.auth-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  padding: var(--space-8);
  text-align: center;
}

.auth-screen h1 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-2);
}

.auth-screen p {
  color: var(--text-secondary);
  margin-bottom: var(--space-8);
}

.auth-form {
  width: 100%;
  max-width: 320px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-4);
  color: var(--text-secondary);
}

.empty-state h3 {
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state p {
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  padding: var(--space-6);
  max-height: 80dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
}

/* Settings list */
.settings-list {
  list-style: none;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-light);
  min-height: 48px;
}

.settings-item:last-child { border-bottom: none; }

.settings-label {
  font-weight: var(--font-weight-bold);
}

.settings-value {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* Toast */
.toast {
  position: fixed;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--text-primary);
  color: white;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  z-index: 300;
  transition: transform 0.3s ease;
  max-width: calc(100% - var(--space-8));
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Invite screen */
.invite-form { margin-top: var(--space-4); }
.invite-sent {
  background: var(--bg-success);
  color: var(--text-success);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
}

/* Schedule card */
.schedule-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.schedule-days {
  display: flex;
  gap: var(--space-1);
}

.schedule-day {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-bold);
  background: var(--bg-secondary);
  color: var(--text-tertiary);
}

.schedule-day.active {
  background: var(--accent-primary);
  color: white;
}

.schedule-time {
  font-weight: var(--font-weight-bold);
  font-size: var(--text-sm);
}

/* Call log */
.call-log-item {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  box-shadow: var(--shadow-sm);
}

.call-log-info { flex: 1; }
.call-log-time {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* Note input */
.note-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  resize: vertical;
  min-height: 80px;
  outline: none;
}

.note-input:focus {
  border-color: var(--border-focus);
}
