/* ─────────────────────────────────────────────────────────────────────────────
   main.css
   Global styles, design system tokens, layout, and base element styles.
   This file is loaded on every page of The Foundry.
───────────────────────────────────────────────────────────────────────────── */


/* ── CSS Custom Properties (Design Tokens) ───────────────────────────────── */
/* Think of these as the "settings" for the entire design system.
   Change a value here and it updates everywhere it's used. */

:root {
  /* Colors */
  --color-background:       #F5F5F7;
  --color-card:             rgba(255, 255, 255, 0.72);
  --color-card-border:      rgba(255, 255, 255, 0.6);
  --color-primary:          #0071E3;
  --color-primary-hover:    #0062C4;
  --color-primary-light:    rgba(0, 113, 227, 0.1);
  --color-error:            #FF3B30;
  --color-error-light:      rgba(255, 59, 48, 0.1);
  --color-success:          #34C759;
  --color-success-light:    rgba(52, 199, 89, 0.1);
  --color-warning:          #FF9500;
  --color-warning-light:    rgba(255, 149, 0, 0.1);
  --color-text-primary:     #1D1D1F;
  --color-text-secondary:   #6E6E73;
  --color-text-tertiary:    #AEAEB2;
  --color-border:           rgba(0, 0, 0, 0.08);
  --color-divider:          rgba(0, 0, 0, 0.06);
  --color-sidebar:          rgba(255, 255, 255, 0.72);
  --color-overlay:          rgba(0, 0, 0, 0.4);

  /* Status colors (for user presence indicators) */
  --status-available:       #34C759;
  --status-busy:            #FF3B30;
  --status-meeting:         #FF9500;
  --status-custom:          #6E6E73;

  /* Typography */
  --font-family:            -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --font-size-xs:           12px;
  --font-size-sm:           13px;
  --font-size-base:         15px;
  --font-size-md:           16px;
  --font-size-lg:           18px;
  --font-size-xl:           22px;
  --font-size-2xl:          28px;
  --font-size-3xl:          34px;
  --font-weight-regular:    400;
  --font-weight-medium:     500;
  --font-weight-semibold:   600;
  --font-weight-bold:       700;
  --line-height-tight:      1.2;
  --line-height-normal:     1.5;
  --line-height-loose:      1.7;

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

  /* Border radius */
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    18px;
  --radius-xl:    24px;
  --radius-full:  980px;
  --radius-round: 50%;

  /* Shadows */
  --shadow-sm:    0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-md:    0 2px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg:    0 4px 40px rgba(0, 0, 0, 0.12);
  --shadow-card:  0 2px 20px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.8);

  /* Transitions */
  --transition-fast:    100ms ease-in-out;
  --transition-base:    200ms ease-in-out;
  --transition-slow:    300ms ease-in-out;

  /* Layout */
  --sidebar-width:        240px;
  --content-max-width:    1100px;
  --content-padding:      var(--space-6);
  --bottom-nav-height:    72px;
  --header-height:        64px;
}


/* ── Reset & Base Styles ─────────────────────────────────────────────────── */

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

html {
  /* Prevent text size adjustments on orientation change (iOS) */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Smooth scrolling when anchors are used */
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-background);
  /* Safe area insets for iOS (notch, home indicator) */
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  /* Prevent overscroll bounce on iOS (keeps the app feel) */
  overscroll-behavior: none;
  /* Better text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Remove default button and input styles so we control them fully */
button,
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

/* Remove default list styles (we add our own when needed) */
ul,
ol {
  list-style: none;
}

/* Links default to inherit color — we style them explicitly where needed */
a {
  color: inherit;
  text-decoration: none;
}

/* Images fill their container and don't overflow */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Prevent horizontal scroll on the whole page */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}


/* ── Typography Scale ────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  letter-spacing: -0.2px;
}

h1 { font-size: var(--font-size-3xl); letter-spacing: -0.5px; }
h2 { font-size: var(--font-size-2xl); letter-spacing: -0.4px; }
h3 { font-size: var(--font-size-xl); letter-spacing: -0.3px; }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-md); }
h6 { font-size: var(--font-size-base); }

p {
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
}

.text-secondary {
  color: var(--color-text-secondary);
}

.text-tertiary {
  color: var(--color-text-tertiary);
}

.text-sm {
  font-size: var(--font-size-sm);
}

.text-xs {
  font-size: var(--font-size-xs);
}

.text-center {
  text-align: center;
}

.font-medium {
  font-weight: var(--font-weight-medium);
}

.font-semibold {
  font-weight: var(--font-weight-semibold);
}


/* ── Dashboard Layout ────────────────────────────────────────────────────── */
/* This is the main two-column layout:
   Left sidebar (fixed) + Right content area (scrollable) on desktop.
   On mobile: bottom navigation + full-width content area. */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar (desktop) ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — accounts for mobile browser bars */
  background: var(--color-sidebar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  /* The sidebar slides in from the left when the app loads */
  transform: translateX(0);
  transition: transform var(--transition-slow);
  /* Safe area padding for notch phones in landscape */
  padding-left: env(safe-area-inset-left);
}

