/*
 * OrthoMetrics theme layer — canonical design tokens + brand font.
 * Loaded FIRST on every page (before page-specific <style> blocks and
 * ui-polish.css) so page styles can override; single source of truth
 * for colors, type, spacing, radii, and shadows.
 */

/* ---- Brand font: DM Sans (variable), self-hosted for CSP (font-src 'self') ---- */
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url('/fonts/DMSans-Variable-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Latin Extended — covers macrons for te reo Māori (ā ē ī ō ū) */
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url('/fonts/DMSans-Variable-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Brand */
  --primary: #1254a1;
  --primary-dark: #0e4488;
  --primary-light: #e8f0fb;
  --secondary: #1a7f5a;
  --secondary-light: #e3f5ed;
  --violet: #5e5ce6;

  /* Status */
  --danger: #ff3b30;
  --danger-bg: #fff0f0;
  --danger-border: rgba(255, 59, 48, 0.3);
  --warn: #ff9500;

  /* Neutrals */
  --bg: #f5f5f7;
  --border: rgba(0, 0, 0, 0.09);
  --gray-50: #f5f5f7;
  --gray-100: #e8e8ed;
  --gray-200: #d2d2d7;
  --gray-300: #b8b8bd;
  --gray-400: #86868b;
  --gray-500: #6e6e73;
  --gray-600: #3a3a3c;
  --gray-700: #2c2c2e;
  --gray-800: #1d1d1f;
  --gray-900: #111827;

  /* Surfaces + text */
  --card: #ffffff;
  --text: var(--gray-800);
  --muted: var(--gray-500);
  --overlay: rgba(0, 0, 0, 0.5);

  /* Semantic pairs */
  --ok-bg: #f0fdf4;
  --ok-color: #166534;
  --warn-bg: #fff7ed;
  --warn-color: #9a3412;
  --warn-text: #b45309;
  --demo-bg: #fff3cd;
  --demo-border: #f1c40f;
  --demo-color: #8a6d00;

  /* Soft status (banners, chips, badges) */
  --success-soft-bg: #d1fae5;
  --success-soft-text: #065f46;
  --warn-soft-bg: #fef3c7;
  --warn-soft-text: #92400e;
  --warn-strong: #fbbf24;
  --danger-soft-bg: #fee2e2;
  --danger-soft-text: #991b1b;
  --info-soft-bg: #dbeafe;
  --info-soft-text: #1e40af;

  /* Type scale */
  --text-xs: 11px;
  --text-sm: 12.5px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;

  /* Spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-pill: 980px;

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-pop: 0 12px 30px rgba(0, 0, 0, 0.14);
  --shadow-modal: 0 24px 80px rgba(15, 23, 42, 0.28);
  --focus-ring: 0 0 0 3px rgba(18, 84, 161, 0.25);
  --focus-soft: 0 0 0 4px rgba(18, 84, 161, 0.1);

  /* Fonts */
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-body);
}

/* Display type: DM Sans with tightened tracking (replaces the never-loaded Lora) */
h1, h2, h3 {
  letter-spacing: -0.02em;
}

/* ── App shell: dark header + grouped left sidebar + content column ── */
/* Sticky header keeps the sidebar's viewport maths exact: the sidebar is
   pinned below it and sized to the remaining height, so its footer (collapse
   control) is always on screen — previously the 100vh sidebar started below
   the in-flow header and its last 58px sat under the fold. */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
}
.app-body {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 58px);
}
.app-main {
  flex: 1 1 auto;
  min-width: 0;
}

.app-sidebar {
  width: 232px;
  flex: 0 0 auto;
  background: #fff;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  max-height: calc(100vh - 58px);
  align-self: flex-start;
  display: flex;
  flex-direction: column;
}
.app-sidebar-clinic {
  padding: var(--space-4) var(--space-4) 2px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--gray-800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-sidebar.is-collapsed .app-sidebar-clinic { display: none; }

.app-sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: var(--space-2) var(--space-2) var(--space-3);
}
.app-nav-group { padding-top: var(--space-1); }
.app-nav-group-bottom { margin-top: auto; }
.app-nav-group-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: var(--space-4) var(--space-3) 5px;
}
.app-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--gray-600);
  text-align: left;
  cursor: pointer;
  transition: background 0.13s ease, color 0.13s ease;
}
.app-nav-item + .app-nav-item { margin-top: 1px; }
.app-nav-item:hover { background: var(--gray-50); color: var(--gray-800); }
.app-nav-item.is-active {
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}
.app-nav-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.app-nav-item-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.8;
}
.app-nav-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar-foot {
  border-top: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  display: flex;
  justify-content: flex-end;
}
.app-sidebar-collapse {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--gray-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.app-sidebar-collapse:hover { background: var(--gray-50); color: var(--gray-700); }
.app-sidebar-collapse:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Collapsed icon rail (desktop only) */
.app-sidebar.is-collapsed { width: 64px; }
.app-sidebar.is-collapsed .app-nav-item-label,
.app-sidebar.is-collapsed .app-nav-group-label { display: none; }
.app-sidebar.is-collapsed .app-nav-item { justify-content: center; padding: 10px 0; }
.app-sidebar.is-collapsed .app-nav-group { padding-top: var(--space-3); }
.app-sidebar.is-collapsed .app-sidebar-foot { justify-content: center; }

/* Hamburger (dark header) — hidden on desktop */
.app-nav-toggle {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.app-nav-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.app-sidebar-backdrop { display: none; }

/* Mobile drawer: off-canvas via transform (keeps scrollWidth unchanged) */
@media (max-width: 900px) {
  .app-nav-toggle { display: flex; }
  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    width: 264px;
    z-index: 1200;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .app-sidebar.is-open {
    transform: none;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  }
  /* The collapse rail is a desktop affordance; drawers are always full width */
  .app-sidebar.is-collapsed { width: 264px; }
  .app-sidebar.is-collapsed .app-nav-item-label,
  .app-sidebar.is-collapsed .app-nav-group-label { display: block; }
  .app-sidebar.is-collapsed .app-nav-item { justify-content: flex-start; padding: 9px var(--space-3); }
  .app-sidebar-collapse { display: none; }
  .app-sidebar-backdrop.is-open {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 1199;
  }
}
