/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* ============================================
   App Layout & Sidebar
   ============================================ */

/* Hide number input spinners (Chrome, Safari, Edge) */
input[type="number"].no-spinners::-webkit-outer-spin-button,
input[type="number"].no-spinners::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Hide number input spinners (Firefox) */
input[type="number"].no-spinners {
  -moz-appearance: textfield;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--color-sidebar-bg);
  color: var(--slate-200);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--slate-700);
  flex-shrink: 0;
}

.sidebar-logo {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 400;
  text-decoration: none;
  display: flex;
  align-items: center;
}

.sidebar-logo:hover {
  opacity: 0.85;
}

.sidebar-logo svg {
  width: 24px;
  height: 24px;
}

/* Brand logo colors (V3: wine identity) */
.logo-crush {
  color: var(--grape-500);
}

.logo-suffix {
  color: #6B7280; /* Neutral gray */
}

/* On the dark sidebar, the neutral gray fails WCAG AA against navy.
   Lighten it so the ".wine" suffix is legible. */
.sidebar-logo .logo-suffix {
  color: var(--slate-300);
}

/* Hero logo for landing page - larger variant */
.hero-logo {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 400;
}

@media (min-width: 640px) {
  .hero-logo {
    font-size: 3rem;
  }
}

@media (min-width: 768px) {
  .hero-logo {
    font-size: 3.5rem;
  }
}

@media (min-width: 1024px) {
  .hero-logo {
    font-size: 4rem;
  }
}

/* Hero tagline - editorial serif to pair with logo */
.hero-tagline {
  font-family: var(--font-serif);
  font-weight: 300;
  font-style: italic;
  color: var(--slate-600);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

/* Vertical accent line between logo and tagline on desktop */
.hero-divider {
  display: none;
}

@media (min-width: 768px) {
  .hero-divider {
    display: block;
    width: 1px;
    height: 4rem;
    background: linear-gradient(to bottom, transparent, var(--grape-500), transparent);
    flex-shrink: 0;
  }
}

/* Feature cards - editorial accent
   Owns all shadow states to avoid Tailwind specificity conflicts.
   Do NOT combine with shadow-sm / shadow-md utility classes. */
.feature-card {
  border-left: 4px solid var(--grape-500);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  cursor: pointer;
}

.feature-card:hover {
  border-left-color: var(--grape-500);
  box-shadow: 0 8px 20px rgba(124, 82, 149, 0.18);
  transform: translateY(-3px);
}

.feature-card .feature-link {
  color: var(--grape-500);
}

.feature-card:hover .feature-link {
  color: var(--grape-500);
}

/* Bottom CTA - editorial serif */
.cta-headline {
  font-family: var(--font-serif);
  font-weight: 300;
  font-style: italic;
  color: var(--slate-700);
}

.cta-divider {
  width: 3rem;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--grape-500), transparent);
  margin: 0 auto;
}

/* Feature page styles - editorial consistency */
.feature-hero-title {
  font-family: var(--font-serif);
  font-weight: 300;
  font-style: italic;
  color: var(--slate-700);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.feature-hero-label {
  color: var(--grape-500);
  letter-spacing: 0.1em;
}

.feature-hero-subtitle {
  color: var(--slate-500);
  line-height: 1.6;
}

.feature-section-title {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--slate-700);
}

.feature-step-title {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--slate-800);
}

.feature-step-number {
  background: var(--grape-500);
  color: white;
}

.feature-check {
  color: var(--grape-500);
}

/* Auth page logo - medium variant */
.auth-logo {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
}

.sidebar-search {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--slate-700);
  flex-shrink: 0;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 0.6rem;
  width: 14px;
  height: 14px;
  color: var(--slate-400);
  pointer-events: none;
}

.sidebar-search-input {
  width: 100%;
  padding: 0.45rem 0.6rem 0.45rem 2rem;
  background: var(--slate-700);
  border: 1px solid var(--slate-600);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--slate-100);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-search-input::placeholder {
  color: var(--slate-400);
}

.sidebar-search-input:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px var(--overlay-blue-015);
  background: var(--slate-600);
}

.sidebar-nav {
  padding: 1rem 0;
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: none; /* Firefox */
}

.sidebar-nav::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge */
}

/* ============================================
   Sidebar User Menu
   ============================================ */

.sidebar-user {
  position: relative;
  border-top: 1px solid var(--slate-700);
  padding: 0.5rem;
  flex-shrink: 0;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  color: var(--slate-200);
  transition: background 0.15s ease;
}

.user-menu-trigger:hover {
  background: var(--slate-700);
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--slate-600);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar svg {
  width: 18px;
  height: 18px;
  color: var(--slate-300);
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.user-winery {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--slate-100);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 0.75rem;
  color: var(--slate-400);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-chevron {
  width: 16px;
  height: 16px;
  color: var(--slate-400);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.sidebar-user[data-user-menu-open-value="true"] .user-menu-chevron {
  transform: rotate(180deg);
}

/* User Menu Dropdown */
.user-menu-dropdown {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0.5rem;
  right: 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--overlay-black-020);
  overflow: hidden;
  z-index: 100;
}

.user-menu-dropdown.open {
  display: block;
}

.user-menu-section {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.user-menu-section:last-child {
  border-bottom: none;
}

.user-menu-label {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  font-size: 0.875rem;
  color: var(--gray-700);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s ease;
  text-align: left;
}

.user-menu-item:hover {
  background: var(--gray-100);
}

.user-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.user-menu-item .check-icon {
  color: var(--green-600);
}

.user-menu-item .check-placeholder {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.user-menu-item-current {
  font-weight: 500;
  color: var(--gray-800);
  cursor: default;
}

.user-menu-item-current:hover {
  background: transparent;
}

.user-menu-section-danger {
  background: var(--red-50);
}

.user-menu-item-danger {
  color: var(--red-600);
}

.user-menu-item-danger:hover {
  background: var(--red-100);
}

/* Sidebar Auth (when not logged in) */
.sidebar-auth {
  border-top: 1px solid var(--slate-700);
  padding: 0.75rem;
  flex-shrink: 0;
}

.nav-section {
  margin-bottom: 0.5rem;
}

.nav-section.expanded {
  margin-bottom: 1.75rem;
}

.nav-section-title {
  padding: 0.5rem 1rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--slate-400);
}

.nav-section-title-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-decoration: none;
  border-radius: 0.25rem;
  transition: background 0.1s ease, color 0.1s ease;
  cursor: pointer;
}

.nav-section-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: transform 0.2s ease, opacity 0.1s ease;
  transform: rotate(-90deg);
}

.nav-section.expanded .nav-section-chevron {
  transform: rotate(0deg);
}

.nav-section-title-link:hover .nav-section-chevron {
  opacity: 1;
}

/* Accordion: hide nav-links in collapsed sections */
.nav-section .nav-link {
  display: none;
}

.nav-section.expanded .nav-link {
  display: flex;
}

.nav-section-title-link:hover {
  background: var(--slate-700);
  color: var(--slate-300);
}

.nav-section-title-link.active {
  background: var(--slate-700);
  color: var(--slate-200);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  color: var(--slate-300);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.1s ease, color 0.1s ease;
  /* Touch optimization for mobile */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  /* Ensure minimum touch target height (44px recommended) */
  min-height: 44px;
}

/* Active/pressed state for immediate touch feedback */
.nav-link:active {
  background: var(--slate-600);
  color: var(--slate-50);
}

