/* ============================================================
   Bloom Platform - Main Design System
   Paediatric OT Practice Management Platform
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;0,600;1,300;1,400&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300;1,9..40,400&display=swap');

/* ── Design Tokens ────────────────────────────────────────── */
:root {
  /* Colours */
  --sage:      #6b9e72;
  --sage-d:    #4e7a55;
  --sage-l:    #b8d4bc;
  --sage-pale: #eef5ef;
  --ink:       #1e2420;
  --ink-m:     #3d4840;
  --ink-l:     #6b7570;
  --cream:     #f7f4f0;
  --white:     #fdfcfa;
  --border:    #ddd8d0;
  --gold:      #c4963a;
  --rust:      #b85c38;
  --rust-l:    #f9ede8;

  /* Typography */
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;
  --space-7:  48px;
  --space-8:  64px;

  /* Border radius */
  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(30,36,32,0.08);
  --shadow:    0 2px 8px rgba(30,36,32,0.10);
  --shadow-lg: 0 8px 24px rgba(30,36,32,0.12);

  /* Transitions */
  --transition: 180ms ease;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::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: 0.9375rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.375rem; }
h4 { font-size: 1.125rem; }

a {
  color: var(--sage-d);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--sage); }

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

button, input, select, textarea {
  font-family: var(--font-body);
  font-size: inherit;
}

/* ── Layout ───────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--space-4) 0;
}

.main-content {
  overflow-y: auto;
  padding: var(--space-6);
  background: var(--cream);
}

/* ── Brand / Logo ─────────────────────────────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-wordmark {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--sage-d);
  letter-spacing: 0.1em;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--ink-l);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Navigation ───────────────────────────────────────────── */
.nav-section {
  padding: var(--space-2) 0;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-l);
  padding: var(--space-3) var(--space-5) var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  color: var(--ink-m);
  font-size: 0.875rem;
  font-weight: 400;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  user-select: none;
}

.nav-item:hover {
  background: var(--sage-pale);
  color: var(--sage-d);
}

.nav-item.active {
  background: var(--sage-pale);
  color: var(--sage-d);
  border-left-color: var(--sage);
  font-weight: 500;
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--sage);
  color: var(--white);
}
.btn-primary:hover:not(:disabled) { background: var(--sage-d); }

.btn-secondary {
  background: var(--sage-pale);
  color: var(--sage-d);
}
.btn-secondary:hover:not(:disabled) { background: var(--sage-l); }

.btn-outline {
  background: transparent;
  color: var(--sage-d);
  border: 1.5px solid var(--sage-l);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--sage);
  background: var(--sage-pale);
}

.btn-danger {
  background: var(--rust-l);
  color: var(--rust);
}
.btn-danger:hover:not(:disabled) { background: var(--rust); color: var(--white); }

.btn-ghost {
  background: transparent;
  color: var(--ink-m);
}
.btn-ghost:hover:not(:disabled) { background: var(--sage-pale); color: var(--sage-d); }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 13px 28px;
  font-size: 1rem;
}

.btn-full { width: 100%; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  color: var(--ink);
}

/* ── Forms ────────────────────────────────────────────────── */
.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-m);
  margin-bottom: var(--space-1);
  letter-spacing: 0.01em;
}

.form-control {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
}
.form-control:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(107, 158, 114, 0.15);
}
.form-control.error {
  border-color: var(--rust);
  box-shadow: 0 0 0 3px rgba(184, 92, 56, 0.12);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--ink-l);
  margin-top: var(--space-1);
}

.form-error {
  font-size: 0.8125rem;
  color: var(--rust);
  margin-top: var(--space-1);
}

/* ── Alerts / Messages ────────────────────────────────────── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.alert-error {
  background: var(--rust-l);
  color: var(--rust);
  border: 1px solid rgba(184, 92, 56, 0.25);
}

.alert-success {
  background: var(--sage-pale);
  color: var(--sage-d);
  border: 1px solid var(--sage-l);
}

.alert-info {
  background: #f0f4fe;
  color: #3b5bdb;
  border: 1px solid #bfcffe;
}

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-green  { background: var(--sage-pale); color: var(--sage-d); }
.badge-gold   { background: #fdf5e4; color: var(--gold); }
.badge-rust   { background: var(--rust-l); color: var(--rust); }
.badge-grey   { background: #f0efed; color: var(--ink-l); }
.badge-blue   { background: #f0f4fe; color: #3b5bdb; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--sage-pale);
  color: var(--ink-m);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--sage-pale); }

tbody td {
  padding: var(--space-3) var(--space-4);
  color: var(--ink);
}

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

.page-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  color: var(--ink);
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--ink-l);
  margin-top: var(--space-1);
}

/* ── Stats Grid ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-l);
  margin-bottom: var(--space-2);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 500;
  color: var(--sage-d);
}

.stat-delta {
  font-size: 0.8125rem;
  color: var(--ink-l);
  margin-top: var(--space-1);
}

/* ── Notification Bell ────────────────────────────────────── */
.notif-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--ink-m);
  border-radius: var(--radius);
  transition: all var(--transition);
}
.notif-btn:hover { background: var(--sage-pale); color: var(--sage-d); }

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: var(--rust);
  color: white;
  border-radius: 50%;
  font-size: 0.625rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* ── Avatar ───────────────────────────────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--sage-l);
  color: var(--sage-d);
  font-size: 0.875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Loading / Skeleton ───────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--sage-pale) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius);
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--sage-l);
  border-top-color: var(--sage);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--ink-l);
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--ink-m);
  margin-bottom: var(--space-2);
}

