/* ==============================================================
   IoT Project Site — "Lab Bench Spec-Sheet" Design System
   --------------------------------------------------------------
   Grounded in electronics prototyping material culture:
     - Bench white / silkscreen ink surfaces
     - Soldermask teal   #00838C  → primary actions & links
     - Copper            #A55A2A  → data accents (₹, traces)
     - LED green/amber/red        → status indicators
     - Perfboard dot-grid ambient texture
   Type: Chakra Petch (display) / IBM Plex Sans (body)
         IBM Plex Mono (part codes, prices, spec labels)
============================================================== */

:root {
  /* Typography */
  --font-display: 'Chakra Petch', 'IBM Plex Sans', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
  --font-heading: var(--font-display);
  --font-logo: var(--font-display);

  /* Surfaces — Light (bench) */
  --bg-primary: #f2f5f4;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e9eeec;
  --bg-glass: #ffffff;
  --border-color: #d9e1de;
  --border-strong: #b9c6c2;
  --border-glass: var(--border-color);
  --grid-dot: rgba(22, 33, 30, 0.055);

  /* Ink */
  --text-primary: #16211e;
  --text-secondary: #4a5955;
  --text-muted: #7c8a85;
  --text-on-accent: #ffffff;

  /* Soldermask teal — primary accent */
  --accent-primary: #00838c;
  --accent-deep: #006971;
  --accent-secondary: #00838c;
  --accent-tint: rgba(0, 131, 140, 0.08);
  --accent-tint-strong: rgba(0, 131, 140, 0.14);
  --accent-gradient: linear-gradient(135deg, #00838c, #006971);
  --accent-gradient-hover: linear-gradient(135deg, #006971, #00565d);

  /* Copper — data accent */
  --copper: #a55a2a;
  --copper-bright: #b87333;
  --copper-tint: rgba(165, 90, 42, 0.1);

  /* LED status colors */
  --led-green: #2b8a3e;
  --led-amber: #b35c00;
  --led-red: #c92a2a;
  --led-green-tint: rgba(43, 138, 62, 0.1);
  --led-amber-tint: rgba(230, 119, 0, 0.12);
  --led-red-tint: rgba(201, 42, 42, 0.1);

  --success: var(--led-green);
  --info: var(--accent-primary);
  --warning: var(--led-amber);
  --danger: var(--led-red);

  /* Depth */
  --card-shadow: 0 1px 2px rgba(22, 33, 30, 0.05);
  --hover-shadow: 0 6px 20px rgba(22, 33, 30, 0.1);
  --glow-shadow: 0 0 16px var(--accent-tint-strong);

  /* Layout — fluid across viewports */
  --sidebar-width: clamp(228px, 20vw, 272px);
  --header-height: clamp(54px, 8vh, 64px);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* Fluid spacing scale — scales the shell with the viewport width */
  --pad-shell-y: clamp(16px, 2.6vw, 30px);
  --pad-shell-x: clamp(14px, 3vw, 34px);
  --pad-card: clamp(16px, 2.4vw, 24px);
  --gap-fluid: clamp(12px, 1.6vw, 16px);

  /* Fluid base font — legible on a phone, comfortable on a laptop */
  --font-size-base: clamp(0.86rem, 0.82rem + 0.22vw, 0.95rem);
}

/* ==============================================================
   Dark theme — night bench (powered board after hours)
============================================================== */
[data-theme="dark"] {
  --bg-primary: #0c1413;
  --bg-secondary: #131e1c;
  --bg-tertiary: #1b2926;
  --bg-glass: #131e1c;
  --border-color: #263733;
  --border-strong: #3a4f4a;
  --grid-dot: rgba(226, 236, 232, 0.045);

  --text-primary: #e2ece8;
  --text-secondary: #9fb3ac;
  --text-muted: #647871;

  --accent-primary: #3bc6d0;
  --accent-deep: #62d6de;
  --accent-secondary: #3bc6d0;
  --accent-tint: rgba(59, 198, 208, 0.1);
  --accent-tint-strong: rgba(59, 198, 208, 0.18);
  --accent-gradient: linear-gradient(135deg, #3bc6d0, #2aa7b0);
  --accent-gradient-hover: linear-gradient(135deg, #62d6de, #3bc6d0);

  --copper: #d9925b;
  --copper-bright: #e3a877;
  --copper-tint: rgba(217, 146, 91, 0.12);

  --led-green: #51cf66;
  --led-amber: #ffa94d;
  --led-red: #ff6b6b;
  --led-green-tint: rgba(81, 207, 102, 0.12);
  --led-amber-tint: rgba(255, 169, 77, 0.12);
  --led-red-tint: rgba(255, 107, 107, 0.12);

  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --hover-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --glow-shadow: 0 0 18px rgba(59, 198, 208, 0.2);
}

/* ==============================================================
   Reset & base
============================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  font-size: var(--font-size-base);
  transition: background-color 0.3s ease, color 0.3s ease;
  position: relative;
  overflow-x: hidden;
}

/* Media never forces horizontal overflow at any width */
img, svg, video, canvas {
  max-width: 100%;
}

/* Perfboard dot grid — the bench surface */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1.6px);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

a {
  text-decoration: none;
  color: var(--accent-primary);
  transition: color 0.2s ease;
}
a:hover {
  color: var(--accent-deep);
}

::selection {
  background: var(--accent-tint-strong);
  color: var(--text-primary);
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ==============================================================
   Header — solid instrument rail
============================================================== */
.header-glass {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-height);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Header inner row: brand takes remaining space, actions stay compact */
.header-glass .container-fluid {
  height: 100%;
  flex-wrap: nowrap;
}

.navbar-brand {
  min-width: 0;                 /* allow the wordmark to truncate, never overflow */
  overflow: hidden;
}

/* The header rail must never be wider than the screen. The actions keep
   their intrinsic size and the brand gives up space first; below the
   phone breakpoint the account button drops to just its icon. */
.header-actions {
  min-width: 0;
  flex-shrink: 0;
}

.account-btn {
  min-width: 0;
  max-width: 190px;
}

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

.logo-text {
  font-family: var(--font-display);
  color: var(--text-primary);
  font-weight: 700;
  font-size: clamp(0.9rem, 0.8rem + 0.5vw, 1.12rem);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Copper pad before the wordmark */
.logo-text::before {
  content: '';
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
  background: radial-gradient(circle at center, var(--bg-secondary) 2px, var(--copper-bright) 2.6px);
}

.navbar-brand img {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* Small square utility buttons (contact links in header) */
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 1rem;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-tint);
}

/* ==============================================================
   Layout — sidebar + content
============================================================== */
.main-wrapper {
  display: flex;
  flex: 1;
  position: relative;
  /* z-index removed — letting Bootstrap modals escape naturally */
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  min-height: calc(100dvh - var(--header-height));
  padding: 22px 14px;
  flex-shrink: 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100dvh - var(--header-height));
  overflow-y: auto;
  z-index: 50;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

/* Silkscreen console label above nav */
.sidebar-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  padding: 0 14px 12px;
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.86rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  position: relative;
  border-left: 2px solid transparent;
}

.sidebar-link:hover {
  color: var(--accent-primary);
  background: var(--accent-tint);
}

.sidebar-link.active {
  color: var(--accent-primary);
  background: var(--accent-tint);
  font-weight: 600;
  border-left-color: var(--copper-bright);
}

.sidebar-link i {
  font-size: 1.05rem;
  width: 22px;
  text-align: center;
}

.content-area {
  flex: 1;
  min-width: 0;                 /* flex child must be allowed to shrink below content width */
  padding: var(--pad-shell-y) var(--pad-shell-x) 20px;
  /* overflow-y must NOT be auto/hidden or modals get clipped */
  overflow-y: visible;
  overflow-x: visible;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  min-height: calc(100dvh - var(--header-height));
  display: flex;
  flex-direction: column;
}

.content-area > .page-body {
  flex: 1;
}

/* Slim bench-label footer */
.site-footer {
  margin-top: 40px;
  padding: 16px 2px 6px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--text-muted);
}
.site-footer a:hover {
  color: var(--accent-primary);
}

/* ==============================================================
   Reusable responsive layout components
   --------------------------------------------------------------
   Page/section headers, table-cell action clusters and summary
   tiles that stay aligned from a 320px phone to a wide desktop.
============================================================== */

/* Toolbar — a page or section header: title on the left, actions on
   the right, wrapping to stacked rows before anything can overlap. */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: clamp(16px, 2.4vw, 24px);
}

/* Section toolbar sitting inside a card sits tighter to its content */
.card .toolbar,
.toolbar.toolbar-sub {
  margin-bottom: clamp(12px, 2vw, 18px);
}

.toolbar > * {
  min-width: 0;                 /* let long titles truncate, never push */
  margin-bottom: 0 !important;
}

.toolbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.toolbar-title > * {
  min-width: 0;
}

/* Action groups — buttons wrap onto a new line instead of overflowing */
.toolbar-actions,
.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Search field inside a toolbar: grows to fill, caps on desktop,
   and is allowed to shrink to the full width of a phone. */
.toolbar-search {
  flex: 1 1 220px;
  min-width: 0;
  width: 100%;
  max-width: 320px;
}

/* On phones the search box takes the full row under the title */
@media (max-width: 576px) {
  .toolbar-search {
    flex-basis: 100%;
    max-width: 100%;
  }
}

/* Table-cell action cluster — wraps within the cell, consistent gaps,
   no more buttons stacking on top of each other. */
.cell-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.cell-actions form {
  margin: 0;
}

/* Summary stat tiles — responsive auto-fit grid (replaces col-md-3 rows
   that squeezed four cards onto a tablet). */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--gap-fluid);
}

