/* ═══════════════════════════════════════════════════════════
   BuildOS — Main CSS
   Design System: Tokens, Reset, Typography, Layout
═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── CSS Custom Properties (iOS Human Interface Guidelines) ─── */
:root {
  /* Brand & System Colors - iOS System Blue */
  --clr-primary:       #007AFF;
  --clr-primary-800:   #0051A8;
  --clr-primary-700:   #0062CC;
  --clr-primary-600:   #0071E3;
  --clr-primary-400:   #5AC8FA;
  --clr-primary-200:   #B8E2FB;
  --clr-primary-100:   #E1F3FE;
  --clr-primary-50:    #F0F8FF;

  /* Accent - Apple System Blue */
  --clr-accent:        #007AFF;
  --clr-accent-dark:   #0056B3;
  --clr-accent-light:  #F2F8FF;
  --clr-accent-100:    #E5F2FF;

  /* Semantic - iOS System Palette */
  --clr-success:       #34C759;
  --clr-success-light: #EBF9EE;
  --clr-success-100:   #D4F4DA;

  --clr-warning:       #FF9500;
  --clr-warning-light: #FFF7EC;
  --clr-warning-100:   #FFECCC;

  --clr-danger:        #FF3B30;
  --clr-danger-light:  #FFEDED;
  --clr-danger-100:    #FFD5D2;

  --clr-info:          #5856D6;
  --clr-info-light:    #F2F1FC;
  --clr-info-100:      #E4E3F9;

  /* Surfaces - iOS Grouped System */
  --clr-bg:            #F2F2F7;
  --clr-surface:       #FFFFFF;
  --clr-surface-2:     #F8F8FC;
  --clr-border:        rgba(60, 60, 67, 0.12);
  --clr-border-strong: rgba(60, 60, 67, 0.22);

  /* Text - iOS Label System */
  --clr-text-primary:   #000000;
  --clr-text-secondary: #3C3C43;
  --clr-text-muted:     #8E8E93;
  --clr-text-inverse:   #FFFFFF;

  /* Sidebar - iPadOS Materials */
  --sidebar-width:     245px;
  --sidebar-bg:        rgba(246, 246, 248, 0.94);
  --sidebar-text:      #636366;
  --sidebar-text-active: #007AFF;
  --sidebar-accent:    #007AFF;
  --topbar-height:     56px;

  /* Typography - Apple SF Pro Stack */
  --font-family:   -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "SF Pro", "Helvetica Neue", Helvetica, Inter, sans-serif;
  --font-mono:     "SF Mono", Menlo, Monaco, Consolas, "JetBrains Mono", monospace;

  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.8125rem;  /* 13px */
  --text-base: 0.875rem;   /* 14px */
  --text-md:   0.9375rem;  /* 15px */
  --text-lg:   1rem;       /* 16px */
  --text-xl:   1.125rem;   /* 18px */
  --text-2xl:  1.25rem;    /* 20px */
  --text-3xl:  1.5rem;     /* 24px */
  --text-4xl:  1.875rem;   /* 30px */

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius - iOS Squircle Curves */
  --radius-sm:  8px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;
  --radius-2xl: 22px;
  --radius-full: 100px;

  /* Shadows - Apple Diffuse Ambient Lighting */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);

  /* Transitions - Apple Spring / Cubic Ease */
  --transition-fast:   120ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-base:   200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slow:   300ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slower: 400ms cubic-bezier(0.25, 0.1, 0.25, 1);

  /* Z-index stack */
  --z-base:     0;
  --z-raised:   10;
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  300;
  --z-modal:    400;
  --z-toast:    500;
  --z-tooltip:  600;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  color: var(--clr-text-primary);
  background-color: var(--clr-bg);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

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

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

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

ul, ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  width: 100%;
}

/* ─── App Shell ─────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  z-index: var(--z-sticky);
  transition: width var(--transition-slow), min-width var(--transition-slow);
}

#sidebar.collapsed {
  width: 56px;
  min-width: 56px;
}

/* Main area */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Topbar - iOS Frosted Navigation Bar */
#topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: var(--z-sticky);
  position: sticky;
  top: 0;
}

/* Content */
#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6);
  background: var(--clr-bg);
}

/* ─── Typography ─────────────────────────────────────────── */
h1 { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.025em; }
h2 { font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.015em; }
h3 { font-size: var(--text-xl);  font-weight: 600; }
h4 { font-size: var(--text-lg);  font-weight: 600; }
h5 { font-size: var(--text-base); font-weight: 600; }
h6 { font-size: var(--text-sm);  font-weight: 600; }

.text-xs     { font-size: var(--text-xs); }
.text-sm     { font-size: var(--text-sm); }
.text-base   { font-size: var(--text-base); }
.text-md     { font-size: var(--text-md); }
.text-lg     { font-size: var(--text-lg); }
.text-xl     { font-size: var(--text-xl); }
.text-2xl    { font-size: var(--text-2xl); }

.font-medium  { font-weight: 500; }
.font-semibold{ font-weight: 600; }
.font-bold    { font-weight: 700; }

