/* ============================================================
   EmprestaAí — Design System (Apple HIG Style)
   main.css: Tokens, Base Reset, Dark Mode, Layout
   ============================================================ */

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

/* ===================== DESIGN TOKENS ===================== */
:root {
  /* ---- Colors: Light Mode ---- */
  --clr-bg-primary:      #FFFFFF;
  --clr-bg-secondary:    #F2F2F7;
  --clr-bg-tertiary:     #FFFFFF;
  --clr-bg-grouped:      #F2F2F7;
  --clr-bg-card:         #FFFFFF;
  --clr-bg-elevated:     #FFFFFF;
  --clr-bg-overlay:      rgba(0, 0, 0, 0.4);

  --clr-text-primary:    #000000;
  --clr-text-secondary:  #3C3C43CC;
  --clr-text-tertiary:   #3C3C4399;
  --clr-text-quaternary: #3C3C4366;
  --clr-text-placeholder:#3C3C4366;
  --clr-text-inverse:    #FFFFFF;

  --clr-separator:       #3C3C4349;
  --clr-separator-opaque:#C6C6C8;

  /* ---- Accent & Semantic Colors ---- */
  --clr-accent:          #007AFF;
  --clr-accent-hover:    #0062CC;
  --clr-accent-alpha:    rgba(0, 122, 255, 0.12);
  --clr-success:         #34C759;
  --clr-success-alpha:   rgba(52, 199, 89, 0.12);
  --clr-warning:         #FF9500;
  --clr-warning-alpha:   rgba(255, 149, 0, 0.12);
  --clr-danger:          #FF3B30;
  --clr-danger-alpha:    rgba(255, 59, 48, 0.12);
  --clr-purple:          #AF52DE;
  --clr-purple-alpha:    rgba(175, 82, 222, 0.12);
  --clr-teal:            #5AC8FA;
  --clr-teal-alpha:      rgba(90, 200, 250, 0.12);
  --clr-indigo:          #5856D6;
  --clr-mint:            #00C7BE;

  /* ---- Typography ---- */
  --font-family:         'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  --font-size-xs:        11px;
  --font-size-sm:        13px;
  --font-size-base:      15px;
  --font-size-md:        17px;
  --font-size-lg:        20px;
  --font-size-xl:        24px;
  --font-size-2xl:       28px;
  --font-size-3xl:       34px;
  --font-weight-light:   300;
  --font-weight-regular: 400;
  --font-weight-medium:  500;
  --font-weight-semibold:600;
  --font-weight-bold:    700;
  --font-weight-heavy:   800;
  --line-height-tight:   1.1;
  --line-height-snug:    1.3;
  --line-height-base:    1.5;
  --letter-spacing-tight:-0.5px;
  --letter-spacing-wide: 0.3px;

  /* ---- Spacing Scale (4px base) ---- */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  28px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* ---- Border Radius (Apple HIG) ---- */
  --radius-xs:   4px;
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-2xl:  24px;
  --radius-3xl:  28px;
  --radius-full: 999px;

  /* ---- Shadows ---- */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:   0 8px 24px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.08);
  --shadow-xl:   0 16px 48px rgba(0,0,0,0.16), 0 8px 16px rgba(0,0,0,0.10);
  --shadow-card: 0 2px 16px rgba(0,0,0,0.08);
  --shadow-modal:0 24px 64px rgba(0,0,0,0.20);

  /* ---- Transitions ---- */
  --transition-fast:    all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base:    all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow:    all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring:  all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-bounce:  all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* ---- Layout ---- */
  --nav-height:         84px;
  --header-height:      56px;
  --safe-area-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-area-top:      env(safe-area-inset-top, 0px);
  --page-padding:       var(--space-4);
  --max-width:          430px;
}

