/* ============================================================
   BluPrnts V5 — Master Stylesheet
   Design system foundation: tokens, typography, components
   ----------------------------------------------------------------
   Phase 3.2: this file is the SINGLE SOURCE OF TRUTH for brand
   tokens. Do not redefine --forest, --copper, --cream, --dark-*
   etc. in any other file (.html templates, inline styles in
   index.js). If a value needs to change, change it HERE; every
   surface inherits via var(--…). The dark token values below
   match the production console (formerly redefined inline).
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* ── Brand palette (official BluPrnts Brand Guidelines 2025) ──
     Canonical hexes. Token NAMES kept for backward compat; VALUES
     repointed to the brand guide + the Figma Make "Realto+Lumos"
     direction (file pNKQeX5BIsWLGq6QFnDrMP). */
  --cream:         #F2EFE8;   /* Cream — light backgrounds */
  --sand:          #EDE7DB;   /* surface tint (slightly warm) */
  --sand-2:        #E6DDD1;   /* deeper surface tint */
  --sand-accent:   #C8B99A;   /* Warm Sand — secondary/warmth accent */
  --white:         #FFFFFF;
  --charcoal:      #1C1C1C;
  --stone:         #6B6460;
  --dust:          #A09890;
  --forest:        #2C3E32;   /* Forest Navy — primary */
  --forest-mid:    #3D5547;
  --forest-light:  #4A7A5A;
  --forest-mist:   rgba(44,62,50,0.07);
  --forest-mist-2: rgba(44,62,50,0.12);
  --powder:        #A8C5DA;   /* Powder Blue — accents/highlights */
  --powder-mist:   rgba(168,197,218,0.16);
  --botanical:     #5E8C4A;   /* Botanical — CTAs, success */
  --botanical-mist:rgba(94,140,74,0.12);
  --amber:         #C4883A;   /* warm glow accent (canvas) */
  --red:           #C0392B;
  --green-confirm: #5E8C4A;   /* alias → botanical */

  /* Deprecated (retired copper/steel direction). Repointed to brand
     so any stray legacy reference renders on-brand, not orange. */
  --copper:        #5E8C4A;   /* was #B5674D — now botanical */
  --copper-mist:   rgba(94,140,74,0.10);
  --steel:         #A8C5DA;   /* was #7BA9BC — now powder blue */
  --steel-mist:    rgba(168,197,218,0.16);

  /* ── Warm gradient canvas (Make "Realto+Lumos") ──────────────
     Cream base with an amber glow top-right and a soft powder-blue
     glow bottom-left. Apply as `background: var(--canvas)` on body. */
  --canvas:
    radial-gradient(1100px 700px at 100% 0%,  rgba(196,136,58,0.14), transparent 60%),
    radial-gradient(1000px 800px at 0% 100%,  rgba(168,197,218,0.20), transparent 60%),
    var(--cream);

  /* Glassmorphism Design Tokens */
  --glass-bg:           rgba(255, 255, 255, 0.62);
  --glass-border:       rgba(255, 255, 255, 0.55);
  --glass-blur:         18px;
  --glass-bg-dark:      rgba(17, 31, 24, 0.7);
  --glass-border-dark:  rgba(255, 255, 255, 0.08);

  /* Shadows (Apple-style layered soft-depth shadows) */
  --shadow-xs: 0 1px 2px rgba(28,28,28,0.02);
  --shadow-sm: 0 2px 8px rgba(45,74,62,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --shadow-md: 0 10px 24px -6px rgba(45,74,62,0.06), 0 2px 6px rgba(0,0,0,0.02);
  --shadow-lg: 0 20px 48px -10px rgba(45,74,62,0.1), 0 4px 16px rgba(0,0,0,0.03);
  --shadow-xl: 0 32px 64px -12px rgba(45,74,62,0.15);

  /* Blueprint grid texture */
  --blueprint-grid: repeating-linear-gradient(
    0deg, transparent, transparent 39px,
    rgba(45,74,62,0.04) 39px, rgba(45,74,62,0.04) 40px
  ), repeating-linear-gradient(
    90deg, transparent, transparent 39px,
    rgba(45,74,62,0.04) 39px, rgba(45,74,62,0.04) 40px
  );

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

  /* Dark mode (console) — values aligned to production console.html
     in Phase 3.2. Was: void #08120D, surface #0E1B15, surface-2
     #14251E (speculative, never shipped). Now: matches the dark
     console that's been in production. */
  --dark-void:      #0A1A11;
  --dark-surface:   #0E2218;
  --dark-surface-2: #132A1D;
  --dark-surface-3: #1A3127;
  --dark-border:    rgba(255,255,255,0.07);
  --dark-text:      #F4EFE6;
  --dark-text-2:    #8A9E8E;
  --dark-green:     #5E9A6E;        /* aka --green-bright */
  --dark-green-dim: rgba(94,154,110,0.12);
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--canvas);
  background-attachment: fixed;
  color: var(--charcoal);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.blueprint-bg {
  background-image: var(--blueprint-grid);
}

