/* ================================================================
   FitNest Portal — shared styles for login · dashboard · chat
   ================================================================ */

:root {
  --bg-base:        #070b12;
  --bg-surface:     #0d1320;
  --bg-card:        #111928;
  --bg-card-hover:  #151f2e;
  --bg-input:       #0a1019;

  --border:         rgba(255,255,255,0.07);
  --border-active:  rgba(0,212,255,0.4);

  --cyan:           #00d4ff;
  --cyan-dim:       rgba(0,212,255,0.10);
  --cyan-glow:      rgba(0,212,255,0.22);
  --green:          #10efb0;
  --orange:         #f97316;
  --red:            #ef4444;
  --purple:         #10efb0;
  --amber:          #f59e0b;

  --text-primary:   #ffffff;
  --text-secondary: rgba(255,255,255,0.78);
  --text-muted:     rgba(255,255,255,0.52);

  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   20px;
  --r-pill: 999px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.45);
  --t: 0.18s ease;
  --font: 'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  scroll-behavior: smooth;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  position: relative;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  overscroll-behavior-x: none;
  /* Disables double-tap zoom; pair with viewport maximum-scale (see HTML meta) */
  touch-action: manipulation;
}

/* iOS Safari zooms focused inputs if font-size < 16px — breaks chat/toolbars */
@media (max-width: 1024px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="image"]):not([type="file"]),
  textarea,
  select {
    font-size: 16px !important;
    max-width: 100%;
  }
}
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }

/* ── Portal nav ───────────────────────────────────────────────── */
.portal-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 200;
  /* Below status bar / Dynamic Island (requires viewport-fit=cover in HTML) */
  padding-top: constant(safe-area-inset-top);
  padding-top: env(safe-area-inset-top);
  min-height: calc(58px + constant(safe-area-inset-top));
  min-height: calc(58px + env(safe-area-inset-top));
  height: auto;
  display: flex; align-items: center; justify-content: space-between;
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  padding-bottom: 0;
  background: rgba(7,11,18,0.88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  max-width: 100%;
  box-sizing: border-box;
  gap: 10px;
}

/*
 * Reserve space for the fixed nav (matches .portal-nav min-height rules; dashboard/chat
 * use a tighter mobile row — see max-width:720px).
 */
body.portal-app {
  padding-top: calc(58px + constant(safe-area-inset-top));
  padding-top: calc(58px + env(safe-area-inset-top));
  box-sizing: border-box;
}
@media (max-width: 720px) {
  body.portal-app {
    padding-top: calc(50px + max(6px, constant(safe-area-inset-top)));
    padding-top: calc(50px + max(6px, env(safe-area-inset-top)));
  }
}
.portal-logo {
  display: flex; align-items: center; gap: 7px;
  font-size: 18px; font-weight: 800;
  color: var(--text-primary); text-decoration: none;
  flex-shrink: 1;
  min-width: 0;
}
.portal-logo .mark { color: var(--cyan); font-size: 22px; flex-shrink: 0; }
.portal-logo .portal-logo-img {
  height: 32px;
  width: auto;
  max-width: min(252px, 58vw);
  object-fit: contain;
  display: block;
}
.auth-logo .auth-logo-img {
  height: 36px;
  width: auto;
  max-width: min(280px, 88vw);
  object-fit: contain;
  display: block;
}
.portal-nav-right {
  display: flex; align-items: center; gap: 10px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}

.nav-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-secondary);
  min-width: 0;
  flex-shrink: 1;
}
.nav-user span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--cyan-dim); border: 1px solid var(--border-active);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--cyan);
  overflow: hidden; flex-shrink: 0;
}
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Icon shows whenever label is hidden (see 768px media query). */
.nav-signout-btn .nav-signout-icon { display: none; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--r-pill); border: none;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: var(--t); white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-primary  { background: var(--cyan); color: #000; }
.btn-primary:hover { background: #30daff; box-shadow: 0 0 18px var(--cyan-glow); }

.btn-outline  { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn-outline:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.04); }

.btn-ghost    { background: transparent; color: var(--text-secondary); padding: 7px 12px; }
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }

.btn-danger   { background: rgba(239,68,68,0.12); color: var(--red); border: 1px solid rgba(239,68,68,0.22); }
.btn-danger:hover { background: rgba(239,68,68,0.22); }

.btn-sm  { padding: 6px 13px; font-size: 12px; }
.btn-lg  { padding: 13px 28px; font-size: 15px; }
.btn-full { width: 100%; }