.nav-link:hover {
  background: var(--color-sidebar-hover);
  color: var(--slate-50);
}

.nav-link.active {
  background: var(--color-sidebar-active);
  border-left: 3px solid var(--grape-500);
  color: var(--color-surface);
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.main-content {
  flex: 1;
  background: var(--color-bg);
  overflow-y: auto;
}

/* ============================================
   Operation Detail Page
   ============================================ */

.operation-detail {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Header Card */
.operation-header {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
}

.operation-type-badge {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--blue-100);
  color: var(--blue-800);
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.status-badge.committed {
  background: var(--green-100);
  color: var(--green-800);
}

.status-badge.draft {
  background: var(--amber-100);
  color: var(--brown-700);
}

.status-badge.available {
  background: var(--green-100);
  color: var(--green-800);
}

.status-badge.consumed,
.status-badge.empty,
.status-badge.pressed {
  background: var(--gray-100);
  color: var(--gray-600);
}

.operation-meta {
  margin-top: 1rem;
}

.operation-meta dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.25rem;
}

.operation-meta dd {
  font-size: 0.95rem;
  color: var(--gray-800);
  margin: 0 0 0.75rem 0;
}

.operation-notes {
  padding: 1rem;
  background: var(--gray-50);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--gray-700);
  align-self: start;
}

.operation-notes-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.5rem;
}

/* Main Content Grid */
.operation-content {
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .operation-content {
    grid-template-columns: 1fr;
  }
  
  .operation-header {
    grid-template-columns: 1fr;
  }
}

/* Lines Table */
.operation-lines {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 1px 3px var(--overlay-black-008);
}

.lines-header {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.view-toggle-buttons {
  display: flex;
  gap: 0.25rem;
  background: var(--gray-100);
  border-radius: 6px;
  padding: 0.2rem;
}

.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.15s ease;
}

.toggle-btn:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.toggle-btn.active {
  background: var(--color-surface);
  color: var(--blue-500);
  box-shadow: 0 1px 2px var(--overlay-black-010);
}

.operation-lines table {
  width: 100%;
  border-collapse: collapse;
}

.operation-lines table.hidden {
  display: none;
}

/* Detailed view specific styles */
.loss-value {
  color: var(--red-600);
}

.gain-value {
  color: var(--green-600);
}

.spillage-value {
  color: var(--amber-500);
  font-style: italic;
}

.operation-lines th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.operation-lines th:not(:first-child) {
  text-align: right;
}

.operation-lines td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  transition: background-color 0.15s ease;
}

.operation-lines td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.operation-lines tbody tr,
.operation-lines tfoot tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.operation-lines tbody tr:hover,
.operation-lines tbody tr.highlighted,
.operation-lines tfoot tr:hover,
.operation-lines tfoot tr.highlighted {
  background-color: var(--blue-25);
}

.operation-lines td.cell-highlighted {
  background-color: var(--blue-200);
  font-weight: 600;
}

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

/* Line type labels */
.line-type {
  display: inline-block;
  width: 45px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--gray-500);
}

.line-type.from { color: var(--blue-600); }
.line-type.to { color: var(--green-600); }
.line-type.loss { color: var(--red-600); }

.container-link {
  color: var(--gray-800);
  text-decoration: none;
  font-weight: 500;
}

.container-link:hover {
  color: var(--blue-600);
  text-decoration: underline;
}

/* Quantity cells */
.qty-cell {
  font-weight: 600;
  color: var(--gray-800);
}

.qty-cell.from { color: var(--red-600); }
.qty-cell.to { color: var(--green-600); }
.qty-cell.loss { color: var(--red-600); font-style: italic; }

/* Detailed view value styles */
.loss-value { color: var(--red-600); }
.gain-value { color: var(--green-600); }
.spillage-value { color: var(--amber-500); }

/* Diagram Panel */
.operation-diagram {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 1px 3px var(--overlay-black-008);
  min-height: 300px;
}

/* Actions Bar */
.operation-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 1rem;
  align-items: center;
}

.operation-actions a:not(.btn) {
  color: var(--gray-500);
  text-decoration: none;
  font-size: 0.9rem;
}

.operation-actions a:not(.btn):hover {
  color: var(--gray-800);
}

/* ============================================
   Unified Operation Layout (Lines Table + Sankey)
   ============================================ */

/* Lines Section - Full width table */
.operation-lines-section {
  background: var(--color-surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px var(--overlay-black-008);
  margin-bottom: 1.5rem;
}

/* Lines Table Header (toggle buttons) */
.lines-table-header {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem 0.75rem;
  background: var(--gray-25);
  border-bottom: 1px solid var(--gray-200);
}

/* Lines Table Shared Styles */
.operation-lines-table {
  width: 100%;
}

/* Simple Grid Table - clean, minimal styling */
.lines-table.simple-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.lines-table.simple-grid.hidden {
  display: none;
}

.lines-table.simple-grid th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.lines-table.simple-grid th.text-right {
  text-align: right;
}

.lines-table.simple-grid th.col-type {
  width: 55px;
}

.lines-table.simple-grid th.col-qty {
  width: 90px;
}

.lines-table.simple-grid td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--gray-150);
  vertical-align: middle;
}

.lines-table.simple-grid td.text-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lines-table.simple-grid td.text-muted {
  color: var(--gray-400);
}

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

.lines-table.simple-grid tfoot td {
  border-top: 1px solid var(--gray-200);
  background: var(--gray-25);
}

/* Type labels in grid */
.lines-table.simple-grid .type-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.lines-table.simple-grid .type-label.from { color: var(--blue-600); }
.lines-table.simple-grid .type-label.to { color: var(--green-600); }
.lines-table.simple-grid .type-label.loss { color: var(--red-600); }

/* Container links */
.lines-table.simple-grid a {
  color: var(--gray-800);
  text-decoration: none;
}

.lines-table.simple-grid a:hover {
  color: var(--blue-600);
  text-decoration: underline;
}

/* Quantity values */
.lines-table.simple-grid .qty-from { color: var(--red-600); font-weight: 500; }
.lines-table.simple-grid .qty-to { color: var(--green-600); font-weight: 500; }
.lines-table.simple-grid .qty-loss { color: var(--red-600); font-style: italic; }

/* Detailed table colors */
.lines-table.simple-grid .text-loss { color: var(--red-600); }
.lines-table.simple-grid .text-gain { color: var(--green-600); }
.lines-table.simple-grid .text-spillage { color: var(--amber-500); }

/* ============================================
   Edit Mode - Lines Table
   ============================================ */

/* Edit mode row styles */
.lines-table.simple-grid tr.row-selected {
  background: var(--blue-50);
}

.lines-table.simple-grid tr.loss-row {
  background: var(--red-50);
}

/* ─────────────────────────────────────────────────────────────
   Hover Highlights (table ↔ diagram cross-highlighting)
   ───────────────────────────────────────────────────────────── */

/* Row highlight - subtle background when diagram element hovered */
.lines-table.simple-grid tr.hover-highlight {
  background: rgba(56, 189, 248, 0.08);
}

.lines-table.simple-grid tr.loss-row.hover-highlight {
  background: rgba(56, 189, 248, 0.12);
}

/* Cell highlight - more prominent for specific cell ↔ element pairing */
.lines-table.simple-grid td.cell-highlight {
  background: rgba(56, 189, 248, 0.15);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.3);
}