.text-primary   { color: var(--clr-text-primary); }
.text-secondary { color: var(--clr-text-secondary); }
.text-muted     { color: var(--clr-text-muted); }
.text-accent    { color: var(--clr-accent); }
.text-success   { color: var(--clr-success); }
.text-warning   { color: var(--clr-warning); }
.text-danger    { color: var(--clr-danger); }
.text-info      { color: var(--clr-info); }

/* ─── Layout Utilities ───────────────────────────────────── */
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.flex-wrap     { flex-wrap: wrap; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.items-end     { align-items: flex-end; }
.justify-start { justify-content: flex-start; }
.justify-end   { justify-content: flex-end; }
.justify-center{ justify-content: center; }
.justify-between{ justify-content: space-between; }
.gap-1  { gap: var(--space-1); }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.gap-8  { gap: var(--space-8); }
.flex-1 { flex: 1; }
.min-w-0{ min-width: 0; }

.grid { display: grid; }
.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); }

.w-full { width: 100%; }
.h-full { height: 100%; }
.hidden { display: none !important; }
.block  { display: block; }
.relative { position: relative; }
.absolute { position: absolute; }
.overflow-hidden { overflow: hidden; }

/* Spacing utilities */
.p-0  { padding: 0; }
.p-2  { padding: var(--space-2); }
.p-3  { padding: var(--space-3); }
.p-4  { padding: var(--space-4); }
.p-6  { padding: var(--space-6); }
.p-8  { padding: var(--space-8); }
.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.px-6 { padding-left: var(--space-6); padding-right: var(--space-6); }
.py-1 { padding-top: var(--space-1); padding-bottom: var(--space-1); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.pt-4 { padding-top: var(--space-4); }
.pb-4 { padding-bottom: var(--space-4); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

/* ─── Page Header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--clr-text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--clr-text-muted);
  margin-top: var(--space-1);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ─── Section ────────────────────────────────────────────── */
.section {
  margin-bottom: var(--space-8);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.section-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--clr-text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}


/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--clr-border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--clr-primary-400);
}

/* ─── Focus Styles ───────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--clr-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ─── Selection ──────────────────────────────────────────── */
::selection {
  background: var(--clr-accent-100);
  color: var(--clr-primary);
}

/* ─── Loading States ─────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--clr-border) 25%, var(--clr-primary-50) 50%, var(--clr-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* ─── Count-up animation ─────────────────────────────────── */
.count-up {
  transition: all var(--transition-slow);
}

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

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

.animate-fade-in    { animation: fadeIn var(--transition-slow) ease forwards; }
.animate-slide-in   { animation: slideInRight var(--transition-slow) ease forwards; }
.animate-scale-in   { animation: scaleIn var(--transition-slow) ease forwards; }
.animate-pulse      { animation: pulse 2s ease-in-out infinite; }
.animate-spin       { animation: spin 1s linear infinite; }

/* Staggered fade-in for list items */
.stagger-children > * {
  opacity: 1;
  animation: fadeIn 0.3s ease forwards;
}
.stagger-children > *:nth-child(1)  { animation-delay: 0ms; }
.stagger-children > *:nth-child(2)  { animation-delay: 40ms; }
.stagger-children > *:nth-child(3)  { animation-delay: 80ms; }
.stagger-children > *:nth-child(4)  { animation-delay: 120ms; }
.stagger-children > *:nth-child(5)  { animation-delay: 160ms; }
.stagger-children > *:nth-child(6)  { animation-delay: 200ms; }
.stagger-children > *:nth-child(7)  { animation-delay: 240ms; }
.stagger-children > *:nth-child(8)  { animation-delay: 280ms; }

/* ─── Divider ────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--clr-border);
  margin: var(--space-4) 0;
}

/* ─── Progress Bar ───────────────────────────────────────── */
.progress-bar-wrapper {
  height: 6px;
  background: var(--clr-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--clr-accent);
  transition: width var(--transition-slower) ease;
}

.progress-bar.success { background: var(--clr-success); }
.progress-bar.warning { background: var(--clr-warning); }
.progress-bar.danger  { background: var(--clr-danger); }
.progress-bar.info    { background: var(--clr-info); }

/* ─── Status Dot ─────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.active, .status-dot.success { background: var(--clr-success); }
.status-dot.warning, .status-dot.pending { background: var(--clr-warning); }
.status-dot.danger, .status-dot.error  { background: var(--clr-danger); }
.status-dot.info                        { background: var(--clr-info); }
.status-dot.muted                       { background: var(--clr-text-muted); }

/* ─── Avatar ─────────────────────────────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--clr-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: var(--text-xs);
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: var(--text-lg);
}

/* ─── Tooltip ────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--clr-primary);
  color: white;
  font-size: var(--text-xs);
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: var(--z-tooltip);
}

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

/* ─── Currency / Number ──────────────────────────────────── */
.currency {
  font-feature-settings: 'tnum' 1;
  font-variant-numeric: tabular-nums;
}

/* ─── Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
