/* ================================================================
   FortzFit Admin — Design System
   Mobile-first • CSS custom properties • Bootstrap 5 override layer
   ================================================================ */

/* ── 1. CSS Custom Properties ───────────────────────────────────── */
:root {
  /* Override Bootstrap primary → fitness green */
  --bs-primary:                    #22c55e;
  --bs-primary-rgb:                34, 197, 94;
  --bs-primary-text-emphasis:      #166534;
  --bs-primary-bg-subtle:          #dcfce7;
  --bs-primary-border-subtle:      #bbf7d0;
  --bs-link-color:                 #22c55e;
  --bs-link-color-rgb:             34, 197, 94;
  --bs-link-hover-color:           #16a34a;

  /* Body tokens */
  --bs-body-bg:                    #f8fafc;
  --bs-body-color:                 #0f172a;
  --bs-body-font-family:           system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --bs-body-font-size:             0.9375rem;
  --bs-body-line-height:           1.6;

  /* Border & radius */
  --bs-border-color:               #e2e8f0;
  --bs-border-radius:              0.5rem;
  --bs-border-radius-sm:           0.375rem;
  --bs-border-radius-lg:           0.75rem;
  --bs-border-radius-xl:           1rem;
  --bs-border-radius-2xl:          1.5rem;
  --bs-card-border-color:          #e2e8f0;
  --bs-card-border-radius:         0.75rem;
  --bs-card-cap-bg:                #ffffff;
  --bs-card-cap-padding-y:         0.875rem;
  --bs-card-cap-padding-x:         1.125rem;
  --bs-card-spacer-y:              1.125rem;
  --bs-card-spacer-x:              1.125rem;

  /* Sidebar */
  --sidebar-bg:                    #0f172a;
  --sidebar-hover:                 #1e293b;
  --sidebar-text:                  rgba(255, 255, 255, 0.62);
  --sidebar-active-bg:             rgba(34, 197, 94, 0.13);
  --sidebar-border:                rgba(255, 255, 255, 0.07);
  --sidebar-width:                 260px;
  --topbar-height:                 56px;
}

/* ── 2. Base ────────────────────────────────────────────────────── */
body { background: var(--bs-body-bg); }

/* ── 3. Mobile Top Bar ──────────────────────────────────────────── */
.mobile-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  z-index: 1035;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.topbar-toggle {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.82);
  font-size: 1.45rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  line-height: 1;
  transition: background 140ms;
  flex-shrink: 0;
}
.topbar-toggle:hover { background: var(--sidebar-hover); }

.topbar-brand {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-brand .brand-accent { color: var(--bs-primary); }
.topbar-brand small {
  display: block;
  font-size: 0.62rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ── 4. Sidebar (Offcanvas on mobile, permanent on desktop) ─────── */
.admin-sidebar {
  background: var(--sidebar-bg) !important;
  border-right: none !important;
  width: var(--sidebar-width) !important;
}

/* Make offcanvas body a flex column so footer stays at bottom */
.admin-sidebar .offcanvas-body {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 1.25rem 1.125rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.sidebar-logo span { color: var(--bs-primary); }
.sidebar-tagline {
  font-size: 0.63rem;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: 0.125rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-section-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.3);
  padding: 0.625rem 0.75rem 0.25rem;
}

.nav-item-sidebar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 140ms, color 140ms;
  margin-bottom: 2px;
  min-height: 44px; /* touch target */
}
.nav-item-sidebar:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.nav-item-sidebar.active {
  background: var(--sidebar-active-bg);
  color: var(--bs-primary);
  font-weight: 600;
}
.nav-item-sidebar i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.nav-item-sidebar.nav-logout {
  color: rgba(248, 113, 113, 0.75);
}
.nav-item-sidebar.nav-logout:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

/* ── 5. Main Content ────────────────────────────────────────────── */
#main {
  padding: calc(var(--topbar-height) + 1.25rem) 1rem 2.5rem;
  min-height: 100vh;
}

/* ── 6. Page Header ─────────────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--bs-body-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
.page-title i { color: var(--bs-primary); }

/* ── 7. Metric Cards ────────────────────────────────────────────── */
.metric-card {
  background: #fff;
  border-radius: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--bs-border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  height: 100%;
}