/* ── Form fields ──────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 10px 13px;
  font-size: 15px; color: var(--text-primary); font-family: var(--font);
  transition: border-color var(--t);
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(0,212,255,0.07);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-muted); }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px;
}
.card-sm  { padding: 13px 15px; }
.card-lg  { padding: 26px; }

/* ── Badge ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
}
.badge-cyan   { background: var(--cyan-dim);             color: var(--cyan);   border: 1px solid rgba(0,212,255,0.18); }
.badge-green  { background: rgba(16,239,176,0.10);       color: var(--green);  border: 1px solid rgba(16,239,176,0.18); }
.badge-orange { background: rgba(249,115,22,0.10);       color: var(--orange); border: 1px solid rgba(249,115,22,0.18); }
.badge-purple { background: rgba(16,239,176,0.10);        color: var(--purple); border: 1px solid rgba(16,239,176,0.18); }
.badge-muted  { background: rgba(255,255,255,0.06);      color: var(--text-secondary); border: 1px solid var(--border); }

/* ── Dot ──────────────────────────────────────────────────────── */
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-green  { background: var(--green);  box-shadow: 0 0 5px var(--green); }
.dot-orange { background: var(--orange); }
.dot-cyan   { background: var(--cyan);   }
.dot-muted  { background: var(--text-muted); }

/* ── Dividers ─────────────────────────────────────────────────── */
hr.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.or-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); font-size: 12px; margin: 16px 0;
}
.or-divider::before, .or-divider::after {
  content: ''; flex: 1; border-top: 1px solid var(--border);
}

/* ── Toast ────────────────────────────────────────────────────── */
#toast-wrap {
  position: fixed; bottom: 22px; right: 22px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 11px 16px;
  font-size: 13px; color: var(--text-primary);
  box-shadow: var(--shadow-card); pointer-events: auto;
  animation: toastIn .22s ease both;
  max-width: 300px; line-height: 1.4;
}
.toast.ok  { border-left: 3px solid var(--green);  }
.toast.err { border-left: 3px solid var(--red);    }
.toast.out { animation: toastOut .22s ease both; }
@keyframes toastIn  { from { opacity:0; transform:translateY(10px) } to { opacity:1; transform:none } }
@keyframes toastOut { to   { opacity:0; transform:translateY(10px) } }

/* ── Spinner ──────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.12); border-top-color: var(--cyan);
  border-radius: 50%; animation: spin .65s linear infinite; display: inline-block;
}
.spinner-lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed; inset: 0; background: var(--bg-base);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 9999;
}
.loading-overlay p { color: var(--text-secondary); font-size: 14px; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 40px 20px; text-align: center;
}
.empty .icon { font-size: 34px; opacity: 0.35; }
.empty p { font-size: 13px; color: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────────── */
/*
 * 1024px (not 768px): iPhone Safari “Request Desktop Website” uses ~980px width;
 * at 768px those clients still showed the full email and blew the header width.
 */
@media (max-width: 1024px) {
  .portal-nav {
    padding: 0 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-top: constant(safe-area-inset-top);
    padding-top: env(safe-area-inset-top);
    gap: 6px;
  }
  .portal-nav-right { gap: 6px; min-width: 0; }
  .card-lg { padding: 18px; }
  .nav-user span { display: none; }
  /* Text labels off — emoji / icons only (matches chat “← Dashboard”, etc.) */
  .portal-nav-right .btn-outline .btn-label { display: none; }
  .portal-nav-right .nav-signout-btn .btn-label { display: none; }
  .nav-signout-btn .nav-signout-icon { display: inline; }
  .portal-nav-right .btn { padding: 8px 10px; font-size: 12px; }
  .portal-logo {
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 72vw;
  }
  .portal-logo .mark { font-size: 18px; }
}

/*
 * Narrow screens: (chat / generic portal only). Dashboard uses its own grid header + drawer in dashboard.html.
 */
@media (max-width: 720px) {
  .portal-nav:not(.portal-nav-dashboard) {
    flex-wrap: wrap;
    height: auto;
    min-height: 52px;
    padding-top: calc(constant(safe-area-inset-top) + 10px);
    padding-top: calc(env(safe-area-inset-top) + 10px);
    padding-bottom: 10px;
    row-gap: 10px;
    align-content: center;
  }
  .portal-nav:not(.portal-nav-dashboard) .portal-logo {
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
  }
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right > .nav-user,
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right > .btn,
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right > .nav-btn-badge-wrap,
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right > a.btn {
    flex: 0 0 auto;
  }
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right .btn,
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right .nav-btn-badge-wrap,
  .portal-nav:not(.portal-nav-dashboard) .portal-nav-right a.btn-sm {
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
    padding: 10px 12px;
  }
  .portal-nav:not(.portal-nav-dashboard) .nav-top-badge {
    top: -4px;
    right: 2px;
  }
  /* Dashboard: compact messages tile + badge */
  .portal-nav-dashboard .nav-top-badge {
    top: -4px;
    right: 2px;
  }
}

@media (max-width: 520px) {
  .portal-logo { font-size: 15px; }
  .portal-logo .mark { font-size: 17px; }
}

/* ── Accessibility: visible focus for keyboard users ── */
a:focus-visible,
button:focus-visible,
.sidebar-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.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;
}