.stat-tile {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  padding: clamp(16px, 2.2vw, 22px);
  text-align: center;
}

/* Roster / member grid — auto-fit so members never cram on a tablet */
.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

/* Every data table can scroll on its own on a phone without pushing
   the page sideways. */
.table-responsive {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
  max-width: 100%;
}

/* ==============================================================
   Spec labels — silkscreen field names
   (also auto-applied to existing .fs-8.text-uppercase labels)
============================================================== */
.spec-label,
.fs-8.text-uppercase {
  font-family: var(--font-mono);
  font-size: 0.66rem !important;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Part number chip — silkscreen reference designator */
.part-code,
.badge.bg-light {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-secondary) !important;
  background: var(--bg-tertiary) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 4px;
  padding: 3px 8px;
  text-transform: uppercase;
  display: inline-block;
  line-height: 1.5;
}

/* ₹ price value — copper, mono */
.price-inr {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--copper);
  letter-spacing: -0.01em;
}

/* ==============================================================
   Masthead — catalog hero with routed trace
============================================================== */
.masthead {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: clamp(24px, 4vw, 44px);
  margin-bottom: clamp(18px, 2.4vw, 26px);
  overflow: hidden;
}

.masthead-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--copper);
  margin-bottom: 14px;
}

.masthead h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 3.4vw, 2.35rem);
  line-height: 1.15;
  margin: 0 0 12px;
  max-width: 560px;
}