/* Row checkbox with type label */
.lines-table.simple-grid .row-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.lines-table.simple-grid .row-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Container name and detail */
.lines-table.simple-grid .container-name {
  font-weight: 500;
  color: var(--gray-800);
}

.lines-table.simple-grid .container-detail {
  display: block;
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 0.15rem;
}

/* Container select dropdown */
.lines-table.simple-grid .container-select {
  width: 100%;
  max-width: 280px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--gray-800);
  background: var(--color-surface);
}

.lines-table.simple-grid .container-select:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px var(--overlay-blue-015);
}

/* Quantity input wrapper */
.lines-table.simple-grid .qty-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  justify-content: flex-end;
}

.lines-table.simple-grid .qty-input {
  width: 80px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: right;
  color: var(--gray-800);
}

.lines-table.simple-grid .qty-input:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px var(--overlay-blue-015);
}

.lines-table.simple-grid .qty-input:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}

.lines-table.simple-grid .qty-input::placeholder {
  color: var(--gray-400);
}

.lines-table.simple-grid .qty-unit {
  font-size: 0.8rem;
  color: var(--gray-500);
  min-width: 25px;
}

/* Add/Remove buttons */
.lines-table.simple-grid .btn-remove {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: var(--red-100);
  color: var(--red-600);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lines-table.simple-grid .btn-remove:hover {
  background: var(--red-200);
}

.lines-table.simple-grid .add-row td {
  padding: 0.75rem;
  background: var(--gray-25);
  border-top: 1px solid var(--gray-200);
}

.lines-table.simple-grid .btn-add {
  background: none;
  border: 1px dashed var(--gray-300);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  color: var(--gray-500);
  cursor: pointer;
}

.lines-table.simple-grid .btn-add:hover {
  border-color: var(--blue-500);
  color: var(--blue-500);
  background: var(--blue-50);
}

/* Lines Summary (edit mode) */
.lines-summary {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  font-size: 0.9rem;
}

.lines-summary .summary-item {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.lines-summary .summary-label {
  color: var(--gray-500);
}

.lines-summary .summary-value {
  font-weight: 600;
  color: var(--gray-800);
}

.lines-summary .summary-arrow {
  color: var(--gray-400);
  font-size: 1.1rem;
}

.lines-summary .summary-yield .summary-value {
  color: var(--green-600);
}

/* Sankey Section - Full width at bottom */
.operation-sankey-section {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 1.5rem;
  margin-top: 1.5rem;
  box-shadow: 0 1px 3px var(--overlay-black-008);
}

.sankey-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin: 0 0 1rem 0;
}

.operation-sankey-container {
  min-height: 200px;
  width: 100%;
}

/* Production Summary (for Bottlings) */
.production-summary {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  background: var(--color-surface);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 3px var(--overlay-black-008);
}

.summary-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-stat .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-800);
}

.summary-stat .stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

/* Flash Messages */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash-notice {
  background: var(--green-100);
  color: var(--green-800);
  border: 1px solid var(--green-200);
}

.flash-alert {
  background: var(--red-100);
  color: var(--red-800);
  border: 1px solid var(--red-200);
}

/* ============================================
   Buttons - Unified System
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  /* Default: secondary style */
  background: var(--gray-200);
  color: var(--gray-700);
}


.btn:hover {
  background: var(--gray-300);
  color: var(--gray-800);
}

/* Primary - blue */
.btn-primary {
  background: var(--blue-500);
  color: var(--color-surface);
}

.btn-primary:hover {
  background: var(--blue-600);
  color: var(--color-surface);
}

/* Secondary - gray (default) */
.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-300);
  color: var(--gray-800);
}

/* Success / Commit - green */
.btn-commit,
.btn-success {
  background: var(--green-600);
  color: var(--color-surface);
}

.btn-commit:hover,
.btn-success:hover {
  background: var(--green-700);
  color: var(--color-surface);
}

/* Danger - red */
.btn-danger {
  background: var(--red-600);
  color: var(--color-surface);
}

.btn-danger:hover {
  background: var(--red-700);
  color: var(--color-surface);
}

/* Outline variants */
.btn-outline {
  background: transparent;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}

.btn-outline:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
}

.btn-outline-primary {
  background: transparent;
  border: 1px solid var(--blue-500);
  color: var(--blue-500);
}

.btn-outline-primary:hover {
  background: var(--blue-50);
  color: var(--blue-600);
}

.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--red-600);
  color: var(--red-600);
}

.btn-outline-danger:hover {
  background: var(--red-50);
  color: var(--red-700);
}

/* Small button */
.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Extra small button */
.btn-xs {
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
}

/* Spacer utility */
.btn-spacer {
  margin-left: auto;
}

/* Text-style link button */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--gray-500);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
}

.btn-link:hover {
  color: var(--blue-500);
  text-decoration: underline;
}

/* ============================================
   Common Page Styles
   ============================================ */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1.5rem;
  padding-bottom: 0;
}

.page-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--gray-800);
}

.page-header .breadcrumb {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.page-header .breadcrumb a {
  color: var(--blue-500);
  text-decoration: none;
}

.page-header .actions {
  display: flex;
  gap: 0.5rem;
}

/* Mobile: stack header on smaller screens */
@media (max-width: 480px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .page-header > div:first-child {
    text-align: left;
  }

  .page-header > div:last-child {
    display: flex;
    gap: 0.5rem;
  }

  .page-header > div:last-child .btn {
    flex: 1;
    justify-content: center;
  }
}

.card {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 0 1.5rem 1.5rem;
  box-shadow: 0 1px 3px var(--overlay-black-008);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-700);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-header h2 {
  margin: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  padding: 0 1.5rem;
  margin-bottom: 1.5rem;
}

.grid-2 .card {
  margin: 0;
}

@media (max-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Data Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

/* Sortable Table Headers */
.sortable-table th .sort-header {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--gray-500);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}

.sortable-table th .sort-header:hover {
  color: var(--gray-800);
  text-decoration: none;
}

.sortable-table th .sort-header.active {
  color: var(--gray-800);
}

.sortable-table th .sort-indicator {
  font-size: 0.7rem;
  opacity: 0.7;
}

.sortable-table th .sort-header.active .sort-indicator {
  opacity: 1;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.data-table.compact td,
.data-table.compact th {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.data-table tbody tr:hover {
  background: var(--gray-50);
}

.data-table tbody tr[data-href] {
  cursor: pointer;
}

.data-table a {
  color: var(--blue-500);
  text-decoration: none;
}

.data-table a:hover {
  text-decoration: underline;
}

.data-table .link {
  color: var(--gray-500);
  font-size: 0.875rem;
}

.data-table .link:hover {
  color: var(--blue-500);
}

/* Data table in bento cards - tighter padding for compact previews */
.bento-card .data-table.compact td {
  padding: 0.5rem 0.25rem;
}

.bento-card .data-table.compact td:first-child {
  padding-left: 0;
}

.bento-card .data-table.compact td:last-child {
  padding-right: 0;
}

.bento-card .data-table.compact tr:last-child td {
  border-bottom: none;
}

/* Detail Lists */
.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1.5rem;
}

.detail-list dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  padding-top: 0.25rem;
}

.detail-list dd {
  margin: 0;
  color: var(--gray-800);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

.badge-sm {
  padding: 0.125rem 0.375rem;
  font-size: 0.6875rem;
}

.badge.lbs {
  background: var(--amber-100);
  color: var(--brown-700);
}

.badge.gal {
  background: var(--blue-100);
  color: var(--blue-800);
}

.badge.ava {
  background: var(--green-100);
  color: var(--green-800);
}

.badge.consumed {
  background: var(--red-100);
  color: var(--red-800);
}

.badge.available {
  background: var(--green-100);
  color: var(--green-800);
}

/* Container type badges */
.badge.tank {
  background: var(--blue-100);
  color: var(--blue-800);
}

.badge.barrel {
  background: var(--amber-100);
  color: var(--brown-700);
}

.badge.loss {
  background: var(--red-100);
  color: var(--red-800);
}

.badge.product {
  background: var(--violet-150);
  color: var(--violet-600);
}

/* Status badges */
.badge-warning {
  background: var(--amber-100);
  color: var(--amber-800);
}

.badge-info {
  background: var(--blue-100);
  color: var(--blue-700);
}

.badge-success {
  background: var(--green-100);
  color: var(--green-800);
}

/* Commit action badge — outlined style to signal permanent/irreversible action */
.badge-commit {
  background: var(--amber-50, #fffbeb);
  color: var(--amber-800);
  border: 1.5px solid var(--amber-400, #fbbf24);
}

.badge-commit:hover {
  background: var(--amber-100);
  border-color: var(--amber-500, #f59e0b);
}

/* Forms */
.form {
  max-width: 600px;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.5rem;
}

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--gray-800);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--overlay-blue-010);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.form-row.compact {
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--gray-500);
}

.empty-state p {
  margin-bottom: 1rem;
}

.empty-state a {
  color: var(--blue-500);
  text-decoration: none;
}

/* Error Messages */
.error-messages {
  background: var(--red-50);
  border: 1px solid var(--red-200);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.error-messages h3 {
  color: var(--red-800);
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
}

.error-messages ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--red-700);
  font-size: 0.875rem;
}

/* Text helpers */
.text-muted {
  color: var(--gray-400);
}

/* Add Form (details/summary) */
.add-form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}

