/* ============================================
   Live Location Share — Design System
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #6366F1;
  --color-primary-dark: #4F46E5;
  --color-primary-light: #EEF2FF;
  --color-primary-ring: rgba(99, 102, 241, 0.35);

  --color-success: #10B981;
  --color-success-light: #D1FAE5;
  --color-error: #EF4444;
  --color-error-light: #FEE2E2;
  --color-warning: #F59E0B;
  --color-warning-light: #FEF3C7;

  --color-bg: #F8FAFC;
  --color-bg-alt: #F1F5F9;
  --color-surface: #FFFFFF;
  --color-border: #E2E8F0;
  --color-border-light: #F1F5F9;

  --color-text: #0F172A;
  --color-text-secondary: #475569;
  --color-text-muted: #94A3B8;

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  --max-width: 640px;
  --nav-height: 64px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* --- Utilities --- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

.hidden {
  display: none !important;
}

/* --- Navigation --- */
.nav {
  height: var(--nav-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.9);
}

.nav__inner {
  display: flex;
  align-items: center;
  height: 100%;
}

.nav__logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav__logo svg {
  width: 24px;
  height: 24px;
}

.nav__logo-accent {
  color: var(--color-primary);
}

/* --- Main Layout --- */
.main {
  padding: 40px 0 60px;
}

/* --- Card --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-md);
}

.card__title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.3;
  margin-bottom: 8px;
}

.card__subtitle {
  color: var(--color-text-secondary);
  font-size: 0.938rem;
  margin-bottom: 24px;
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.813rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.938rem;
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.input::placeholder {
  color: var(--color-text-muted);
}

.input--readonly {
  background: var(--color-bg-alt);
  cursor: default;
}

/* --- Input Group --- */
.input-group {
  display: flex;
  gap: 8px;
}

.input-group .input {
  flex: 1;
  min-width: 0;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-family);
  line-height: 1.4;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

.btn--primary:focus-visible {
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.btn--secondary {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.btn--outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn--outline:hover:not(:disabled) {
  background: var(--color-primary-light);
}

.btn--danger {
  background: var(--color-error);
  color: #fff;
  border-color: var(--color-error);
}

.btn--danger:hover:not(:disabled) {
  background: #DC2626;
  border-color: #DC2626;
}

.btn--lg {
  padding: 12px 28px;
  font-size: 1rem;
  width: 100%;
}

.btn--sm {
  padding: 6px 14px;
  font-size: 0.813rem;
}

.btn__spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* --- Hero/Share Section --- */
.hero {
  text-align: center;
  padding: 20px 0;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
  background: var(--color-primary-light);
  border-radius: 100px;
  margin-bottom: 20px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.hero .card {
  text-align: left;
}

/* --- Share States --- */
.share-setup {
  text-align: center;
}

.share-setup .card__title {
  font-size: 1.625rem;
}

.share-setup .card__subtitle {
  font-size: 1rem;
}

/* --- Active Sharing State --- */
.share-active {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.success-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-success-light);
  color: #065F46;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.success-banner__icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-success);
  color: #fff;
  border-radius: 50%;
  font-size: 0.688rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* --- Share Link Box --- */
.share-link-box {
  margin-bottom: 20px;
}

.share-link-box label {
  display: block;
  font-size: 0.813rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

/* --- Share Actions (QR + Buttons) --- */
.share-actions {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.qr-box {
  width: 120px;
  height: 120px;
  flex-shrink: 0;
  background: #fff;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.qr-box canvas,
.qr-box img {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-placeholder {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 8px;
}

.share-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

/* --- Status Bar --- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-sm);
  font-size: 0.813rem;
  color: var(--color-text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot--live {
  background: var(--color-success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.1); }
}

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

.status-separator {
  color: var(--color-border);
}

/* --- Error State --- */
.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-error-light);
  color: #991B1B;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.error-banner__icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.retry-area {
  text-align: center;
}

/* --- Geolocation Unsupported --- */
.unsupported-banner {
  text-align: center;
  padding: 40px 20px;
}

.unsupported-banner__icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.unsupported-banner__text {
  font-size: 0.938rem;
  color: var(--color-text-secondary);
}

/* --- Sections --- */
.section {
  padding: 48px 0;
}

.section--alt {
  background: var(--color-bg-alt);
}

.section__title {
  font-size: 1.375rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
  margin-bottom: 32px;
}

/* --- Steps (How It Works) --- */
.steps {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 640px) {
  .steps {
    grid-template-columns: repeat(3, 1fr);
  }
}

.step {
  text-align: center;
  padding: 24px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.step__number {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 700;
  font-size: 0.875rem;
  border-radius: 50%;
}

.step h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.step p {
  font-size: 0.813rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* --- Features --- */
.features {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 640px) {
  .features {
    grid-template-columns: repeat(3, 1fr);
  }
}

.feature {
  padding: 20px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
}

.feature__icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.feature h3 {
  font-size: 0.938rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.feature p {
  font-size: 0.813rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* --- Footer --- */
.footer {
  padding: 24px 0;
  text-align: center;
  border-top: 1px solid var(--color-border);
}

.footer p {
  font-size: 0.813rem;
  color: var(--color-text-muted);
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
  width: calc(100% - 32px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  animation: toastIn 0.25s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast--success {
  border-left: 3px solid var(--color-success);
}

.toast--error {
  border-left: 3px solid var(--color-error);
}

.toast--info {
  border-left: 3px solid var(--color-primary);
}

.toast__icon {
  flex-shrink: 0;
  font-size: 1rem;
}

.toast__message {
  flex: 1;
}

.toast__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1.125rem;
  padding: 0 2px;
  line-height: 1;
}

.toast__close:hover {
  color: var(--color-text);
}

/* --- Track Page (Map) --- */
.map-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.map-page .nav {
  position: relative;
}

.map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.map-overlay {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 480px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-xl);
}

.map-overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.map-overlay__name {
  font-weight: 600;
  font-size: 0.938rem;
}

.map-overlay__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
}

.map-overlay__coords {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
  margin-bottom: 4px;
}

.map-overlay__updated {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.map-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
  text-align: center;
  color: var(--color-text-secondary);
}

.map-error__icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.map-error__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
}

.map-error__text {
  font-size: 0.875rem;
  margin-bottom: 20px;
}

.map-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.map-loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .card {
    padding: 24px 16px;
  }

  .share-actions {
    flex-direction: column;
    align-items: center;
  }

  .qr-box {
    width: 140px;
    height: 140px;
  }

  .share-buttons {
    width: 100%;
    flex-direction: row;
  }

  .share-buttons .btn {
    flex: 1;
  }

  .map-overlay {
    bottom: 12px;
    width: calc(100% - 16px);
    padding: 12px 16px;
  }
}

/* --- Focus visible for accessibility --- */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* --- Selection --- */
::selection {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

/* --- Print --- */
@media print {
  .nav, .toast-container { display: none; }
}