/* Display headlines — Bebas Neue */
.display {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.02em;
  line-height: 0.95;
}

/* Elegant subheads — DM Serif Display */
.serif {
  font-family: 'DM Serif Display', serif;
}

/* Mono — codes, IDs, numbers */
.mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Section labels */
.label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dust);
}

/* ── Card System ────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-md);
  padding: 24px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.glass-card:hover {
  box-shadow: var(--shadow-md);
  background: rgba(255, 255, 255, 0.75);
}

.squircle {
  border-radius: var(--radius-lg);
}

.card-sand {
  background: var(--sand);
  border-radius: var(--radius-md);
  padding: 24px;
}

.card-accent {
  border-left: 4px solid var(--forest);
}

.card-copper {
  border-left: 3px solid var(--copper);
}

/* ── Button System ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.9375rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  height: 52px;
  padding: 0 28px;
  background: var(--forest);
  color: #fff;
}
.btn-primary:hover {
  background: var(--forest-mid);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  height: 48px;
  padding: 0 24px;
  background: transparent;
  color: var(--forest);
  border: 1.5px solid var(--forest);
}
.btn-secondary:hover { background: var(--forest-mist); }

.btn-ghost {
  height: 44px;
  padding: 0 20px;
  background: transparent;
  color: var(--stone);
  border: 1.5px solid var(--sand-2);
}
.btn-ghost:hover { border-color: var(--stone); color: var(--charcoal); }

.btn-copper {
  height: 52px;
  padding: 0 28px;
  background: var(--copper);
  color: #fff;
}
.btn-copper:hover { opacity: 0.92; transform: translateY(-1px); }

.btn-sm {
  height: 36px;
  padding: 0 16px;
  font-size: 0.8125rem;
}

.btn-lg {
  height: 60px;
  padding: 0 36px;
  font-size: 1rem;
  border-radius: var(--radius-md);
}

@media (max-width: 430px) {
  .btn { min-height: 48px; }
}

/* ── Status Badge System ────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.badge-new        { background: rgba(123,169,188,0.15); color: #4A7A9B; }
.badge-collecting { background: rgba(196,136,58,0.12);  color: #9B6520; }
.badge-quoted     { background: rgba(123,169,188,0.15); color: #4A7A9B; }
.badge-approved   { background: rgba(45,74,62,0.12);    color: var(--forest); }
.badge-dispatched { background: rgba(181,103,77,0.12);  color: var(--copper); }
.badge-inprogress {
  background: rgba(181,103,77,0.12);
  color: var(--copper);
  animation: badge-pulse 2s ease infinite;
}
.badge-complete  { background: rgba(45,122,79,0.12);   color: var(--green-confirm); }
.badge-escalated { background: rgba(192,57,43,0.10);   color: var(--red); }

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.7; }
}

/* ── Form Inputs ────────────────────────────────────────────── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--stone);
}

.input {
  height: 52px;
  padding: 0 16px;
  background: var(--white);
  border: 1.5px solid var(--sand-2);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--charcoal);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

.input:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(45,74,62,0.08);
}

.input::placeholder { color: var(--dust); }

@media (max-width: 430px) {
  .input { font-size: 1rem; }
}

.textarea {
  padding: 14px 16px;
  height: auto;
  min-height: 100px;
  resize: vertical;
}

/* ── Bottom Sheet / Modal ───────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28,28,28,0.45);
  z-index: 100;
  display: none;
  backdrop-filter: blur(2px);
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  background: var(--white);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 101;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--sand-2);
  border-radius: 2px;
  margin: 14px auto 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--sand);
}

.sheet-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--charcoal);
}

/* ── Bottom Navigation ──────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-bottom));
  background: var(--white);
  border-top: 1px solid var(--sand);
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
  box-shadow: 0 -4px 20px rgba(28,28,28,0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  transition: all 0.15s ease;
}

.nav-icon {
  width: 24px;
  height: 24px;
  color: var(--dust);
  transition: color 0.15s ease, transform 0.15s ease;
}

.nav-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--dust);
  letter-spacing: 0.03em;
  transition: color 0.15s ease;
}

.nav-item.active .nav-icon { color: var(--forest); transform: translateY(-1px); }
.nav-item.active .nav-label { color: var(--forest); }
.nav-item:hover .nav-icon { color: var(--stone); }

.has-bottom-nav {
  padding-bottom: calc(64px + env(safe-area-inset-bottom) + 16px);
}

/* ── Condition Score Gauge ──────────────────────────────────── */
.score-gauge-ring { transition: stroke-dasharray 1.2s cubic-bezier(0.4, 0, 0.2, 1); }
.score-excellent  { stroke: #2D7A4F; }
.score-good       { stroke: #4A8A5A; }
.score-fair       { stroke: var(--amber); }
.score-poor       { stroke: #C05A3A; }
.score-critical   { stroke: var(--red); }

/* ── Stat Cards ─────────────────────────────────────────────── */
.stat-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-number {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.5rem;
  letter-spacing: 0.02em;
  color: var(--charcoal);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dust);
}

.stat-change {
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 6px;
}

.stat-change.up   { color: var(--green-confirm); }
.stat-change.down { color: var(--red); }

/* ── Toast Notifications ────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 40px);
  max-width: 360px;
}

.toast {
  background: var(--charcoal);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  opacity: 0;
  animation: toast-in 0.3s ease forwards, toast-out 0.3s ease 2.7s forwards;
}

.toast-success { border-left: 3px solid var(--green-confirm); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--forest); }

@keyframes toast-in {
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateY(-10px); opacity: 0; }
}

/* ── Sparkline Chart (CSS-only) ─────────────────────────────── */
.sparkline-container {
  height: 40px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
}

.sparkline-bar {
  flex: 1;
  background: var(--forest-mist);
  border-radius: 2px 2px 0 0;
  min-height: 4px;
  transition: height 0.6s ease;
}

.sparkline-bar.highlight { background: var(--forest); }

/* ── Skeleton Loading ───────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--sand) 0%,
    var(--sand-2) 50%,
    var(--sand) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--radius-sm);
}

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

/* ── Dark Mode (Console) ────────────────────────────────────── */
[data-theme='dark'] {
  --page-bg:       var(--dark-void);
  --card-bg:       var(--dark-surface);
  --card-bg-2:     var(--dark-surface-2);
  --text-primary:  var(--dark-text);
  --text-secondary:var(--dark-text-2);
  --border-color:  var(--dark-border);
  --action:        var(--dark-green);
}

[data-theme='dark'] body {
  background: var(--dark-void);
  color: var(--dark-text);
}

[data-theme='dark'] .card {
  background: var(--dark-surface);
  box-shadow: none;
  border: 1px solid var(--dark-border);
}

[data-theme='dark'] .glass-card {
  background: var(--glass-bg-dark);
  border-color: var(--glass-border-dark);
  box-shadow: none;
}

[data-theme='dark'] .input {
  background: var(--dark-surface-2);
  border-color: var(--dark-border);
  color: var(--dark-text);
}

[data-theme='dark'] .bottom-nav {
  background: var(--dark-surface);
  border-top-color: var(--dark-border);
}

[data-theme='dark'] .sheet {
  background: var(--dark-surface);
}

/* ── Responsive Grid Utilities ──────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

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

.stack    { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { gap: 8px; }
.stack-lg { gap: 20px; }
.row      { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