/* ===================== DARK MODE TOKENS ===================== */
@media (prefers-color-scheme: dark) {
  :root {
    --clr-bg-primary:      #000000;
    --clr-bg-secondary:    #1C1C1E;
    --clr-bg-tertiary:     #2C2C2E;
    --clr-bg-grouped:      #000000;
    --clr-bg-card:         #1C1C1E;
    --clr-bg-elevated:     #2C2C2E;
    --clr-bg-overlay:      rgba(0, 0, 0, 0.7);

    --clr-text-primary:    #FFFFFF;
    --clr-text-secondary:  #EBEBF599;
    --clr-text-tertiary:   #EBEBF566;
    --clr-text-quaternary: #EBEBF533;
    --clr-text-placeholder:#EBEBF533;
    --clr-text-inverse:    #000000;

    --clr-separator:       #38383A;
    --clr-separator-opaque:#38383A;

    --clr-accent:          #0A84FF;
    --clr-accent-hover:    #409CFF;
    --clr-accent-alpha:    rgba(10, 132, 255, 0.18);
    --clr-success:         #30D158;
    --clr-success-alpha:   rgba(48, 209, 88, 0.18);
    --clr-warning:         #FF9F0A;
    --clr-warning-alpha:   rgba(255, 159, 10, 0.18);
    --clr-danger:          #FF453A;
    --clr-danger-alpha:    rgba(255, 69, 58, 0.18);
    --clr-purple:          #BF5AF2;
    --clr-purple-alpha:    rgba(191, 90, 242, 0.18);
    --clr-teal:            #64D2FF;
    --clr-teal-alpha:      rgba(100, 210, 255, 0.18);
    --clr-indigo:          #5E5CE6;
    --clr-mint:            #63E6E2;

    --shadow-sm:   0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.2);
    --shadow-lg:   0 8px 24px rgba(0,0,0,0.5), 0 4px 8px rgba(0,0,0,0.3);
    --shadow-xl:   0 16px 48px rgba(0,0,0,0.6), 0 8px 16px rgba(0,0,0,0.4);
    --shadow-card: 0 2px 16px rgba(0,0,0,0.4);
    --shadow-modal:0 24px 64px rgba(0,0,0,0.7);
  }
}

/* Manual dark mode override */
[data-theme="dark"] {
  --clr-bg-primary:      #000000;
  --clr-bg-secondary:    #1C1C1E;
  --clr-bg-tertiary:     #2C2C2E;
  --clr-bg-grouped:      #000000;
  --clr-bg-card:         #1C1C1E;
  --clr-bg-elevated:     #2C2C2E;
  --clr-text-primary:    #FFFFFF;
  --clr-text-secondary:  #EBEBF599;
  --clr-text-tertiary:   #EBEBF566;
  --clr-text-quaternary: #EBEBF533;
  --clr-separator:       #38383A;
  --clr-accent:          #0A84FF;
  --clr-success:         #30D158;
  --clr-warning:         #FF9F0A;
  --clr-danger:          #FF453A;
  --shadow-card:         0 2px 16px rgba(0,0,0,0.4);
}

/* Manual light mode override */
[data-theme="light"] {
  --clr-bg-primary:      #FFFFFF;
  --clr-bg-secondary:    #F2F2F7;
  --clr-bg-tertiary:     #FFFFFF;
  --clr-bg-grouped:      #F2F2F7;
  --clr-bg-card:         #FFFFFF;
  --clr-bg-elevated:     #FFFFFF;
  --clr-bg-overlay:      rgba(0, 0, 0, 0.4);
  --clr-text-primary:    #000000;
  --clr-text-secondary:  #3C3C43CC;
  --clr-text-tertiary:   #3C3C4399;
  --clr-text-quaternary: #3C3C4366;
  --clr-separator:       #3C3C4349;
  --clr-accent:          #007AFF;
  --clr-success:         #34C759;
  --clr-warning:         #FF9500;
  --clr-danger:          #FF3B30;
  --shadow-card:         0 2px 16px rgba(0,0,0,0.08);
}

/* ===================== BASE RESET ===================== */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-base);
  color: var(--clr-text-primary);
  background-color: var(--clr-bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overscroll-behavior: none;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-family);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--clr-text-primary);
}