.metric-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.metric-icon.icon-green  { background: #dcfce7; color: #16a34a; }
.metric-icon.icon-blue   { background: #dbeafe; color: #1d4ed8; }
.metric-icon.icon-amber  { background: #fef3c7; color: #d97706; }
.metric-icon.icon-purple { background: #f3e8ff; color: #9333ea; }
.metric-icon.icon-slate  { background: #f1f5f9; color: #64748b; }

.metric-value {
  font-size: 1.625rem;
  font-weight: 800;
  line-height: 1;
  color: var(--bs-body-color);
}
.metric-label {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 0.2rem;
  font-weight: 500;
}

/* ── 8. Cards ───────────────────────────────────────────────────── */
.card { border: 1px solid var(--bs-border-color); }

.card-header {
  font-weight: 600;
  font-size: 0.875rem;
  background: #fff !important;
  color: var(--bs-body-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── 9. Tables ──────────────────────────────────────────────────── */
.table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
  font-weight: 600;
  white-space: nowrap;
  background: #f8fafc;
}
.table > :not(caption) > * > * { padding: 0.65rem 0.875rem; }

/* ── 10. Badges ─────────────────────────────────────────────────── */
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25em 0.6em;
  border-radius: 9999px;
}

/* ── 11. Search bar ─────────────────────────────────────────────── */
.search-wrapper { position: relative; }
.search-wrapper .search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  pointer-events: none;
  font-size: 0.9rem;
}
.search-wrapper .form-control { padding-left: 2.5rem; }

/* ── 12. User Cards (mobile list) ───────────────────────────────── */
.user-card {
  background: #fff;
  border-radius: 0.75rem;
  border: 1px solid var(--bs-border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  padding: 0.875rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 140ms, border-color 140ms;
  width: 100%;
}
.user-card:hover, .user-card:focus-within {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.09);
  border-color: #94a3b8;
  color: inherit;
}

.user-avatar {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: #dcfce7;
  color: #16a34a;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-avatar.onboarding {
  background: #fef3c7;
  color: #92400e;
}

.user-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.user-card-phone {
  font-size: 0.75rem;
  color: #64748b;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.user-card-meta { font-size: 0.75rem; color: #64748b; }

/* ── 13. Tabs ───────────────────────────────────────────────────── */
.nav-tabs {
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 0.125rem;
  border-bottom: 2px solid var(--bs-border-color);
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tabs .nav-link {
  white-space: nowrap;
  font-size: 0.85rem;
  font-weight: 500;
  color: #64748b;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 0.65rem 0.875rem;
  border-radius: 0.5rem 0.5rem 0 0;
  transition: color 140ms;
}
.nav-tabs .nav-link:hover {
  color: var(--bs-body-color);
  background: #f8fafc;
  border-bottom-color: transparent;
}
.nav-tabs .nav-link.active {
  color: var(--bs-primary);
  border-bottom-color: var(--bs-primary);
  background: transparent;
  font-weight: 600;
}
.nav-tabs .nav-link .badge {
  background: #e2e8f0;
  color: #64748b;
}
.nav-tabs .nav-link.active .badge {
  background: #dcfce7;
  color: #16a34a;
}

/* ── 14. Form improvements ──────────────────────────────────────── */
.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.form-control, .form-select {
  font-size: 0.875rem;
  border-color: var(--bs-border-color);
  border-radius: 0.5rem;
  min-height: 38px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.2);
}

/* BMI display pill */
.bmi-display {
  padding: 0.45rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 38px;
  display: flex;
  align-items: center;
}

/* ── 15. Progress bar ───────────────────────────────────────────── */
.progress { border-radius: 9999px; }
.progress-bar { background-color: var(--bs-primary); }

/* ── 16. WhatsApp Chat ──────────────────────────────────────────── */
.wa-window {
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c7bfb5' fill-opacity='0.25'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  border-radius: 0.75rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.wa-topbar {
  background: #075e54;
  color: #fff;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}
.wa-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #25d366;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700;
  flex-shrink: 0;
}
.wa-name { font-weight: 600; font-size: 0.95rem; line-height: 1.2; }
.wa-sub  { font-size: 0.72rem; opacity: 0.8; }

.wa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.wa-msg { display: flex; margin-bottom: 0.2rem; }
.wa-msg.from-user      { justify-content: flex-end; }
.wa-msg.from-assistant { justify-content: flex-start; }

.wa-bubble {
  position: relative;
  max-width: 75%;
  padding: 0.45rem 0.65rem 0.3rem;
  border-radius: 7.5px;
  font-size: 0.875rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.wa-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  width: 0; height: 0;
}
.from-user .wa-bubble {
  background: #d9fdd3;
  border-top-right-radius: 0;
  color: #111;
}
.from-user .wa-bubble::before {
  right: -8px;
  border-left: 8px solid #d9fdd3;
  border-bottom: 8px solid transparent;
}
.from-assistant .wa-bubble {
  background: #fff;
  border-top-left-radius: 0;
  color: #111;
}
.from-assistant .wa-bubble::before {
  left: -8px;
  border-right: 8px solid #fff;
  border-bottom: 8px solid transparent;
}
.wa-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 0.2rem;
  font-size: 0.68rem;
  color: #667781;
  white-space: nowrap;
}
.from-user .wa-ticks { color: #53bdeb; }

.wa-date-sep { text-align: center; margin: 0.6rem 0; }
.wa-date-sep span {
  background: #e1f3fb;
  color: #54656f;
  font-size: 0.72rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  display: inline-block;
}

/* ── 17. Memory badges ──────────────────────────────────────────── */
.memory-badge-alerta     { background: #fee2e2; color: #991b1b; }
.memory-badge-lesão      { background: #fee2e2; color: #991b1b; }
.memory-badge-preferência { background: #dbeafe; color: #1e40af; }
.memory-badge-progresso  { background: #dcfce7; color: #166534; }
.memory-badge-geral      { background: #f1f5f9; color: #475569; }

/* ── 18. Accordion (workout plan) ───────────────────────────────── */
.accordion-button {
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.875rem 1rem;
}
.accordion-button:not(.collapsed) { color: var(--bs-primary); }
.accordion-button:focus { box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.2); }
.accordion-button::after {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2364748b'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
}

/* ── 19. Breadcrumb ─────────────────────────────────────────────── */
.breadcrumb {
  font-size: 0.78rem;
  --bs-breadcrumb-divider-color: #94a3b8;
  --bs-breadcrumb-item-active-color: #64748b;
}
.breadcrumb-item + .breadcrumb-item::before { color: #94a3b8; }
.breadcrumb a { color: #64748b; text-decoration: none; }
.breadcrumb a:hover { color: var(--bs-primary); }

/* ── 20. Alert improvements ─────────────────────────────────────── */
.alert {
  font-size: 0.875rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.alert .alert-icon { flex-shrink: 0; margin-top: 0.05rem; }

/* ── 21. Desktop layout (≥992px) ────────────────────────────────── */
@media (min-width: 992px) {
  /* Hide mobile topbar */
  .mobile-topbar { display: none !important; }

  /* Always-visible sidebar (override Bootstrap Offcanvas JS) */
  .admin-sidebar {
    transform: none !important;
    visibility: visible !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    border-right: 1px solid rgba(255, 255, 255, 0.04) !important;
    z-index: 100 !important;
  }

  /* Hide backdrop on desktop */
  .offcanvas-backdrop { display: none !important; }

  /* Sidebar close btn only needed on mobile */
  .sidebar-close-btn { display: none !important; }

  /* Main content offset */
  #main {
    margin-left: var(--sidebar-width);
    padding: 2rem 2.5rem 3rem;
  }

  .page-title { font-size: 1.5rem; }
  .metric-value { font-size: 1.875rem; }

  /* Show table view, hide card list */
  .users-table-view { display: block !important; }
  .users-card-view  { display: none !important; }
}

/* ── 22. Mobile-only: card view for users ───────────────────────── */
.users-table-view { display: none; }
.users-card-view  { display: block; }

/* ── 23. Login page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1a2d45 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255,255,255,0.05);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 380px;
}
.login-logo {
  width: 4.5rem;
  height: 4.5rem;
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.25rem;
  margin: 0 auto 1.25rem;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.25);
}
.login-title {
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  color: #0f172a;
  margin-bottom: 0.25rem;
}
.login-subtitle {
  font-size: 0.8rem;
  text-align: center;
  color: #64748b;
  margin-bottom: 1.75rem;
}
.login-btn {
  background: var(--bs-primary);
  color: #fff;
  border: none;
  border-radius: 0.625rem;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
  transition: background 140ms, transform 80ms;
  letter-spacing: 0.02em;
  min-height: 48px;
}
.login-btn:hover  { background: #16a34a; }
.login-btn:active { transform: scale(0.985); }

/* ── 24. Refs page — legend ─────────────────────────────────────── */
.refs-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.78rem;
  color: #64748b;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.refs-legend .dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: middle;
}
.refs-legend .dot-green { background: #22c55e; }
.refs-legend .dot-amber { background: #f59e0b; }

/* ── 25. Utility helpers ────────────────────────────────────────── */
.font-mono { font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace; font-size: 0.85em; }
.text-muted-sm { font-size: 0.78rem; color: #64748b; }
.section-divider { border: none; border-top: 1px solid var(--bs-border-color); margin: 1.25rem 0; }