/* ── Main content area ── */
.main-content {
  /* Push the content to the right of the sidebar */
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Content scrolls independently of the sidebar */
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Content inner area (padding and max width) ── */
.content-area {
  flex: 1;
  padding: var(--content-padding);
  max-width: var(--content-max-width);
  width: 100%;
}

/* ── Page header (title + action button row) ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}

.page-header-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: -0.4px;
}

/* ── Mobile layout overrides ── */
@media (max-width: 767px) {
  /* Hide the sidebar on mobile */
  .sidebar {
    display: none;
  }

  /* Content takes up the full width on mobile */
  .main-content {
    margin-left: 0;
    /* Leave space at the bottom for the tab bar */
    padding-bottom: var(--bottom-nav-height);
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  }

  .content-area {
    padding: var(--space-4);
  }

  .page-header-title {
    font-size: var(--font-size-xl);
  }
}

/* ── Tablet layout ── */
@media (min-width: 768px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
  }

  .content-area {
    padding: var(--space-5);
  }
}


/* ── Bottom Tab Navigation (mobile only) ─────────────────────────────────── */

.bottom-nav {
  display: none; /* hidden on desktop — shown on mobile via media query below */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  /* Add extra height for the iOS home indicator */
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-sidebar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--color-border);
  z-index: 100;
}

.bottom-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 72px; /* fixed height so it doesn't squish with safe area padding */
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  padding: 8px 4px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--color-text-tertiary);
  transition: color var(--transition-base);
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.bottom-nav-item i {
  font-size: 22px;
}

.bottom-nav-item.active {
  color: var(--color-primary);
}

@media (max-width: 767px) {
  .bottom-nav {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }
}


/* ── Sidebar Internal Layout ─────────────────────────────────────────────── */

.sidebar-header {
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.sidebar-wordmark {
  font-size: 20px;
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  letter-spacing: -0.4px;
}

.sidebar-wordmark span {
  color: var(--color-primary);
}

/* User info block at top of sidebar */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-base);
  margin: var(--space-2) var(--space-2);
}

.sidebar-user:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.sidebar-user-info {
  flex: 1;
  min-width: 0; /* allows text to truncate properly */
}

.sidebar-user-name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  /* Truncate long names with "..." */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-status {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Navigation links list */
.sidebar-nav {
  flex: 1;
  padding: var(--space-2) var(--space-2);
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: background-color var(--transition-base), color var(--transition-base);
  position: relative;
}

.nav-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
  color: var(--color-text-primary);
}

.nav-item.active {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
}

.nav-item i {
  font-size: 18px;
  flex-shrink: 0;
}

.nav-item-label {
  flex: 1;
}

/* Badge on nav items (e.g., unread message count) */
.nav-badge {
  background-color: var(--color-error);
  color: white;
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Bottom section of sidebar (notifications, settings, sign out) */
.sidebar-footer {
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-footer-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: background-color var(--transition-base), color var(--transition-base);
}

.sidebar-footer-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
  color: var(--color-text-primary);
}

/* Sign out button gets error color on hover */
.sidebar-footer-item.sign-out:hover {
  background-color: var(--color-error-light);
  color: var(--color-error);
}

.sidebar-footer-item i {
  font-size: 18px;
}


/* ── Section Content Fade ────────────────────────────────────────────────── */
/* The content area fades in when sections are switched */

.section-content {
  animation: fadeIn 200ms ease;
}


/* ── Grid Layouts ────────────────────────────────────────────────────────── */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 767px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}


/* ── Utility Classes ─────────────────────────────────────────────────────── */

/* Visually hidden — accessible to screen readers but not visible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* 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-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }

/* Spacing utilities */
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* Overflow utilities */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cursor utilities */
.cursor-pointer { cursor: pointer; }

/* Display utilities */
.hidden { display: none !important; }


/* ── Scrollbar Styling ───────────────────────────────────────────────────── */
/* Custom scrollbar — thin and subtle, matching the app's clean aesthetic */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}


/* ── Focus styles ────────────────────────────────────────────────────────── */
/* Visible focus rings for keyboard navigation (accessibility) */

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Remove focus ring for mouse users (it shows only on keyboard navigation) */
:focus:not(:focus-visible) {
  outline: none;
}


/* ── Selection color ─────────────────────────────────────────────────────── */

::selection {
  background-color: rgba(0, 113, 227, 0.2);
  color: var(--color-text-primary);
}


/* ── Loading Spinner ─────────────────────────────────────────────────────── */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.spinner-dark {
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ── Empty State ─────────────────────────────────────────────────────────── */
/* Used when a section has no data to display */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  gap: var(--space-3);
}

.empty-state-icon {
  font-size: 48px;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-2);
}

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

.empty-state-message {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  max-width: 280px;
  line-height: var(--line-height-normal);
}


/* ── Profile Panel (slide-out) ───────────────────────────────────────────── */

.profile-panel-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}

.profile-panel-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.profile-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform var(--transition-slow);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.profile-panel.open {
  transform: translateX(0);
}

/* On mobile, the profile panel slides up from the bottom */
@media (max-width: 767px) {
  .profile-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 90vh;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
  }

  .profile-panel.open {
    transform: translateY(0);
  }
}

.profile-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.profile-panel-header h2 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.profile-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 22px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-base);
}

.profile-panel-close:hover {
  color: var(--color-text-primary);
}

.profile-panel-body {
  padding: var(--space-5);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
