/* ============================================================
   FAIRSMILE DESIGN SYSTEM
   Apple-inspired, production-grade dental platform
   ============================================================ */

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

:root {
  /* Primary Palette */
  --blue: #0071e3;
  --blue-hover: #0062cc;
  --blue-active: #004ea3;
  --blue-light: #e1f0ff;
  --blue-subtle: #f0f7ff;

  /* Semantic Colors */
  --green: #30d158;
  --green-dark: #248a3d;
  --green-light: #e8faf0;
  --amber: #ff9f0a;
  --amber-dark: #c77c0a;
  --amber-light: #fff8eb;
  --red: #ff453a;
  --red-dark: #c93730;
  --red-light: #fff0ef;

  /* Neutral Scale — true Apple grays */
  --gray-50: #fbfbfd;
  --gray-100: #f5f5f7;
  --gray-150: #eeeff1;
  --gray-200: #e8e8ed;
  --gray-300: #d2d2d7;
  --gray-400: #aeaeb2;
  --gray-500: #86868b;
  --gray-600: #6e6e73;
  --gray-700: #48484a;
  --gray-800: #363638;
  --gray-900: #1d1d1f;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
    'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, monospace;

  /* Type Scale */
  --text-xs: 0.6875rem;    /* 11px */
  --text-sm: 0.8125rem;    /* 13px */
  --text-base: 0.9375rem;  /* 15px */
  --text-md: 1.0625rem;    /* 17px */
  --text-lg: 1.25rem;      /* 20px */
  --text-xl: 1.5rem;       /* 24px */
  --text-2xl: 1.75rem;     /* 28px */
  --text-3xl: 2rem;        /* 32px */
  --text-4xl: 2.5rem;      /* 40px */
  --text-5xl: 3rem;        /* 48px */
  --text-6xl: 3.5rem;      /* 56px */
  --text-hero: 4.5rem;     /* 72px */

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;
  --sp-24: 96px;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 24px;
  --r-pill: 100px;
  --r-full: 50%;

  /* Shadows — Apple depth system */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 8px -2px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 24px -4px rgba(0,0,0,.08), 0 4px 8px -2px rgba(0,0,0,.04);
  --shadow-xl: 0 24px 48px -8px rgba(0,0,0,.10), 0 8px 16px -4px rgba(0,0,0,.05);
  --shadow-2xl: 0 40px 80px -12px rgba(0,0,0,.14);
  --shadow-focus: 0 0 0 4px rgba(0,113,227,.25);
  --shadow-card: 0 0 0 1px rgba(0,0,0,.03), 0 2px 4px rgba(0,0,0,.04), 0 12px 24px rgba(0,0,0,.04);

  /* Transitions */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-spring: cubic-bezier(.175, .885, .32, 1.275);
  --t-fast: 150ms;
  --t-base: 250ms;
  --t-slow: 400ms;

  /* Z-index */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;
  --z-toast: 400;

  /* Layout */
  --container: 1200px;
  --container-sm: 680px;
  --container-xs: 480px;
  --nav-h: 52px;
}

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

body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--gray-900);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

#root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: var(--font); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Container --- */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}
.container-sm { max-width: var(--container-sm); }
.container-xs { max-width: var(--container-xs); }