.masthead-sub {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 540px;
  margin: 0 0 18px;
}

.masthead-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.masthead-meta .led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--led-green);
  box-shadow: 0 0 6px var(--led-green);
  display: inline-block;
  animation: ledBlink 2.4s ease-in-out infinite;
}

/* Routed copper traces, right side */
.masthead-trace {
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 400px;
  max-width: 42%;
  pointer-events: none;
}

.masthead-trace path {
  stroke: var(--copper-bright);
  stroke-width: 2;
  fill: none;
  opacity: 0.5;
  stroke-linecap: round;
}

.masthead-trace .pad {
  fill: var(--accent-primary);
  opacity: 0.8;
}

.masthead-trace .pad-hole {
  fill: var(--bg-secondary);
}

.masthead-trace .trace-led {
  fill: var(--led-green);
  animation: ledBlink 2.4s ease-in-out infinite;
}

@keyframes ledBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ==============================================================
   Cards
============================================================== */
.card {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--card-shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

/* Inner padding never crowds the card edge on small screens */
.card.p-4 {
  padding: var(--pad-card) !important;
}

.bg-glass {
  background: var(--bg-secondary) !important;
}

/* Catalog spec cards */
.spec-card {
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.spec-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-primary) !important;
  box-shadow: var(--hover-shadow);
}

