/**
 * base.css — Reset + Global Styles + Layout
 *
 * Design principles:
 * - Orange brand top bar (app.fitcomfitness.com style)
 * - Apple whitespace and typography hierarchy
 * - Chinese text: line-height 1.7, min 14px
 * - Touch targets: min 48px height
 */

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

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);          /* 16px — never smaller */
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: var(--leading-relaxed);  /* 1.7 for Chinese readability */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: var(--text-base);  /* 16px prevents iOS zoom */
}

ul, ol {
  list-style: none;
}

/* ── Typography Hierarchy ── */
h1 { font-size: var(--text-3xl); font-weight: 700; line-height: var(--leading-tight); }
h2 { font-size: var(--text-2xl); font-weight: 600; line-height: var(--leading-tight); }
h3 { font-size: var(--text-xl);  font-weight: 600; line-height: var(--leading-tight); }
h4 { font-size: var(--text-lg);  font-weight: 600; line-height: var(--leading-normal); }

.text-sm { font-size: var(--text-sm); }  /* 14px — smallest allowed */
.text-lg { font-size: var(--text-lg); }
.text-2xl { font-size: var(--text-2xl); }

/* ── Screen Layout ── */
.screen {
  min-height: 100vh;
  min-height: 100dvh;  /* dynamic viewport for mobile */
}

#app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

#page-content {
  flex: 1;
  padding: var(--space-xl);
  overflow-y: auto;
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
}

/* ── Scrollbar (subtle, Apple-like) ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--bg-skeleton);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Utility Classes ── */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }
.text-center { text-align: center; }
.text-muted { color: var(--text-tertiary); }
.font-bold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }

/* ═══════════════════════════════════════════
   LOGIN SCREEN
   ═══════════════════════════════════════════ */
#login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fitcom-dark);
  background-image: linear-gradient(160deg, #262626 0%, #1A1A1A 100%);
}
.login-container {
  width: 100%;
  max-width: 420px;
  padding: var(--space-xl);
}
.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl) var(--space-xl);
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: var(--space-2xl);
}
.login-logo h1 {
  font-family: var(--font-heading);
  font-size: var(--text-4xl);
  color: var(--fitcom-orange);
  letter-spacing: 1px;
  margin-top: var(--space-md);
  line-height: 1;
}
.login-logo p {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--space-sm);
}
.login-btn {
  width: 100%;
  min-height: var(--touch-lg);   /* 56px — big, confident */
  font-size: var(--text-lg);
  font-weight: 600;
  margin-top: var(--space-md);
  border-radius: var(--radius-md);
}
.login-error {
  color: var(--danger);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-md);
  background: var(--danger-light);
  border-radius: var(--radius-md);
}

/* ═══════════════════════════════════════════
   TOP BAR — Orange Brand Bar (app.fitcom style)
   ═══════════════════════════════════════════ */
#header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  background: var(--bg-topbar);    /* ← ORANGE brand bar */
  color: var(--text-inverse);
  flex-shrink: 0;
  z-index: 100;
}
.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.header-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-inverse);
}
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.header-branch-select {
  width: auto;
  min-width: 160px;
  min-height: 36px;
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.15);
  color: var(--text-inverse);
  border: 1px solid rgba(255,255,255,0.2);
}
.header-branch-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}
.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.header-user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: rgba(255,255,255,0.9);
}
/* Override button colors inside orange header */
#header .btn-ghost {
  color: rgba(255,255,255,0.8);
}
#header .btn-ghost:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text-inverse);
}
#header .avatar {
  background: rgba(255,255,255,0.2);
  color: var(--text-inverse);
  border: 2px solid rgba(255,255,255,0.3);
}

/* ═══════════════════════════════════════════
   SIDEBAR — Dark, Icon + Text
   ═══════════════════════════════════════════ */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 200;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-xl) var(--space-lg);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  color: var(--fitcom-orange);
  letter-spacing: 0.5px;
  line-height: 1;
}
.sidebar-nav {
  flex: 1;
  padding: var(--space-lg) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-md);  /* taller for touch */
  min-height: var(--touch-min);               /* 48px min */
  border-radius: var(--radius-md);
  color: rgba(255,255,255,0.55);
  font-size: var(--text-base);                /* 16px — not smaller */
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
}
.sidebar-item:hover {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.06);
}
.sidebar-item.active {
  color: var(--fitcom-orange);
  background: rgba(246, 146, 30, 0.12);
}
.sidebar-item svg {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  opacity: 0.6;
}
.sidebar-item:hover svg {
  opacity: 0.9;
}
.sidebar-item.active svg {
  opacity: 1;
  stroke: var(--fitcom-orange);
}
.sidebar-footer {
  padding: var(--space-lg);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.sidebar-footer span {
  font-size: var(--text-sm);
  color: rgba(255,255,255,0.3);
}

/* ═══════════════════════════════════════════
   BOTTOM NAV — Mobile (Grab-style: big, clear)
   ═══════════════════════════════════════════ */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 900;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.bottom-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-sm) var(--space-md);
  font-size: 11px;                            /* tab label only — decorative, not content */
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
  min-width: 64px;
  min-height: var(--touch-min);               /* 48px touch target */
  -webkit-tap-highlight-color: transparent;
}
.bottom-tab.active {
  color: var(--fitcom-orange);
}
.bottom-tab svg {
  width: 24px;
  height: 24px;
}

/* ═══════════════════════════════════════════
   MODULE TABS — Sub-navigation within a module
   ═══════════════════════════════════════════ */
.module-tabs {
  display: flex;
  gap: var(--space-sm);
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.module-tabs::-webkit-scrollbar { display: none; }
.module-tab {
  padding: var(--space-md) var(--space-lg);
  min-height: var(--touch-min);               /* 48px touch target */
  display: flex;
  align-items: center;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-tertiary);
  text-decoration: none;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.module-tab:hover {
  color: var(--text-primary);
}
.module-tab.active {
  color: var(--fitcom-orange);
  border-bottom-color: var(--fitcom-orange);
  font-weight: 600;
}

/* ═══════════════════════════════════════════
   PAGE HEADER — Section title + action button
   ═══════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════
   MOBILE / DESKTOP VISIBILITY
   ═══════════════════════════════════════════ */
.mobile-only { display: none; }

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }

  #sidebar { display: none; }

  #header {
    padding: 0 var(--space-md);
  }

  #page-content {
    padding: var(--space-md);
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + var(--space-lg));
  }

  .header-user-name { display: none; }
  .header-branch-select { min-width: 120px; font-size: var(--text-sm); }

  .page-header { flex-direction: column; align-items: flex-start; gap: var(--space-md); }
}

@media (min-width: 769px) {
  #bottom-nav { display: none !important; }
}

/* Tablet: collapsed sidebar (icons only) */
@media (min-width: 769px) and (max-width: 1023px) {
  #sidebar { width: var(--sidebar-collapsed); }
  .sidebar-item span { display: none; }
  .sidebar-brand { display: none; }
  .sidebar-logo { justify-content: center; padding: var(--space-lg) var(--space-sm); }
  .sidebar-item { justify-content: center; padding: var(--space-md) var(--space-sm); }
  .sidebar-nav { padding: var(--space-lg) var(--space-xs); }
}