p { margin: 0; }

a {
  color: var(--clr-accent);
  text-decoration: none;
  transition: var(--transition-fast);
}

button {
  cursor: pointer;
  font-family: var(--font-family);
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

input, select, textarea {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--clr-text-primary);
  background: transparent;
  border: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder, textarea::placeholder {
  color: var(--clr-text-placeholder);
}

img { max-width: 100%; height: auto; display: block; }
ul, ol { margin: 0; padding: 0; list-style: none; }

/* ===================== LOADING SCREEN ===================== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--clr-bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  animation: loadingPulse 2s ease-in-out infinite;
}

.loading-logo {
  animation: logoSpin 2s linear infinite;
}

.loading-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--clr-text-primary);
  letter-spacing: var(--letter-spacing-tight);
}

.loading-subtitle {
  font-size: var(--font-size-sm);
  color: var(--clr-text-secondary);
}

.loading-bar {
  width: 120px;
  height: 3px;
  background: var(--clr-bg-secondary);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: var(--space-2);
}

.loading-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--clr-accent), var(--clr-teal));
  border-radius: var(--radius-full);
  animation: loadingBar 1.5s ease-in-out infinite;
}

/* ===================== AUTH SCREEN ===================== */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--clr-bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: var(--space-8) var(--space-6);
  overflow-y: auto;
}

.auth-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  max-width: 360px;
  width: 100%;
  padding-top: var(--safe-area-top);
}

.auth-logo {
  width: 88px;
  height: 88px;
  background: linear-gradient(135deg, #1C1C1E 0%, #2C2C2E 100%);
  border-radius: var(--radius-2xl);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-xl), 0 0 40px rgba(0, 122, 255, 0.2);
  margin-bottom: var(--space-2);
}

.auth-title {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-tight);
  text-align: center;
  background: linear-gradient(135deg, var(--clr-text-primary), var(--clr-text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-subtitle {
  font-size: var(--font-size-base);
  color: var(--clr-text-secondary);
  text-align: center;
  line-height: var(--line-height-base);
  max-width: 280px;
}

.auth-features {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  background: var(--clr-bg-secondary);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  margin: var(--space-2) 0;
}

.auth-feature {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--clr-text-secondary);
  font-weight: var(--font-weight-medium);
}

.auth-feature-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.btn-google-signin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-4) var(--space-6);
  background: var(--clr-bg-secondary);
  border: 1px solid var(--clr-separator);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--clr-text-primary);
  transition: var(--transition-fast);
  cursor: pointer;
}

.btn-google-signin:hover {
  background: var(--clr-bg-tertiary);
  border-color: var(--clr-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-google-signin:active {
  transform: translateY(0);
  box-shadow: none;
}

.auth-disclaimer {
  font-size: var(--font-size-xs);
  color: var(--clr-text-tertiary);
  text-align: center;
}

/* ===================== APP LAYOUT ===================== */
.app {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--clr-bg-primary);
  overflow: hidden;
}

.page-content {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-area-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ===================== PAGE STRUCTURE ===================== */
.page {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-area-bottom) + var(--space-4));
  animation: pageEnter 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--clr-bg-primary);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--clr-separator);
  padding: var(--space-4) var(--page-padding);
  padding-top: calc(var(--space-4) + var(--safe-area-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
}

.page-header-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--clr-text-primary);
}

.page-header-back {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--clr-accent);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
  cursor: pointer;
}

.page-header-back:hover { opacity: 0.7; }
.page-header-back svg { width: 20px; height: 20px; }

.page-header-action {
  color: var(--clr-accent);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
  cursor: pointer;
}

.page-header-action:hover { background: var(--clr-accent-alpha); }

.page-body {
  padding: var(--space-4) var(--page-padding);
}

