/* ============================================================
   TITUS Flow — Layout & Global Styles
   ============================================================ */

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

/* Prevent iOS Safari auto-zoom on input focus */
input, textarea, select {
  font-size: 16px !important;
}

/* Android Chrome 100dvh fix */
:root { --app-height: 100dvh; }

html, body {
  height: 100%;
  height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* Prevent iOS bounce scroll that causes keyboard gap */
  position: fixed;
  width: 100%;
  overflow: hidden;
}

/* ── App shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: var(--app-height, 100dvh);
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

/* ── Screen container ── */
#screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

/* ── Bottom nav ── */
#nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-h) + var(--safe-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
  box-shadow: 0 2px 0 8px var(--card);
  transition: transform .25s ease, opacity .25s ease;
}

/* Hide nav completely when empty or during onboarding */
#nav:empty {
  display: none !important;
  pointer-events: none;
}

/* Screen padding only when nav is visible */
#screen.has-nav {
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}
#screen:not(.has-nav) {
  padding-bottom: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  padding: 4px 0;
  transition: opacity .15s;
}
.nav-item:active { opacity: .7; }

.nav-icon {
  font-size: 22px;
  line-height: 1;
  color: var(--txt3);
  transition: color .15s;
}
.nav-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--txt3);
  transition: color .15s;
}
.nav-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
  transition: background .15s;
  margin-top: 1px;
}
.nav-item.active .nav-icon,
.nav-item.active .nav-label { color: var(--navy); }
.nav-item.active .nav-dot   { background: var(--navy); }

/* ── Screen header ── */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  padding-top: calc(var(--space-lg) + var(--safe-top) + env(safe-area-inset-top, 16px));
}

.screen-title { font-size: 20px; font-weight: 700; color: var(--txt); }
.screen-sub   { font-size: 12px; color: var(--txt3); margin-top: 1px; }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-sm);
}

/* ── Section label ── */
.section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--txt3);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: var(--space-sm) var(--space-lg) var(--space-xs);
}

/* ── Tier badge ── */
.tier-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--tc-lt);
  color: var(--tc-dk);
  flex-shrink: 0;
}

/* ── Priority badge ── */
.priority-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  background: var(--tc-lt);
  color: var(--tc-dk);
  flex-shrink: 0;
}

/* ── FAB (floating action button) ── */
.fab {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  border: none;
  font-size: 24px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform .15s, box-shadow .15s;
  flex-shrink: 0;
}
.fab:active { transform: scale(.94); box-shadow: var(--shadow-sm); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:active { opacity: .85; transform: scale(.98); }
.btn-primary   { background: var(--navy); color: #fff; }
.btn-secondary { background: var(--card); color: var(--txt2); border: 1px solid var(--border); }
.btn-tier      { background: var(--tc); color: #fff; }
.btn-full      { width: 100%; }

/* ── Input ── */
.input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 16px;  /* 16px minimum prevents iOS auto-zoom on focus */
  font-family: var(--font);
  color: var(--txt);
  background: var(--card);
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--navy); }
.input::placeholder { color: var(--txt3); }

.input-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--txt2);
  margin-bottom: var(--space-xs);
  display: block;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

/* ── Avatar ── */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-sm) 0;
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
  gap: var(--space-sm);
  text-align: center;
}
.empty-icon  { font-size: 36px; opacity: .4; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--txt2); }
.empty-sub   { font-size: 13px; color: var(--txt3); }

/* ── Offline banner ── */
#offline-banner {
  display: none;
  background: #334155;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  padding: 6px;
}
body.offline #offline-banner { display: block; }

/* ── Spinner ── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading screen ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  z-index: 999;
  transition: opacity .3s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loading-logo   { font-size: 42px; font-weight: 800; color: #fff; letter-spacing: -.5px; }
.loading-sub    { font-size: 14px; color: rgba(255,255,255,.5); }
.loading-dots span {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #F5A623;
  margin: 0 3px;
  animation: bounce .9s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: .5; }
  40%            { transform: scale(1);   opacity: 1;  }
}

/* ── Utilities ── */
.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm      { gap: var(--space-sm); }
.gap-md      { gap: var(--space-md); }
.px-lg       { padding-left: var(--space-lg); padding-right: var(--space-lg); }
.py-md       { padding-top: var(--space-md);  padding-bottom: var(--space-md); }
.mt-sm       { margin-top: var(--space-sm); }
.mt-md       { margin-top: var(--space-md); }
.text-sm     { font-size: 12px; }
.text-xs     { font-size: 11px; }
.text-muted  { color: var(--txt3); }
.font-600    { font-weight: 600; }
.truncate    { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