.spec-card .spec-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.98rem;
  line-height: 1.35;
  color: var(--text-primary);
}

/* Locked documentation panel (project details) */
.locked-panel {
  background: var(--bg-secondary);
  border: 1.5px dashed var(--border-strong) !important;
  border-radius: var(--radius-md);
}

.locked-panel .bi {
  color: var(--accent-primary);
}

/* ==============================================================
   KPI cards — indicator modules
============================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

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

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent-primary);
}

.kpi-card:nth-child(2)::before { background: var(--led-green); }
.kpi-card:nth-child(3)::before { background: var(--led-amber); }
.kpi-card:nth-child(4)::before { background: var(--copper-bright); }

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-tint);
  color: var(--accent-primary);
  font-size: 1.25rem;
  flex-shrink: 0;
}

.kpi-card:nth-child(2) .kpi-icon { background: var(--led-green-tint); color: var(--led-green); }
.kpi-card:nth-child(3) .kpi-icon { background: var(--led-amber-tint); color: var(--led-amber); }
.kpi-card:nth-child(4) .kpi-icon { background: var(--copper-tint); color: var(--copper); }

.kpi-details h4 {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.kpi-details .value {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

/* ==============================================================
   Tables — datasheet grids
============================================================== */
.table {
  font-size: 0.86rem;
  color: var(--text-primary);
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-primary);
}

.table thead th {
  background: transparent;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.64rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}

.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  color: var(--text-primary);
}

.table tbody tr {
  transition: background-color 0.15s ease;
}

.table tbody tr:hover {
  background: var(--accent-tint);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table-responsive {
  border-radius: var(--radius-sm);
}

/* ==============================================================
   Forms
============================================================== */
.form-glass-control {
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  width: 100%;
  outline: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-glass-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.form-glass-control::placeholder {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.form-control, .form-select {
  background-color: var(--bg-secondary) !important;
  border-color: var(--border-strong) !important;
  color: var(--text-primary) !important;
  font-family: var(--font-body);
  border-radius: var(--radius-sm) !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent-primary) !important;
  box-shadow: 0 0 0 3px var(--accent-tint) !important;
}

.form-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-check-input {
  background-color: var(--bg-tertiary);
  border-color: var(--border-strong);
}

.form-check-input:checked {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.form-check-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

/* Section headers inside long forms */
.form-section-title {
  font-family: var(--font-mono);
  font-size: 0.7rem !important;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.input-group-text {
  background: var(--bg-tertiary) !important;
  border-color: var(--border-strong) !important;
  color: var(--text-secondary) !important;
}

/* ==============================================================
   Buttons
============================================================== */
.btn-glass {
  background: var(--accent-primary);
  color: var(--text-on-accent);
  border: 1px solid var(--accent-primary);
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  text-decoration: none;
}

[data-theme="dark"] .btn-glass {
  color: #0c1413;
}

.btn-glass:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--text-on-accent);
  transform: translateY(-1px);
}

[data-theme="dark"] .btn-glass:hover {
  color: #0c1413;
}

.btn-glass:active {
  transform: translateY(0);
}

.btn-glass-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
  text-decoration: none;
}

.btn-glass-secondary:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-tint);
}

.btn-glass.btn-sm,
.btn-glass-secondary.btn-sm {
  padding: 6px 10px;
  font-size: 0.66rem;
  gap: 5px;
}