/* ===================== BOTTOM NAV ===================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  height: calc(var(--nav-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  background: var(--clr-bg-primary);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--clr-separator);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 200;
  padding-top: var(--space-2);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  flex: 1;
  padding: var(--space-2) 0;
  color: var(--clr-text-tertiary);
  text-decoration: none;
  transition: var(--transition-fast);
  position: relative;
}

.nav-item.active,
.nav-item[data-active="true"] {
  color: var(--clr-accent);
}

.nav-icon {
  width: 24px;
  height: 24px;
  transition: var(--transition-fast);
}

.nav-label {
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.2px;
}

.nav-item.active .nav-icon,
.nav-item[data-active="true"] .nav-icon {
  transform: scale(1.1);
}

/* ---- FAB Nav Item ---- */
.nav-item-fab {
  flex: 1.2;
}

.nav-fab {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--clr-accent), var(--clr-indigo));
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 122, 255, 0.4);
  transition: var(--transition-spring);
  margin-top: -16px;
}

.nav-fab svg {
  width: 24px;
  height: 24px;
  stroke: white;
}

.nav-item-fab:hover .nav-fab,
.nav-item-fab:active .nav-fab {
  transform: scale(1.08) rotate(45deg);
  box-shadow: 0 6px 24px rgba(0, 122, 255, 0.5);
}

/* ===================== HIDDEN UTILITY ===================== */
.hidden { display: none !important; }
.invisible { visibility: hidden !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ===================== SECTION HEADERS ===================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--page-padding) var(--space-2);
}

.section-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--clr-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
}

.section-action {
  font-size: var(--font-size-sm);
  color: var(--clr-accent);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 0; height: 0; display: none; }
scrollbar-width: none;

/* ===================== SAFE AREA PADDING ===================== */
.safe-top { padding-top: var(--safe-area-top); }
.safe-bottom { padding-bottom: var(--safe-area-bottom); }

/* ===================== TEXT UTILITIES ===================== */
.text-primary   { color: var(--clr-text-primary); }
.text-secondary { color: var(--clr-text-secondary); }
.text-tertiary  { color: var(--clr-text-tertiary); }
.text-accent    { color: var(--clr-accent); }
.text-success   { color: var(--clr-success); }
.text-warning   { color: var(--clr-warning); }
.text-danger    { color: var(--clr-danger); }
.text-center    { text-align: center; }
.text-right     { text-align: right; }
.font-medium    { font-weight: var(--font-weight-medium); }
.font-semibold  { font-weight: var(--font-weight-semibold); }
.font-bold      { font-weight: var(--font-weight-bold); }

/* ===================== FLEX UTILITIES ===================== */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }

/* ===================== EMPTY STATE ===================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-16) var(--space-6);
  text-align: center;
}

.empty-state-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: var(--space-2);
}

.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--clr-text-primary);
}

.empty-state-desc {
  font-size: var(--font-size-sm);
  color: var(--clr-text-secondary);
  max-width: 240px;
  line-height: var(--line-height-base);
}

/* ===================== MAPS MODAL ===================== */
.maps-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--clr-bg-primary);
  display: flex;
  flex-direction: column;
  transition: var(--transition-base);
}

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

.maps-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--page-padding);
  padding-top: calc(var(--space-4) + var(--safe-area-top));
  background: var(--clr-bg-primary);
  border-bottom: 1px solid var(--clr-separator);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  flex-shrink: 0;
  z-index: 1;
}

.maps-title {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
}

.maps-close-btn {
  width: 32px; height: 32px;
  background: var(--clr-bg-secondary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.maps-close-btn svg { width: 16px; height: 16px; stroke: var(--clr-text-secondary); }
.maps-close-btn:hover { background: var(--clr-bg-tertiary); }

#maps-container {
  flex: 1;
}

.maps-address-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--page-padding);
  padding-bottom: calc(var(--space-4) + var(--safe-area-bottom));
  background: var(--clr-bg-secondary);
  border-top: 1px solid var(--clr-separator);
  font-size: var(--font-size-sm);
  color: var(--clr-text-secondary);
  flex-shrink: 0;
}

.maps-address-bar svg { color: var(--clr-accent); flex-shrink: 0; }