.add-form summary {
  cursor: pointer;
  color: var(--blue-500);
  font-size: 0.875rem;
  font-weight: 500;
}

.add-form[open] summary {
  margin-bottom: 1rem;
}

/* Composition List */
.composition-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.composition-list li {
  padding: 0.25rem 0;
  font-size: 0.9rem;
}

.composition-list .composition-breakdown {
  list-style: none;
  margin: 0.25rem 0 0 1rem;
  padding: 0;
}

.composition-list .composition-breakdown li {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.15rem 0;
}

.composition-list .breakdown-key {
  font-weight: 500;
}

.composition-list .breakdown-pct {
  color: var(--gray-500);
}

.composition-list .breakdown-qty {
  font-size: 0.8rem;
}

/* Compact composition (single line) */
.composition-compact {
  font-size: 0.85rem;
  color: var(--gray-500);
}

/* ============================================
   Inventory Summary (Products)
   ============================================ */
.inventory-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1.5rem;
}

.inventory-stat {
  text-align: center;
}

.inventory-stat .stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-800);
}

.inventory-stat .stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

/* Bottling Summary */
.bottling-summary {
  margin-bottom: 1.5rem;
}

.bottling-summary h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--gray-700);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 1rem;
}

.summary-grid dt {
  font-size: 0.75rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.summary-grid dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-800);
}

/* Operation type badge for bottling */
.operation-type-badge.bottling {
  background: linear-gradient(135deg, var(--violet-500), var(--violet-600));
}

/* ============================================
   Composition Inspector
   ============================================ */
.composition-inspector {
  padding: 1rem;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--gray-200);
}

.inspector-header h4 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-800);
}

.inspector-header .total-qty {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-500);
  background: var(--gray-100);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}

.inspector-section {
  margin-bottom: 1.5rem;
}

.inspector-section:last-child {
  margin-bottom: 0;
}

.inspector-section h5 {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
}

.attribute-group {
  margin-bottom: 1rem;
}

.attribute-group:last-child {
  margin-bottom: 0;
}

.attribute-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.5rem;
}

.attribute-value {
  font-size: 1rem;
  color: var(--gray-800);
}

.attribute-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.breakdown-row {
  display: grid;
  grid-template-columns: 120px 1fr 50px 80px;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.breakdown-row.simple {
  grid-template-columns: 1fr auto;
}

.breakdown-label {
  color: var(--gray-700);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breakdown-bar-container {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--violet-500), var(--indigo-500));
  border-radius: 4px;
  transition: width 0.3s ease;
}

.breakdown-value {
  text-align: right;
  color: var(--gray-500);
  font-weight: 500;
}

.breakdown-qty {
  text-align: right;
  color: var(--gray-400);
  font-size: 0.75rem;
}

/* Cost Grid */
.cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.cost-item {
  background: var(--gray-50);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.cost-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.25rem;
}

.cost-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-800);
}

.cost-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--gray-400);
  margin-top: 0.25rem;
}

/* ============================================
   Additional Utility Styles
   ============================================ */

/* Card headings */
.card h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--gray-200);
}

/* Notice messages */
.notice {
  color: var(--green-800);
  background: var(--green-100);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin: 0 1.5rem 1rem;
  font-size: 0.9rem;
}

/* 3-column form row */
.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (max-width: 768px) {
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

/* Action buttons group */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.action-buttons .btn {
  text-align: center;
}

/* Sankey container */
.sankey-container {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 1rem;
  min-height: 200px;
}

/* Detail grid for multi-column layouts */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 0 1.5rem;
  margin-bottom: 1.5rem;
}

.detail-grid .card {
  margin: 0;
}

/* Error messages h4 */
.error-messages h4 {
  color: var(--red-800);
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
}

/* Form max-width override for full-width forms */
.form.full-width {
  max-width: none;
}

/* ============================================
   Composition Section (for operation pages)
   ============================================ */
.composition-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-200);
}

.composition-section h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
}

.composition-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.composition-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  overflow: hidden;
}

.composition-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--gray-100);
  border-bottom: 1px solid var(--gray-200);
}

.composition-card-header strong {
  font-size: 0.9rem;
  color: var(--gray-800);
}

/* Primary composition card (highlighted) */
.composition-card-primary {
  border-color: var(--violet-500);
  border-width: 2px;
}

.composition-card-primary .composition-card-header {
  background: linear-gradient(135deg, var(--violet-50), var(--violet-100));
  border-bottom-color: var(--violet-300);
}

.qty-badge {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--gray-500);
  background: var(--color-surface);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--gray-200);
}

/* Collapsible composition section */
.composition-section.collapsible {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 0;
  margin-top: 1.5rem;
}

.composition-section.collapsible summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  background: var(--gray-50);
  border-radius: 8px;
  list-style: none;
}

.composition-section.collapsible summary::-webkit-details-marker {
  display: none;
}

.composition-section.collapsible summary::before {
  content: '▶';
  font-size: 0.7rem;
  color: var(--gray-400);
  transition: transform 0.2s ease;
}

.composition-section.collapsible[open] summary::before {
  transform: rotate(90deg);
}