/* ── Modals ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 36, 32, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
  backdrop-filter: blur(4px);
  animation: fade-in 150ms ease;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slide-up 200ms ease;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title {
  font-family: var(--font-display);
  font-size: 1.375rem;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1);
  color: var(--ink-l);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  line-height: 1;
  font-size: 1.25rem;
}
.modal-close:hover { background: var(--sage-pale); color: var(--sage-d); }

@keyframes fade-in  { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } }

/* ── Tab Strip ────────────────────────────────────────────── */
.tab-strip {
  display: flex;
  border-bottom: 2px solid var(--border);
  gap: 0;
  margin-bottom: var(--space-5);
}

.tab-btn {
  background: none;
  border: none;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--ink-l);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
  font-weight: 400;
}
.tab-btn:hover { color: var(--sage-d); }
.tab-btn.active {
  color: var(--sage-d);
  border-bottom-color: var(--sage);
  font-weight: 500;
}

/* ── Utilities ────────────────────────────────────────────── */
.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    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2       { gap: var(--space-2); }
.gap-3       { gap: var(--space-3); }
.gap-4       { gap: var(--space-4); }

.text-sm   { font-size: 0.875rem; }
.text-xs   { font-size: 0.75rem; }
.text-muted { color: var(--ink-l); }
.text-sage  { color: var(--sage-d); }
.text-rust  { color: var(--rust); }
.text-gold  { color: var(--gold); }

.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }

.w-full    { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Sidebar Toggle Button ────────────────────────────────── */
.sidebar-toggle-btn { display: none; }

/* ── Responsive ───────────────────────────────────────────── */

/* Tablet */
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 200px 1fr;
  }
  .main-content {
    padding: var(--space-4);
  }
}

/* Mobile */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
  }

  /* Sidebar: slide-over drawer on mobile */
  .sidebar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 800;
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
  }
  .sidebar.open { display: block; }

  /* Backdrop behind sidebar */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0,0,0,0.35);
    z-index: 799;
  }

  .main-content {
    grid-row: 2;
    padding: var(--space-3);
    overflow-x: auto;
    min-width: 0;
  }

  /* Page header: stack on mobile */
  .page-header {
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }
  .page-title { font-size: 1.5rem; }

  /* Stats grid: 2 cols on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }
  .stat-value { font-size: 1.5rem; }

  /* Cards: less padding */
  .card {
    padding: var(--space-3);
    border-radius: var(--radius);
  }

  /* Tables: ensure horizontal scroll */
  .table-wrapper { margin: 0 calc(-1 * var(--space-3)); }
  table { font-size: 0.8125rem; }
  thead th, tbody td { padding: var(--space-2) var(--space-3); }

  /* Tab strips: scrollable horizontally */
  .tab-strip, .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .tab-strip::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  .tab-btn, .tab { flex-shrink: 0; padding: var(--space-2) var(--space-3); font-size: 0.8125rem; }

  /* Buttons: slightly larger touch targets */
  .btn { padding: 10px 16px; min-height: 40px; }
  .btn-sm { padding: 8px 12px; min-height: 36px; }

  /* Forms: full width inputs */
  .form-control, .form-input { font-size: 16px; } /* Prevents iOS zoom on focus */

  /* Modals: full-width on mobile */
  .modal-overlay { padding: var(--space-2); align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 85vh;
    padding: var(--space-4);
  }

  /* Topbar adjustments */
  .topbar {
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }
  .sidebar-toggle-btn { display: flex !important; }
  .brand-wordmark { font-size: 1.2rem; }
  .brand-sub { display: none; }
  .user-menu-name { display: none; }
  .search-bar { max-width: none; }

  /* Notification dropdown: full width */
  .notif-dropdown {
    position: fixed;
    right: var(--space-2);
    left: var(--space-2);
    top: 56px;
    width: auto;
  }

  /* Empty state: less padding */
  .empty-state { padding: var(--space-5) var(--space-3); }

  /* Wizard steps: scroll */
  .wizard-steps { overflow-x: auto; flex-wrap: nowrap; }
  .wizard-step { min-width: 100px; flex-shrink: 0; }

  /* Rich text editor: less padding */
  .rte-area { min-height: 280px; padding: var(--space-3); }
}

  /* Force 2+ column inline grids to single column on mobile */
  [style*="grid-template-columns: 220px"],
  [style*="grid-template-columns:220px"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: 1fr 1fr !important;
  }
  /* Weekly schedule grid: keep 7 cols but allow overflow scroll */
  [style*="grid-template-columns:repeat(7"] {
    overflow-x: auto;
    min-width: 0;
  }
  /* Complex grids (invoice lines, billing) to single column */
  [style*="grid-template-columns:3fr"],
  [style*="grid-template-columns:2fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Patient profile: stack sidebar above content */
  [style*="grid-template-columns:220px 1fr"],
  [style*="grid-template-columns: 220px 1fr"] {
    grid-template-columns: 1fr !important;
    gap: var(--space-3) !important;
  }

  /* Patient sidebar photo card: horizontal on mobile */
  [style*="grid-template-columns:220px 1fr"] > div:first-child > .card:first-child {
    text-align: left !important;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
  }
  [style*="grid-template-columns:220px 1fr"] > div:first-child > .card:first-child > div:first-child {
    margin-bottom: 0 !important;
  }

  /* Patient sidebar info card: collapse empty space */
  [style*="grid-template-columns:220px 1fr"] > div:first-child {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
  }

  /* Settings page sidebar layout */
  [style*="max-width:820px"] {
    max-width: 100% !important;
  }
}

/* Small phone */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  h1, .page-title { font-size: 1.3rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.1rem; }
}