/* Bootstrap button harmonization */
.btn-success {
  background-color: var(--led-green) !important;
  border-color: var(--led-green) !important;
}
.btn-danger {
  background-color: var(--led-red) !important;
  border-color: var(--led-red) !important;
}
.btn-warning {
  background-color: var(--led-amber) !important;
  border-color: var(--led-amber) !important;
  color: #fff !important;
}
.btn-outline-success {
  border-color: var(--led-green) !important;
  color: var(--led-green) !important;
}
.btn-outline-success:hover {
  background: var(--led-green) !important;
  color: #fff !important;
}
.btn-outline-info {
  border-color: var(--accent-primary) !important;
  color: var(--accent-primary) !important;
}
.btn-outline-info:hover {
  background: var(--accent-primary) !important;
  color: #fff !important;
}
.btn-outline-primary {
  border-color: var(--accent-primary) !important;
  color: var(--accent-primary) !important;
}
.btn-outline-primary:hover {
  background: var(--accent-primary) !important;
  color: #fff !important;
}
.btn-outline-warning {
  border-color: var(--led-amber) !important;
  color: var(--led-amber) !important;
}
.btn-outline-warning:hover {
  background: var(--led-amber) !important;
  color: #fff !important;
}
.btn-outline-danger {
  border-color: var(--led-red) !important;
  color: var(--led-red) !important;
}
.btn-outline-danger:hover {
  background: var(--led-red) !important;
  color: #fff !important;
}