.composition-section.collapsible summary h3 {
  margin: 0;
  padding: 0;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.composition-section.collapsible summary .hint {
  font-size: 0.8rem;
  color: var(--gray-400);
  font-weight: 400;
  margin-left: auto;
}

.composition-section.collapsible[open] summary {
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid var(--gray-200);
}

.composition-section.collapsible .composition-grid {
  padding: 1rem;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.4rem;
  background: var(--gray-200);
  color: var(--gray-500);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
}

/* ============================================
   Responsive Sidebar
   ============================================ */

/* Mobile top bar — hidden on desktop, fixed 44px strip on mobile */
.top-bar {
  display: none;
}

/* Sidebar toggle — lives inside .top-bar, hidden on desktop */
.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0.375rem;
  color: var(--slate-200);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle svg {
  width: 22px;
  height: 22px;
}

.sidebar-toggle:hover {
  background: var(--slate-700);
}

/* Top bar title — truncates long page names */
.top-bar-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--slate-200);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Top bar home — wordmark, hidden on desktop, shown on mobile */
.top-bar-home {
  display: none;
  flex-shrink: 0;
  font-family: var(--font-serif);
  font-size: 1rem;
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.top-bar-home:hover {
  background: var(--slate-700);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-black-050);
  z-index: 999;
  /* Touch optimization */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Mobile styles */
@media (max-width: 768px) {
  /* Top bar — fixed strip with hamburger, title, action */
  .top-bar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: var(--color-ink);
    border-bottom: none;
    z-index: 1001;
    padding: 0 0.75rem;
    align-items: center;
    gap: 0.5rem;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .top-bar-home {
    display: flex;
  }

  /* Page header: hide title on mobile (it's in the top bar now) */
  .page-header h1 {
    display: none;
  }

  /* Collapse page-header first child if it only contained a title */
  .page-header > div:first-child:has(> h1:only-child) {
    display: none;
  }

  /* Right-align actions when title div is collapsed */
  .page-header > div:last-child {
    margin-left: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-nav {
    overflow-y: visible;
    min-height: auto;
  }

  .sidebar-user {
    flex-shrink: 0;
  }

  .user-menu-trigger {
    padding: 0.75rem;
    min-height: 56px;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .main-content {
    padding-top: 44px; /* Space for top bar */
  }

  /* Page header: tighter mobile padding (title is in the top bar) */
  .page-header {
    padding: 0.5rem 1rem 0;
    gap: 0.5rem;
  }

  /* Stack operation content on mobile */
  .operation-content {
    grid-template-columns: 1fr;
  }

  /* Full width cards on mobile */
  .grid-2 {
    grid-template-columns: 1fr;
    padding: 0 1rem;
  }

  .card {
    margin: 0 1rem 1rem;
  }

  /* Compact filter bar on mobile — less padding, inline layout */
  .filter-bar {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    background: transparent;
    border-bottom: none;
    margin: 0 1rem;
  }

  .filter-bar .form-control {
    font-size: 0.875rem;
  }

  /* Smaller form rows */
  .form-row {
    grid-template-columns: 1fr;
  }

  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

/* Tablet styles */
@media (max-width: 1024px) and (min-width: 769px) {
  .sidebar {
    width: 200px;
  }
  
  .nav-link {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }
}

/* ============================================
   Enhanced Container Dropdown
   ============================================ */

.container-select-wrapper {
  position: relative;
}

.container-select-wrapper .form-control {
  padding-right: 2.5rem;
}

/* Search input for dropdowns */
.dropdown-search {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.dropdown-search:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--overlay-blue-010);
}

/* Custom dropdown container */
.custom-dropdown {
  position: relative;
}

.custom-dropdown-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--gray-800);
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.custom-dropdown-trigger:hover {
  border-color: var(--gray-400);
}

.custom-dropdown-trigger:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--overlay-blue-010);
}

.custom-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  margin-top: 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--overlay-black-015);
  max-height: 300px;
  overflow-y: auto;
}

.custom-dropdown.open .custom-dropdown-menu {
  display: block;
}

.dropdown-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.dropdown-option:hover {
  background: var(--gray-100);
}

.dropdown-option.selected {
  background: var(--blue-50);
  color: var(--blue-600);
}

.dropdown-search {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--gray-200);
  font-size: 0.9rem;
  outline: none;
}

.dropdown-search:focus {
  background: var(--gray-50);
}

.dropdown-option-name {
  font-weight: 500;
}

.dropdown-option-qty {
  font-size: 0.8rem;
  color: var(--gray-500);
}

.dropdown-option-type {
  font-size: 0.7rem;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Show all link */
.dropdown-show-all {
  display: block;
  padding: 0.5rem 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--blue-500);
  text-decoration: none;
  border-top: 1px solid var(--gray-200);
}

.dropdown-show-all:hover {
  background: var(--gray-50);
}

/* Empty state in dropdown */
.dropdown-empty {
  padding: 1rem;
  text-align: center;
  color: var(--gray-400);
  font-size: 0.9rem;
}

/* ============================================
   Pagination
   ============================================ */

.pagination-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--gray-500);
}

.pagination {
  display: flex;
  gap: 0.25rem;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  text-decoration: none;
  transition: all 0.15s ease;
}

.pagination a {
  color: var(--gray-700);
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
}

.pagination a:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

.pagination .current {
  background: var(--blue-500);
  color: var(--color-surface);
  border: 1px solid var(--blue-500);
}

.pagination .disabled {
  color: var(--gray-400);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  cursor: not-allowed;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--gray-500);
  white-space: nowrap;
}

.filter-group select,
.filter-group input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-size: 0.85rem;
}

.filter-search {
  flex: 1;
  min-width: 200px;
}

.filter-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  padding-left: 2rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.5rem center;
}

.filter-search input:focus {
  outline: none;
  border-color: var(--blue-500);
}

/* Sortable table headers */
.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.sortable:hover {
  color: var(--gray-700);
}

.sortable::after {
  content: '↕';
  margin-left: 0.25rem;
  opacity: 0.3;
  font-size: 0.7rem;
}

.sortable.asc::after {
  content: '↑';
  opacity: 1;
}

.sortable.desc::after {
  content: '↓';
  opacity: 1;
}

/* ============================================
   Small Button Variant
   ============================================ */

.btn-small {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

/* ============================================
   Editable Operation Lines (Form Mode)
   ============================================ */

.operation-lines-editor {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 3px var(--overlay-black-008);
}

.lines-editor-table {
  overflow-x: auto;
}

.lines-table.editable {
  width: 100%;
  border-collapse: collapse;
}

.lines-table.editable th {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.lines-table.editable td {
  padding: 0.75rem 0.5rem;
  vertical-align: middle;
}

.lines-table.editable .section-header td {
  padding: 1rem 0.5rem 0.5rem;
  border-bottom: none;
}

.lines-table.editable .section-label {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.lines-table.editable .section-hint {
  margin-left: 0.75rem;
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
}

.lines-table.editable .line-row {
  border-bottom: 1px solid var(--gray-100);
}

.lines-table.editable .line-row:hover {
  background: var(--gray-50);
}

.lines-table.editable .line-row.selected {
  background: var(--blue-50);
}

.lines-table.editable .line-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lines-table.editable .source-name {
  font-weight: 500;
}

.lines-table.editable .source-detail {
  font-size: 0.85rem;
}

.lines-table.editable .source-select,
.lines-table.editable .dest-select {
  min-width: 200px;
  flex: 1;
}

.lines-table.editable .line-checkbox {
  width: 40px;
  text-align: center;
}

.lines-table.editable .line-select-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.lines-table.editable .qty-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lines-table.editable .qty-input {
  width: 100px;
  text-align: right;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
}

.lines-table.editable .qty-input:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}

.lines-table.editable .qty-input:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--overlay-blue-010);
}