/* --- Typography --- */
.heading-hero {
  font-size: var(--text-hero);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--gray-900);
}
.heading-1 {
  font-size: var(--text-5xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.heading-2 {
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.heading-3 {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.heading-4 {
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.4;
}
.text-lg { font-size: var(--text-lg); line-height: 1.5; }
.text-md { font-size: var(--text-md); line-height: 1.55; }
.text-sm { font-size: var(--text-sm); line-height: 1.5; }
.text-xs { font-size: var(--text-xs); line-height: 1.45; }
.text-muted { color: var(--gray-500); }
.text-secondary { color: var(--gray-600); }
.text-center { text-align: center; }
.text-blue { color: var(--blue); }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-weight: 500;
  font-size: var(--text-base);
  line-height: 1;
  border: none;
  border-radius: var(--r-pill);
  padding: 12px 24px;
  transition: all var(--t-base) var(--ease);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-sm { padding: 8px 18px; font-size: var(--text-sm); }
.btn-lg { padding: 16px 32px; font-size: var(--text-md); font-weight: 600; }
.btn-xl { padding: 18px 40px; font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.01em; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover {
  background: var(--blue-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,113,227,.35);
}
.btn-primary:active { background: var(--blue-active); transform: translateY(0); }

.btn-secondary {
  background: var(--gray-150);
  color: var(--gray-900);
}
.btn-secondary:hover {
  background: var(--gray-200);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--blue);
  box-shadow: inset 0 0 0 1.5px var(--blue);
}
.btn-outline:hover {
  background: var(--blue);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--blue);
}
.btn-ghost:hover { background: var(--blue-subtle); }

.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover {
  background: var(--green-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(48,209,88,.35);
}

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-dark); }

/* --- Cards --- */
.card {
  background: #fff;
  border-radius: var(--r-xl);
  padding: var(--sp-8);
  box-shadow: var(--shadow-card);
  transition: all var(--t-base) var(--ease);
}
.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.card-flat {
  background: #fff;
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  border: 1px solid var(--gray-200);
}
.card-glass {
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--r-xl);
  padding: var(--sp-8);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: var(--shadow-lg);
}

/* --- Forms --- */
.form-group { margin-bottom: var(--sp-5); }
.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: var(--sp-2);
  letter-spacing: 0.01em;
}
.form-input {
  width: 100%;
  padding: 12px 16px;
  font-size: var(--text-base);
  font-family: var(--font);
  color: var(--gray-900);
  background: #fff;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--r-md);
  transition: all var(--t-fast) var(--ease);
  appearance: none;
}
.form-input::placeholder { color: var(--gray-400); }
.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: var(--shadow-focus);
}
.form-input.error { border-color: var(--red); }
.form-error { color: var(--red); font-size: var(--text-xs); margin-top: var(--sp-1); }
textarea.form-input { min-height: 110px; resize: vertical; line-height: 1.6; }
select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386868b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.6;
}
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-green { background: var(--green-light); color: var(--green-dark); }
.badge-amber { background: var(--amber-light); color: var(--amber-dark); }
.badge-red { background: var(--red-light); color: var(--red-dark); }
.badge-gray { background: var(--gray-150); color: var(--gray-600); }

/* --- Spinner --- */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  display: inline-block;
}
.spinner-white { border-color: rgba(255,255,255,.3); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Responsive Grid --- */
.grid { display: grid; gap: var(--sp-6); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  :root {
    --text-hero: 2.75rem;
    --text-5xl: 2rem;
    --text-4xl: 1.75rem;
    --text-3xl: 1.5rem;
    --nav-h: 48px;
  }
  .container { padding: 0 var(--sp-4); }
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  top: calc(var(--nav-h) + 12px);
  right: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 14px 20px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-xl);
  animation: toastIn .3s var(--ease-spring);
  min-width: 280px;
}
.toast-success { background: var(--green-dark); }
.toast-error { background: var(--red); }
.toast-warning { background: var(--amber-dark); }
.toast-info { background: var(--blue); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

/* --- Modal / Overlay --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal);
  padding: var(--sp-6);
  animation: fadeIn .2s var(--ease);
}
.modal {
  background: #fff;
  border-radius: var(--r-2xl);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn .25s var(--ease-spring);
}
.modal-sm { max-width: 440px; }
.modal-md { max-width: 580px; }
.modal-lg { max-width: 780px; }
.modal-header {
  padding: var(--sp-6) var(--sp-8);
  border-bottom: 1px solid var(--gray-150);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body { padding: var(--sp-8); }
.modal-footer {
  padding: var(--sp-4) var(--sp-8) var(--sp-6);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  border: none;
  background: var(--gray-100);
  color: var(--gray-600);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast) var(--ease);
}
.modal-close:hover { background: var(--gray-200); color: var(--gray-900); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: scale(.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Popup Dialog (replaces alert/confirm) --- */
.popup-dialog {
  background: #fff;
  border-radius: var(--r-2xl);
  padding: var(--sp-10);
  max-width: 400px;
  width: 100%;
  text-align: center;
  animation: modalIn .25s var(--ease-spring);
}
.popup-icon {
  width: 56px; height: 56px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin: 0 auto var(--sp-5);
}
.popup-icon-success { background: var(--green-light); color: var(--green-dark); }
.popup-icon-error { background: var(--red-light); color: var(--red); }
.popup-icon-warning { background: var(--amber-light); color: var(--amber-dark); }
.popup-icon-info { background: var(--blue-light); color: var(--blue); }
.popup-icon-confirm { background: var(--blue-light); color: var(--blue); }

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: var(--sp-16) var(--sp-8);
}
.empty-icon {
  font-size: 56px;
  margin-bottom: var(--sp-5);
  opacity: .8;
}
.empty-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}
.empty-desc {
  font-size: var(--text-base);
  color: var(--gray-500);
  margin-bottom: var(--sp-6);
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

/* --- Section wrapper --- */
.section {
  padding: var(--sp-20) 0;
}
.section-sm {
  padding: var(--sp-12) 0;
}
.section-white {
  background: #fff;
}
.section-gray {
  background: var(--gray-100);
}