/* ==============================================================
   Badges — LED indicator pills
============================================================== */
.badge {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  padding: 4px 9px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge.bg-success,
.badge.bg-warning,
.badge.bg-danger,
.badge.bg-info {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* LED dot */
.badge.bg-success::before,
.badge.bg-warning::before,
.badge.bg-danger::before,
.badge.bg-info::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 5px currentColor;
  flex-shrink: 0;
}

.badge.bg-success {
  background-color: var(--led-green-tint) !important;
  color: var(--led-green) !important;
}
.badge.bg-warning {
  background-color: var(--led-amber-tint) !important;
  color: var(--led-amber) !important;
}
.badge.bg-danger {
  background-color: var(--led-red-tint) !important;
  color: var(--led-red) !important;
}
.badge.bg-info {
  background-color: var(--accent-tint) !important;
  color: var(--accent-primary) !important;
}
.badge.bg-primary,
.badge.bg-indigo,
.bg-indigo {
  background-color: var(--accent-tint-strong) !important;
  color: var(--accent-primary) !important;
}
.badge.bg-secondary {
  background-color: var(--bg-tertiary) !important;
  color: var(--text-secondary) !important;
  border: 1px solid var(--border-color);
}

/* Keep ink readable when templates add .text-dark inside tinted badges */
.badge.bg-warning.text-dark {
  color: var(--led-amber) !important;
}

/* ==============================================================
   Alert pills — deadline LEDs
============================================================== */
.alert-pill {
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.alert-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 5px currentColor;
  flex-shrink: 0;
}

.alert-pill.red {
  background: var(--led-red-tint);
  color: var(--led-red);
}
.alert-pill.red::before {
  animation: ledBlink 1.2s ease-in-out infinite;
}
.alert-pill.orange {
  background: var(--led-amber-tint);
  color: var(--led-amber);
}
.alert-pill.green {
  background: var(--led-green-tint);
  color: var(--led-green);
}

/* ==============================================================
   Flash alert banners
============================================================== */
.alert {
  border-radius: var(--radius-sm) !important;
  font-family: var(--font-body);
  font-size: 0.875rem;
  border: 1px solid transparent !important;
  border-left-width: 3px !important;
}

.alert-success {
  background: var(--led-green-tint) !important;
  color: var(--led-green) !important;
  border-left-color: var(--led-green) !important;
}
.alert-danger {
  background: var(--led-red-tint) !important;
  color: var(--led-red) !important;
  border-left-color: var(--led-red) !important;
}
.alert-warning {
  background: var(--led-amber-tint) !important;
  color: var(--led-amber) !important;
  border-left-color: var(--led-amber) !important;
}
.alert-info {
  background: var(--accent-tint) !important;
  color: var(--accent-primary) !important;
  border-left-color: var(--accent-primary) !important;
}

/* ==============================================================
   Theme toggle — slide switch
============================================================== */
.theme-switch {
  cursor: pointer;
  width: 42px;
  height: 21px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  position: relative;
  display: inline-block;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.theme-switch::after {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  background: var(--text-secondary);
  top: 2px;
  left: 2px;
  transition: transform 0.25s ease, background-color 0.25s ease;
}

[data-theme="dark"] .theme-switch::after {
  transform: translateX(21px);
  background: var(--accent-primary);
}

/* ==============================================================
   Modals & dropdowns
============================================================== */
.modal {
  z-index: 1065;
}

.modal-backdrop {
  z-index: 1055;
}

.modal-content {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
  color: var(--text-primary);
}

.modal-header {
  border-bottom-color: var(--border-color) !important;
}

.modal-footer {
  border-top-color: var(--border-color) !important;
}

.modal-title {
  font-family: var(--font-display);
  font-weight: 600;
}

.dropdown-menu {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  padding: 6px;
}

.dropdown-item {
  color: var(--text-primary) !important;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 0.86rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-item:hover {
  background: var(--accent-tint) !important;
  color: var(--accent-primary) !important;
}

.dropdown-header {
  color: var(--text-muted) !important;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.dropdown-divider {
  border-color: var(--border-color);
}

/* ==============================================================
   Pagination — mono chips
============================================================== */
.pagination .page-link {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  min-width: 34px;
  text-align: center;
  transition: all 0.15s ease;
}

.pagination .page-link:hover {
  border-color: var(--accent-primary) !important;
  color: var(--accent-primary);
  background: var(--accent-tint);
}

.pagination .page-item.active .page-link {
  background: var(--accent-primary);
  border-color: var(--accent-primary) !important;
  color: #fff;
}

.pagination .page-item.disabled .page-link {
  background: transparent;
  color: var(--text-muted);
  opacity: 0.5;
}

/* ==============================================================
   Scrollbars
============================================================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==============================================================
   Utilities & Bootstrap harmonization
============================================================== */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-dark { color: var(--text-primary) !important; }
.text-accent { color: var(--accent-primary) !important; }
.text-success { color: var(--led-green) !important; }
.text-danger { color: var(--led-red) !important; }
.text-warning { color: var(--led-amber) !important; }
.text-info { color: var(--accent-primary) !important; }

.bg-primary { background-color: var(--bg-primary) !important; }
.bg-secondary { background-color: var(--bg-secondary) !important; }

.border-glass { border-color: var(--border-color) !important; }

.fs-7 { font-size: 0.85rem !important; }
.fs-8 { font-size: 0.75rem !important; }

.rounded-4 { border-radius: var(--radius-md) !important; }

.font-mono { font-family: var(--font-mono); }
.italic { font-style: italic; }
.style-desc { line-height: 1.7; }

.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-truncate-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.list-group-item {
  background: transparent !important;
  border-color: var(--border-color) !important;
  color: var(--text-primary) !important;
}

hr {
  border-color: var(--border-color);
  opacity: 1;
}

/* Page headings */
h2.fw-bold {
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

h2.fw-bold i {
  color: var(--accent-primary);
  font-size: 1.2rem;
}

/* ==============================================================
   Sidebar toggle — lives in the header rail, opens the side drawer.
   Deliberately not a floating bottom button: navigation belongs with
   the other header controls, not on top of the page content.
============================================================== */
.sidebar-toggle {
  display: none;                /* only shown once the sidebar collapses */
  width: 38px;
  height: 38px;
  margin-right: 10px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 1.2rem;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sidebar-toggle:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-tint);
}

/* ==============================================================
   Responsive
============================================================== */
/* Between the sidebar appearing and a wide desktop, the content column is
   too narrow for the routed-trace artwork — hide it so it can never overlap
   the hero headline. It returns only when there's real room for it. */
@media (max-width: 1199px) {
  .masthead-trace {
    display: none;
  }
  .masthead h1,
  .masthead-sub {
    max-width: none;
  }
}

/* Tablet / small laptop — collapse the sidebar into an off-canvas drawer */
@media (max-width: 992px) {
  .main-wrapper {
    flex-direction: column;
  }
  /* Off-canvas drawer. Slide with a transform rather than a negative
     `left`: the offset then always matches the drawer's real width, so no
     sliver of the sidebar can be left sitting on top of the page content. */
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    height: calc(100dvh - var(--header-height));
    width: min(84vw, 300px);
    z-index: 999;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: flex;
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0; right: 0; bottom: 0;
    background: rgba(12, 20, 19, 0.45);
    z-index: 998;
  }
  .sidebar-overlay.show {
    display: block;
  }
  .masthead-trace {
    display: none;
  }
  .masthead h1,
  .masthead-sub {
    max-width: none;
  }
}

/* Phones — tighten the header actions and stack KPI cards two-up */
@media (max-width: 768px) {
  .header-glass .d-flex.gap-3 {
    gap: 0.6rem !important;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  .kpi-card {
    padding: 14px 16px;
    gap: 12px;
  }
  .kpi-icon {
    width: 38px;
    height: 38px;
    font-size: 1.05rem;
  }
  .kpi-details .value {
    font-size: 1.25rem;
  }
  h2.fw-bold {
    font-size: 1.15rem;
  }
  .table {
    font-size: 0.8rem;
  }
  .table thead th,
  .table tbody td {
    padding: 10px 12px;
  }
}

/* Phones — the account button keeps its icon and drops the name, so the
   header rail fits alongside the menu button and the wordmark. */
@media (max-width: 575.98px) {
  .account-name {
    display: none;
  }
  .account-btn.dropdown-toggle::after {
    display: none;              /* caret is noise once the label is gone */
  }
  .account-btn {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* Small phones — drop the wordmark to a compact size, shrink utility icons */
@media (max-width: 480px) {
  .header-glass .container-fluid {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
  .header-glass .d-flex.gap-3 {
    gap: 0.4rem !important;
  }
  .icon-btn {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Very narrow phones — hide the theme label icons that flank the switch */
@media (max-width: 360px) {
  .header-glass .bi-sun-fill,
  .header-glass .bi-moon-stars-fill {
    display: none;
  }
}

/* Short / landscape viewports — the "irrespective of height" case.
   Un-stick the sidebar so a keyboard or short screen can scroll it,
   and let the header ride the top instead of fixing content off-screen. */
@media (max-height: 560px) and (max-width: 992px) {
  .sidebar {
    height: auto;
    min-height: 0;
    max-height: calc(100dvh - var(--header-height));
  }
}

@media (max-height: 620px) and (min-width: 993px) {
  .sidebar {
    position: static;
    height: auto;
    min-height: 100%;
  }
  .header-glass {
    position: static;
  }
}

/* ==============================================================
   Motion
============================================================== */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.content-area {
  animation: fadeSlideUp 0.35s ease-out;
}

.kpi-card {
  animation: fadeSlideUp 0.4s ease-out both;
}
.kpi-card:nth-child(1) { animation-delay: 0.04s; }
.kpi-card:nth-child(2) { animation-delay: 0.08s; }
.kpi-card:nth-child(3) { animation-delay: 0.12s; }
.kpi-card:nth-child(4) { animation-delay: 0.16s; }
.kpi-card:nth-child(5) { animation-delay: 0.2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ── Fix: Bootstrap .btn-close full clickable area ───────────────── */
.btn-close {
  width: 2rem !important;
  height: 2rem !important;
  padding: 0 !important;
  background-size: 0.9rem !important;   /* × icon smaller than button */
  background-position: center !important;
  background-repeat: no-repeat;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.15s;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-close:hover {
  opacity: 1;
}


/* ── Dashboard finance card hover lift ───────────────────────────── */
.dashboard-finance-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 28px rgba(0,0,0,0.13) !important;
  cursor: pointer;
}