.lines-table.editable .qty-unit {
  font-size: 0.85rem;
  color: var(--gray-500);
  min-width: 30px;
}

.lines-table.editable .line-actions {
  width: 40px;
  text-align: center;
}

.lines-table.editable .btn-remove {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: none;
  background: var(--red-100);
  color: var(--red-600);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lines-table.editable .btn-remove:hover {
  background: var(--red-200);
}

.lines-table.editable .add-line-row td {
  padding: 0.75rem 0.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Lines Summary */
.lines-summary {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem;
  background: var(--gray-50);
  border-radius: 8px;
  margin-top: 1rem;
}

.lines-summary .summary-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.lines-summary .summary-label {
  font-size: 0.85rem;
  color: var(--gray-500);
}

.lines-summary .summary-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-800);
}

.lines-summary .summary-arrow {
  font-size: 1.25rem;
  color: var(--gray-400);
}

.lines-summary .summary-yield .summary-value {
  color: var(--green-600);
}

/* Button Icon variant */
.btn-icon {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Operation Form Styles
   ============================================ */

/* Preview Actions */
.operation-preview-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
}

/* Preview Results States */
.operation-preview-states {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 3px var(--overlay-black-008);
}

.operation-preview-states h4 {
  font-size: 0.9rem;
  color: var(--gray-500);
  margin: 0 0 1rem 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Operation Header Form Mode */
.operation-meta-form {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  margin-top: 1rem;
}

.operation-meta-form .form-group {
  margin-bottom: 0;
}

.operation-meta-form .form-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.25rem;
  display: block;
}

.operation-meta-form .status-display {
  padding-top: 1.5rem;
}

.operation-notes-input {
  max-width: 400px;
}

.operation-notes-input label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.25rem;
  display: block;
}

/* ============================================
   Detailed Edit Mode - Compact Inputs
   ============================================ */

/* Compact quantity input wrapper */
.qty-input-wrapper.compact {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

/* Small quantity input for detailed table */
.qty-input.qty-input-sm {
  width: 70px;
  padding: 0.3rem 0.4rem;
  font-size: 0.85rem;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  text-align: right;
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.qty-input.qty-input-sm:hover {
  border-color: var(--gray-300);
}

.qty-input.qty-input-sm:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px var(--overlay-blue-015);
}

.qty-input.qty-input-sm::placeholder {
  color: var(--gray-350);
  font-style: italic;
}

/* Primary qty field - slightly larger/emphasized */
.qty-input.qty-primary {
  width: 80px;
  font-weight: 500;
  border-color: var(--gray-300);
}

.qty-input.qty-primary:focus {
  border-color: var(--blue-500);
}

/* Loss/gain input - can be negative */
.qty-input.loss-gain-input {
  color: var(--gray-500);
}

.qty-input.loss-gain-input:focus {
  color: var(--gray-800);
}

/* Spillage input styling */
.qty-input.spillage-input {
  color: var(--gray-400);
}

.qty-input.spillage-input:focus {
  color: var(--gray-800);
}

/* Readonly/computed fields in detailed table */
.lines-table.detailed-table td.font-semibold {
  font-weight: 600;
  color: var(--gray-800);
}

/* Detailed table specific adjustments */
.lines-table.detailed-table th.col-qty {
  width: 85px;
}

.lines-table.detailed-table td.col-qty {
  padding: 0.5rem 0.35rem;
}

/* Container name in edit mode */
.lines-table.detailed-table .container-name {
  font-weight: 500;
  color: var(--gray-800);
}

/* Row highlighting for detailed edit */
.lines-table.detailed-table tr[data-line-type="from"] {
  background: var(--overlay-blue-003);
}

.lines-table.detailed-table tr[data-line-type="to"] {
  background: var(--overlay-green-003);
}

.lines-table.detailed-table tr[data-line-type="from"]:hover,
.lines-table.detailed-table tr[data-line-type="to"]:hover {
  background: var(--overlay-blue-008);
}

/* Loss row in detailed edit */
.lines-table.detailed-table tr.loss-row {
  background: var(--red-50);
}

.lines-table.detailed-table tr.loss-row:hover {
  background: var(--red-100);
}

/* Input validation states */
.qty-input.is-invalid {
  border-color: var(--red-600);
  background: var(--red-50);
}

.qty-input.is-warning {
  border-color: var(--amber-500);
  background: var(--amber-50);
}

/* Conservation violation indicator */
.conservation-error {
  color: var(--red-600);
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* Detailed edit summary enhancements */
.lines-summary.detailed-summary {
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
}

.lines-summary .summary-delta {
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.lines-summary .summary-delta.balanced {
  background: var(--green-100);
  color: var(--green-800);
}

.lines-summary .summary-delta.unbalanced {
  background: var(--red-100);
  color: var(--red-800);
}

/* Tooltip for field help */
.field-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-left: 0.25rem;
  background: var(--gray-200);
  border-radius: 50%;
  font-size: 0.65rem;
  color: var(--gray-500);
  cursor: help;
  vertical-align: middle;
}

.field-help:hover {
  background: var(--gray-300);
  color: var(--gray-700);
}

/* ============================================
   Composition Display Component
   ============================================ */

/* Empty and Loading States */
.composition-empty {
  color: var(--gray-400);
}

.composition-loading {
  color: var(--gray-400);
  font-style: italic;
  font-size: 0.85rem;
}

/* Inline Mode - Single line for table cells */
.composition-inline {
  font-size: 0.85rem;
  color: var(--gray-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
  display: inline-block;
}

/* Summary Mode */
.composition-summary {
  font-size: 0.9rem;
}

.composition-summary-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.composition-attr {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.composition-attr-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--gray-500);
  min-width: 60px;
}

.composition-attr-values {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  color: var(--gray-700);
}

.composition-value {
  display: inline-flex;
  align-items: baseline;
  gap: 0.25rem;
}

.composition-pct {
  font-weight: 600;
  color: var(--gray-800);
}

.composition-key {
  color: var(--gray-600);
}

.composition-more {
  font-size: 0.8rem;
  color: var(--gray-400);
  font-style: italic;
}

/* Expand/Collapse Buttons */
.composition-expand-btn,
.composition-collapse-btn {
  background: none;
  border: none;
  padding: 0.25rem 0;
  font-size: 0.8rem;
  color: var(--blue-500);
  cursor: pointer;
  text-decoration: none;
  margin-top: 0.5rem;
}

.composition-expand-btn:hover,
.composition-collapse-btn:hover {
  color: var(--blue-600);
  text-decoration: underline;
}

/* Full Mode */
.composition-full,
.composition-full-content {
  margin-top: 0.5rem;
}

.composition-full-view {
  padding: 0.75rem 0;
}

.composition-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.composition-total {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-500);
  background: var(--gray-100);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}

.composition-section {
  margin-bottom: 1.25rem;
}

.composition-section:last-child {
  margin-bottom: 0;
}

.composition-section-title {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
}

.composition-attribute {
  margin-bottom: 0.75rem;
}

.composition-attribute:last-child {
  margin-bottom: 0;
}

.composition-attribute-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.35rem;
}

.composition-attribute-value {
  font-size: 0.9rem;
  color: var(--gray-800);
}

/* Breakdown with Bars */
.composition-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.composition-breakdown-row {
  display: grid;
  grid-template-columns: 100px 1fr 45px 70px;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.composition-breakdown-row.simple {
  grid-template-columns: 1fr auto;
}

/* Cost Grid */
.composition-cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.composition-cost-item {
  background: var(--gray-50);
  border-radius: 6px;
  padding: 0.75rem;
  text-align: center;
}

.composition-cost-item .cost-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.15rem;
}

.composition-cost-item .cost-value {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-800);
}

.composition-cost-item .cost-hint {
  display: block;
  font-size: 0.65rem;
  color: var(--gray-400);
  margin-top: 0.15rem;
}

/* Cost Breakdown drilldown — see docs/design/cost-and-margin.md §5 */
.composition-cost-details {
  margin-top: 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: var(--gray-50);
}

.composition-cost-details > summary.composition-cost-details-summary {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--gray-700);
  user-select: none;
  list-style: revert;
}

.composition-cost-details[open] > summary.composition-cost-details-summary {
  border-bottom: 1px solid var(--gray-200);
}

.composition-cost-component-group {
  padding: 0.5rem 0.75rem 0.75rem;
}

.composition-cost-component-group + .composition-cost-component-group {
  border-top: 1px solid var(--gray-200);
}

.composition-cost-component-title {
  margin: 0 0 0.4rem 0;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

.composition-cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.composition-cost-table th,
.composition-cost-table td {
  padding: 0.3rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
  font-weight: normal;
}

.composition-cost-table tbody tr:last-child th,
.composition-cost-table tbody tr:last-child td {
  border-bottom: none;
}

.composition-cost-table thead th {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.composition-cost-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.composition-cost-table .component-key {
  font-weight: 600;
  color: var(--gray-800);
}

.composition-cost-trace-link {
  font-size: 0.75rem;
  color: var(--blue-600, #2563eb);
  text-decoration: none;
  white-space: nowrap;
}

.composition-cost-trace-link:hover {
  text-decoration: underline;
}


/* ============================================
   Job Card Mobile-First Styles
   ============================================ */

/* Override card margins for job list - tighter spacing */
.job-card.card {
  margin: 0 1rem;
  padding: 0;
  border-left: 3px solid transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

/* Selected/expanded state - clear visual indicator */
.job-card[open] {
  border-left-color: var(--blue-500);
  background: var(--blue-50);
}

.job-card[open].status-draft {
  border-left-color: var(--amber-500);
  background: var(--amber-50);
}

.job-card[open].status-completed {
  border-left-color: var(--green-500);
  background: var(--green-50);
}

/* Tighten task container padding when job is expanded */
.job-card[open] > .border-t > div {
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}

/* Job card summary - compact single row on mobile */
.job-card-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  list-style: none;
  min-height: 44px; /* Touch target */
}

.job-card-summary::-webkit-details-marker {
  display: none;
}

.job-card-summary:hover {
  background: var(--gray-50);
}

.job-card[open] .job-card-summary:hover {
  background: transparent;
}

/* Chevron + Status dot */
.job-card-primary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.job-card-primary .chevron {
  color: var(--gray-400);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.job-card[open] .chevron {
  transform: rotate(90deg);
}

/* Status indicator - compact colored dot */
.job-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.job-status-dot.draft {
  background: var(--amber-400);
}

.job-status-dot.in_progress {
  background: var(--blue-500);
}

.job-status-dot.completed {
  background: var(--green-500);
}

/* Job name/description */
.job-card-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-card-name .inline-edit-input {
  font-weight: 600;
  font-size: 0.9375rem;
}

/* Operation status badge (Draft/Committed) - shown inline */
.job-card-op-status {
  flex-shrink: 0;
}

/* Secondary: Lot (bold) · Name · Count */
.job-card-secondary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
}

/* Lot field - bold, first */
.job-card-lot {
  flex-shrink: 0;
}

.job-card-lot .inline-edit-input {
  font-size: 0.8125rem;
  color: var(--gray-800);
  font-weight: 600;
  field-sizing: content;
  width: auto;
  min-width: 4ch;
  max-width: 140px;
}

/* Info group: name · count */
.job-card-info {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

/* Description field */
.job-card-info .job-card-desc {
  flex: 1;
  min-width: 0;
}

.job-card-info .job-card-desc .inline-edit-input {
  font-size: 0.8125rem;
  color: var(--gray-500);
  field-sizing: content;
  width: auto;
  min-width: 4ch;
}

/* Progress count */
.job-card-info .job-card-progress {
  color: var(--gray-400);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Separators */
.job-card-info .job-card-progress::before {
  content: "·";
  margin: 0 0.5rem;
  color: var(--gray-300);
}

/* Action buttons (status badge, detail link, delete) */
.job-card-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

/* When collapsed, shrink inline-edit inputs to content width
   so surrounding space acts as an expand/collapse target */
.job-card:not([open]) .inline-edit-input {
  field-sizing: content;
  width: auto;
  min-width: 3ch;
}

/* Detail link is DOM-first (for selector matching) but badge shows first visually */
.job-card-actions .job-detail-link { order: 1; }
.job-card-actions .badge { order: 0; }
.job-card-actions .status-dropdown { order: 0; }
.job-card-actions form:last-child { order: 2; }

/* Jobs list container - tight spacing */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Status filter pills - horizontal scroll on mobile */
.status-filters {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 0.25rem;
  margin: 0 1rem;
}

.status-filters::-webkit-scrollbar {
  display: none;
}

.status-filters .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Touch-friendly buttons */
@media (max-width: 639px) {
  .job-card-actions .btn {
    min-height: 36px;
    padding: 0.5rem 0.75rem;
  }

  .job-card-actions .btn-icon-only {
    min-width: 36px;
    padding: 0.5rem;
  }

  /* Stack the job card header so lot + name sit on one row
     and the action buttons wrap to a second, right-aligned row.
     Prevents the lot/name inputs from colliding with the status
     dropdown, detail link, and delete button on narrow screens. */
  .job-card-secondary {
    flex-wrap: wrap;
    row-gap: 0.375rem;
  }

  .job-card-actions {
    flex: 1 1 100%;
    justify-content: flex-end;
  }
}


/* ============================================
   Task Card Styles (Job Page)
   ============================================ */

.task-card {
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: var(--color-surface);
  margin-bottom: 0.5rem;
}

.task-card[open] {
  border-color: var(--gray-300);
  border-radius: 4px;
}

.task-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.task-row-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 0%;
  min-width: 0;
}

.task-row-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.task-row::-webkit-details-marker {
  display: none;
}

.task-row:hover {
  background: var(--gray-50);
}

.task-chevron {
  font-size: 1rem;
  color: var(--gray-400);
  transition: transform 0.15s ease;
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.task-card[open] .task-chevron {
  transform: rotate(90deg);
}

.task-number {
  color: var(--gray-400);
  font-size: 0.75rem;
  font-family: monospace;
  width: 1.25rem;
  flex-shrink: 0;
}

.task-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.task-status-pending {
  background: var(--gray-300);
}

.task-status-in_progress {
  background: var(--blue-500);
}

.task-status-completed {
  background: var(--green-500);
}

.task-description {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.task-description-form {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
}

.task-description-input {
  field-sizing: content;
  width: auto;
  min-width: 4ch;
  font-weight: 500;
  font-size: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
  margin: -0.15rem -0.35rem;
  color: inherit;
}

.task-description-input:hover {
  border-color: var(--gray-300);
  background: var(--gray-50);
}

.task-description-input:focus {
  outline: none;
  border-color: var(--blue-500);
  background: var(--color-surface);
  box-shadow: 0 0 0 2px var(--overlay-blue-015);
}

.task-description-input::placeholder {
  color: var(--gray-400);
  font-weight: 400;
}

.task-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.task-edit {
  color: var(--gray-400);
  text-decoration: none;
  padding: 0.25rem;
}

.task-edit:hover {
  color: var(--gray-700);
}

.task-delete {
  color: var(--gray-400);
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.task-delete:hover {
  color: var(--danger, #dc2626);
}

/* Touch-friendly task actions on mobile */
@media (max-width: 639px) {
  .task-actions .btn-xs {
    min-height: 36px;
    min-width: 52px;
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
  }

  .task-actions .badge-action {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.625rem;
  }

  .task-edit,
  .task-delete {
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
  }

  /* Stack task rows vertically on mobile: description on its own
     line, then the badge + status dropdown + edit/delete wraps to
     a second line, indented under the description so the layout
     still reads as a single logical item. Prevents the
     field-sizing:content description input from overlapping the
     type badge and status dropdown on narrow screens. */
  .task-row-main {
    flex: 1 1 100%;
  }

  .task-row-meta {
    flex: 1 1 100%;
    /* Indent to align with description text: chevron (1rem) +
       gap (0.5rem) + number (1.25rem) + gap (0.5rem) = 3.25rem */
    padding-left: 3.25rem;
  }

  .task-mini-tile-wrapper {
    max-width: 100%;
  }
}

/* ===== Unified Status Dropdown ===== */
/* Used by jobs, tasks, and operations for consistent status badge + transition menu */

.status-dropdown {
  position: relative;
  display: inline-block;
}

.status-dropdown > summary {
  list-style: none;
  cursor: pointer;
}

.status-dropdown > summary::-webkit-details-marker {
  display: none;
}

.badge-action {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

/* button_to wraps in a form — keep it inline */
form:has(> .badge-action) {
  display: inline;
}

button.badge-action {
  border: none;
  font: inherit;
}

.badge-action:hover {
  filter: brightness(0.93);
}

/* SVG caret icon inside badge */
.badge-caret-icon {
  width: 0.55em;
  height: 0.55em;
  opacity: 0.65;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
}

.status-dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 20;
  min-width: 120px;
  padding: 0.25rem;
}

/* When the controller portals the menu to <body> to escape ancestor
   overflow:hidden (e.g. collapsible job/task cards), switch to fixed
   positioning driven by inline top/left from getBoundingClientRect(). */
.status-dropdown-menu--portaled {
  position: fixed;
  right: auto;
  top: 0;
  left: 0;
  margin-top: 0;
  z-index: 1000;
}

/* button_to wraps in a form — keep it flush inside the dropdown */
.status-dropdown-menu form {
  margin: 0;
  padding: 0;
}

.status-dropdown-item {
  display: block;
  width: 100%;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  text-align: left;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--gray-700);
  text-decoration: none;
}

.status-dropdown-item:hover {
  background: var(--gray-100);
}

.status-dropdown-item--success {
  color: var(--green-700, #15803d);
  font-weight: 500;
}

.status-dropdown-item--success:hover {
  background: var(--green-50, #f0fdf4);
}

.status-dropdown-item--commit {
  color: var(--amber-800, #92400e);
  font-weight: 500;
}

.status-dropdown-item--commit:hover {
  background: var(--amber-50, #fffbeb);
}

.task-content {
  border-top: 1px solid var(--gray-200);
  padding: 0.75rem;
  background: var(--gray-50);
  font-size: 0.875rem;
}

/* Note preview in header */
.note-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gray-700);
  font-size: 0.875rem;
}

/* Note inline editor */
.note-editor {
  padding: 0.5rem;
  background: var(--gray-50);
}

.note-form {
  width: 100%;
}

.note-textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  font-size: 0.875rem;
  font-family: inherit;
  resize: vertical;
  min-height: 4rem;
  background: var(--color-surface);
}

.note-textarea:focus {
  outline: none;
  border-color: var(--primary, #4f46e5);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.note-hint {
  margin-top: 0.25rem;
  text-align: right;
}

.task-lab-results {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.lab-result-item {
  display: inline-flex;
  align-items: center;
  background: var(--gray-100);
  border-radius: 4px;
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
}

.lab-result-key {
  color: var(--gray-500);
  margin-right: 0.25rem;
}

.lab-result-value {
  font-weight: 600;
  color: var(--gray-800);
}

/* Mini tile embedded in task row — hidden when card is expanded to avoid duplication */
.task-card[open] .task-mini-tile-wrapper {
  display: none;
}

.task-mini-tile-wrapper {
  flex-shrink: 1;
  min-width: 0;
  max-width: 300px;
}

.task-mini-tile-wrapper .mini-tile-card {
  display: flex;
  border-radius: 6px;
  font-size: 0.75rem;
}

.task-mini-tile-wrapper .mini-tile-card > div {
  padding: 0.25rem 0.5rem;
}

/* Task list (unified tasks index) */
.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.task-list-item {
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
}

.task-list-item:hover {
  border-color: var(--gray-300);
}

.task-list-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}

.task-list-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.task-list-content {
  flex: 1;
  min-width: 0;
}

.task-list-title {
  font-weight: 500;
  color: var(--gray-900);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-list-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.8125rem;
}

.task-list-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Filter row styles */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.filter-label {
  font-size: 0.8125rem;
  color: var(--gray-500);
  margin-right: 0.25rem;
}

/* Job add actions (+ Operation, + Lab Test, + Note links) */
.job-add-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.job-add-actions form {
  display: contents;
}

.job-add-actions button,
.job-add-actions a {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* ============================================
   Inline Edit Inputs
   ============================================ */

.inline-edit-form {
  display: inline-block;
}

.inline-edit-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
  margin: -0.15rem -0.35rem;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  width: 100%;
  min-width: 120px;
  max-width: 400px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.inline-edit-input:hover {
  border-color: var(--gray-300);
  background: var(--gray-50);
}

.inline-edit-input:focus {
  outline: none;
  border-color: var(--blue-500);
  background: var(--color-surface);
  box-shadow: 0 0 0 2px var(--overlay-blue-015);
}

.inline-edit-input::placeholder {
  color: var(--gray-400);
  font-weight: 400;
}

/* Mobile: larger touch targets for inline editing */
@media (max-width: 639px) {
  .inline-edit-input {
    padding: 0.5rem 0.5rem;
    margin: -0.5rem -0.5rem;
    min-height: 36px;
  }
}

/* ============================================
   Public layout nav + footer
   ============================================ */

.public-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--color-sidebar-bg);
  border-bottom: 1px solid var(--slate-700);
}

.public-nav-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 400;
}

.public-nav-logo:hover {
  opacity: 0.85;
}

.public-nav-logo .logo-suffix {
  color: var(--slate-300);
}

.public-nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.public-nav-link {
  font-size: 0.875rem;
  color: var(--slate-300);
  text-decoration: none;
  transition: color 0.1s ease;
}

.public-nav-link:hover {
  color: #fff;
}

.public-footer {
  border-top: 1px solid #e5e7eb;
  padding: 1.5rem;
  text-align: center;
  background: #fff;
}

.public-footer-text {
  font-size: 0.8125rem;
  color: #9ca3af;
  margin: 0;
}

.public-footer-link {
  color: #6b7280;
  text-decoration: none;
}

.public-footer-link:hover {
  color: #111827;
  text-decoration: underline;
}
