:root {
  --color-primary: #2d5016;
  --color-primary-light: #4a7a2e;
  --color-primary-dark: #1a3009;
  --color-accent: #6b8f3c;
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #e0e0e0;
  --color-border-light: #f0f0f0;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-text-muted: #999999;
  --color-compliance-good: #2e7d32;
  --color-compliance-warn: #f9a825;
  --color-compliance-bad: #c62828;
  --color-warning: #b0601a;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;
  --nav-height: 56px;
  --subnav-height: 44px;
  --content-max-width: 1200px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
}
a { color: var(--color-primary); }

.main-nav {
  display: flex;
  align-items: center;
  height: var(--nav-height);
  padding: 0 var(--space-lg);
  background: var(--color-primary);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10000;
}
.nav-brand a {
  color: white;
  font-weight: 700;
  font-size: var(--font-size-lg);
  text-decoration: none;
  margin-right: var(--space-xl);
  white-space: nowrap;
}
.nav-links { display: flex; gap: var(--space-sm); flex: 1; }
.nav-link {
  color: rgba(255, 255, 255, 0.8);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  text-decoration: none;
}
.nav-link:hover { color: white; background: rgba(255, 255, 255, 0.15); text-decoration: none; }
.nav-link.active { color: white; background: rgba(255, 255, 255, 0.2); }
.nav-user { display: flex; align-items: center; gap: var(--space-md); }
.nav-username { font-size: var(--font-size-sm); opacity: 0.8; }

.sub-nav {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: var(--subnav-height);
  align-items: center;
}
.sub-nav-link {
  color: var(--color-text-secondary);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  text-decoration: none;
  white-space: nowrap;
}
.sub-nav-link:hover { color: var(--color-text); background: var(--color-bg); text-decoration: none; }
.sub-nav-link.active { color: var(--color-primary); font-weight: 600; background: var(--color-bg); }

.content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-lg);
  min-height: calc(100vh - var(--nav-height) - 60px);
}
.status-line {
  margin-bottom: var(--space-md);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}
.main-footer {
  text-align: center;
  padding: var(--space-lg);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  border-top: 1px solid var(--color-border-light);
}
.page-header { margin-bottom: var(--space-lg); }
.page-header h1 { margin: 0 0 var(--space-xs); font-size: var(--font-size-2xl); }
.subtle { color: var(--color-text-secondary); margin: 0; }
.text-secondary { color: var(--color-text-secondary); }
.view { display: none; }
.view.active { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}
.card h2 { font-size: var(--font-size-lg); margin: 0 0 var(--space-md); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-md); }
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.toolbar label {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 600;
}
.toolbar .table-filter { width: auto; margin-bottom: 0; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.kpi-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  text-align: center;
}
.kpi-value { font-size: var(--font-size-2xl); font-weight: 700; color: var(--color-primary); margin-bottom: var(--space-xs); }
.kpi-label { font-size: var(--font-size-sm); color: var(--color-text-secondary); }

.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-lg); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; font-size: var(--font-size-sm); border-collapse: collapse; }
.data-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 2px solid var(--color-border);
  color: var(--color-text-secondary);
  font-weight: 600;
  white-space: nowrap;
}
.data-table td { padding: var(--space-sm) var(--space-md); border-bottom: 1px solid var(--color-border-light); }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--color-text); background: var(--color-bg); }
.data-table th.sortable::after { content: ""; display: inline-block; min-width: 1em; margin-left: 0.35em; color: var(--color-text-muted); }
.data-table th.sortable.sorted-asc::after { content: "▲"; }
.data-table th.sortable.sorted-desc::after { content: "▼"; }
.data-table tbody tr:hover { background: var(--color-bg); }
.text-right, .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-toggle { cursor: pointer; }
.row-detail { background: var(--color-bg); }
.row-detail td { font-size: var(--font-size-xs); color: var(--color-text-secondary); border-bottom-color: var(--color-border-light); }
.detail-client, .detail-product, .detail-supplier { padding-left: var(--space-xl) !important; }
.detail-section td { color: var(--color-text); }
.compliance-good { color: var(--color-compliance-good); }
.compliance-warn { color: var(--color-compliance-warn); }
.compliance-bad { color: var(--color-compliance-bad); }
.bg-good { background: var(--color-compliance-good); }
.bg-warn { background: var(--color-compliance-warn); }
.bg-bad { background: var(--color-compliance-bad); }
.compliance-bar-track { height: 16px; background: var(--color-border-light); border-radius: var(--radius-sm); overflow: hidden; }
.compliance-bar { height: 100%; border-radius: var(--radius-sm); transition: width 0.5s ease; }
.table-filter {
  width: 100%;
  max-width: 400px;
  padding: var(--space-xs) var(--space-sm);
  margin-bottom: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
}
.table-filter:focus { outline: none; border-color: var(--color-primary); }

.category-bars { display: flex; flex-direction: column; gap: var(--space-md); }
.category-row { display: flex; align-items: center; gap: var(--space-md); }
.category-label { width: 100px; font-size: var(--font-size-sm); font-weight: 500; }
.category-bar-track { flex: 1; height: 24px; background: var(--color-bg); border-radius: var(--radius-sm); overflow: hidden; }
.category-bar { height: 100%; border-radius: var(--radius-sm); background: var(--color-primary); transition: width 0.5s ease; }
.category-value { width: 120px; font-size: var(--font-size-sm); color: var(--color-text-secondary); text-align: right; white-space: nowrap; }
.bar-label { width: 200px; font-size: var(--font-size-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-value { width: 100px; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-lg); margin-top: var(--space-lg); }
.chart-container { position: relative; height: 320px; }
.legend-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 16px; font-size: var(--font-size-sm); color: var(--color-text-secondary); }
.month-selector { display: flex; gap: var(--space-xs); flex-wrap: wrap; }
.month-btn {
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--color-text);
  font-size: var(--font-size-sm);
}
.month-btn:hover { background: var(--color-bg); text-decoration: none; }
.month-btn.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.month-btn.disabled { opacity: 0.5; cursor: default; background: var(--color-bg); }
.heatmap-scroll { overflow-x: auto; }
.heatmap-table { border-collapse: collapse; font-size: var(--font-size-xs); }
.heatmap-header { writing-mode: vertical-lr; transform: rotate(180deg); padding: var(--space-sm); white-space: nowrap; font-weight: 600; }
.heatmap-producer { white-space: nowrap; padding: var(--space-xs) var(--space-sm); font-weight: 500; font-size: var(--font-size-xs); }
.heatmap-cell { width: 40px; min-width: 40px; height: 32px; text-align: center; vertical-align: middle; font-size: 10px; font-weight: 600; border: 1px solid white; }
.heatmap-empty { background: var(--color-bg); }
.heatmap-good { background: #bbf7d0; color: #166534; }
.heatmap-warn { background: #fef08a; color: #854d0e; }
.heatmap-bad { background: #fecaca; color: #991b1b; }
.section-heading { font-size: var(--font-size-xl); color: var(--color-text-secondary); margin: var(--space-xl) 0 var(--space-md); padding-bottom: var(--space-xs); border-bottom: 2px solid var(--color-border); }
.vehicle-stops-header { font-size: var(--font-size-base); margin: var(--space-lg) 0 var(--space-sm); padding-bottom: var(--space-xs); border-bottom: 1px solid var(--color-border-light); }
.inline-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.inline-input { min-width: 260px; padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font: inherit; }
.inline-input.plan-product-display,
.inline-input.plan-product-category,
.inline-input.plan-product-sort { min-width: 0; width: 100%; }
.kg-input { width: 58px; padding: 4px 6px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font: inherit; text-align: right; }
.month-cell { min-width: 98px; }
.month-ref { font-size: 11px; line-height: 1.2; margin-bottom: 2px; white-space: nowrap; }
.global-ref { color: #516273; }
.producer-ref { color: #7759a6; }
.mini-input-wrap { display: flex; align-items: center; gap: 4px; margin-top: 3px; justify-content: flex-end; font-size: 11px; }
.mini-input-wrap span { color: var(--color-text-secondary); min-width: 10px; text-align: left; }
.catalog-create-grid > * { flex: 1 1 180px; }
.catalog-actions { justify-content: flex-end; margin-top: 0; }
.catalog-status {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border: 1px solid var(--color-border-light);
}
.catalog-status.is-active { background: #eefaf0; color: #17633a; }
.catalog-status.is-archived { background: #f5f5f5; color: #6b7280; }
.small-line { margin-top: 4px; font-size: var(--font-size-xs); }
.offer-input { background: #eef5ff; border-color: #a8c7fa; }
.commit-input { background: #eefaf0; border-color: #9ad0a5; }
.monthly-prices { display: flex; gap: var(--space-xs); flex-wrap: wrap; }
.price-pill {
  display: inline-flex;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
}
.monthly-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: var(--space-xs);
}
.price-editor-pill {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
}
.price-editor-pill input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
}
.inline-save-bar {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}
.card-header-nav { display: flex; align-items: center; gap: var(--space-md); margin-bottom: var(--space-lg); }
.nav-period-label { flex: 1; text-align: center; font-size: var(--font-size-lg); font-weight: 700; }
.nav-arrow { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--color-bg); border: 1px solid var(--color-border); color: var(--color-text); text-decoration: none; font-size: var(--font-size-lg); }
.nav-arrow.nav-disabled { opacity: 0.3; pointer-events: none; }
.cell-with-bar { display: inline-flex; align-items: center; gap: 6px; width: 100%; justify-content: flex-end; }
.mini-bar { display: inline-block; height: 12px; background: var(--color-primary); border-radius: 2px; min-width: 2px; }
.row-inactive td { color: var(--color-text-muted); }
.logistica-map-content, .logistica-parades-content { padding: 0 !important; max-width: none !important; height: calc(100vh - var(--nav-height) - var(--subnav-height)); overflow: hidden; }
#main-map { display: flex; height: 100%; min-height: 620px; }
#map-container { flex: 1; position: relative; }
#map, #stops-map { width: 100%; height: 100%; min-height: 620px; }
#map-controls { position: absolute; top: 10px; right: 10px; z-index: 1000; background: var(--color-surface); padding: 8px 12px; border-radius: var(--radius-md); box-shadow: var(--shadow-md); display: flex; gap: 12px; align-items: center; font-size: var(--font-size-xs); }
#status-bar { position: absolute; bottom: 10px; left: 10px; z-index: 1000; background: rgba(255,255,255,.92); padding: 4px 10px; border-radius: var(--radius-sm); font-size: 12px; color: var(--color-text-secondary); box-shadow: var(--shadow-sm); }
#sidebar, #stops-sidebar { width: 340px; background: var(--color-surface); overflow-y: auto; border-left: 1px solid var(--color-border); padding: 12px; }
.vehicle-card { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.vehicle-card.active { border-color: var(--color-primary); background: #f0f7ec; }
.vehicle-plate { font-weight: 700; color: var(--color-primary); }
.vehicle-details { font-size: 12px; color: var(--color-text-secondary); line-height: 1.5; }
.truck-marker { color: white; border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; border: 2px solid white; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.school-marker { width: 10px; height: 10px; background: #ffe600; border: 2px solid #c8a000; border-radius: 50%; }
.stops-summary { background: #1f2937; color: #e5e7eb; padding: 10px; border-radius: var(--radius-md); margin-bottom: 12px; font-size: var(--font-size-sm); }
.stops-filters label, .stops-legend div { display: block; font-size: var(--font-size-xs); margin-bottom: 6px; }
.stops-table { width: 100%; border-collapse: collapse; font-size: var(--font-size-xs); }
.stops-table th, .stops-table td { padding: 5px; border-bottom: 1px solid var(--color-border-light); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.legend-dot.geofence { background: #4ecca3; } .legend-dot.new { background: #00b4d8; } .legend-dot.frequent { background: #ff6b6b; } .legend-dot.occasional { background: #ffa94d; } .legend-dot.rare { background: #666; } .legend-dot.warehouse { background: #e040fb; }

.hamburger { display: none; background: none; border: none; cursor: pointer; padding: var(--space-sm); margin-left: auto; }
.hamburger span { display: block; width: 22px; height: 2px; background: white; margin: 5px 0; border-radius: 1px; }
.mobile-menu { display: none; }

@media (max-width: 768px) {
  .nav-links, .nav-user, .sub-nav { display: none; }
  .hamburger { display: block; }
  .main-nav { padding: 0 var(--space-md); }
  .nav-open .mobile-menu {
    display: block;
    position: absolute;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--color-primary);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-lg);
    z-index: 99;
  }
  .mobile-section-toggle {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    color: rgba(255, 255, 255, 0.85);
    background: none;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: var(--font-size-base);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
  }
  .mobile-section.open > .mobile-section-toggle { color: white; font-weight: 600; background: rgba(255, 255, 255, 0.08); }
  .mobile-children { display: none; background: rgba(0, 0, 0, 0.15); padding: var(--space-xs) 0; }
  .mobile-section.open > .mobile-children { display: block; }
  .mobile-child-link { display: block; padding: var(--space-sm) var(--space-lg) var(--space-sm) var(--space-2xl); color: rgba(255, 255, 255, 0.7); text-decoration: none; font-size: var(--font-size-sm); }
  .mobile-child-link.active { color: white; font-weight: 600; }
  .content { padding: var(--space-md); }
  .grid-2col { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .category-row { flex-wrap: wrap; }
  .category-label { width: 80px; }
  .category-value { width: 100%; text-align: left; }
  .section-head { display: block; }
  .toolbar { align-items: stretch; flex-direction: column; gap: var(--space-xs); }
  .toolbar .table-filter { width: 100%; }
  .data-table th, .data-table td { padding: var(--space-xs) var(--space-sm); font-size: var(--font-size-xs); }
}
.compact-list {
  margin: 0;
  padding-left: 18px;
}
.compact-list li {
  margin: 2px 0;
}

.offer-page .main-nav,
.offer-page .sub-nav { display: none; }
.offer-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}
.offer-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}
.offer-kicker {
  margin: 0 0 4px;
  color: var(--color-primary);
  font-weight: 700;
  font-size: var(--font-size-sm);
}
.offer-header h1 { margin: 0 0 6px; }
.offer-save-status {
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px 12px;
  background: white;
  color: var(--color-text-secondary);
  white-space: nowrap;
  font-size: var(--font-size-sm);
}
.offer-save-status[data-mode="pending"] { color: var(--color-warning); }
.offer-save-status[data-mode="saving"] { color: var(--color-primary); }
.offer-save-status[data-mode="saved"] { color: var(--color-compliance-good); }
.offer-save-status[data-mode="error"] { color: var(--color-compliance-bad); }
.offer-error { border-color: #f5c2c7; color: var(--color-compliance-bad); }
.offer-instructions p { margin: 0 0 8px; }
.offer-table-scroll { max-height: calc(100vh - 260px); }
.offer-table th { position: sticky; top: 0; background: white; z-index: 2; }
.offer-table .offer-product-col {
  position: sticky;
  left: 0;
  background: white;
  z-index: 3;
  min-width: 190px;
}
.offer-table td { vertical-align: top; }
.offer-cell { min-width: 115px; }
.offer-need,
.offer-price {
  font-size: 11px;
  color: var(--color-text-secondary);
  line-height: 1.25;
  white-space: nowrap;
}
.offer-price { color: var(--color-primary); margin-bottom: 4px; }
.offer-kg-input {
  width: 72px;
  padding: 5px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-align: right;
  font: inherit;
}
.offer-comment-cell { min-width: 220px; }
.offer-comment {
  width: 100%;
  min-width: 200px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  font: inherit;
  resize: vertical;
}
@media (max-width: 760px) {
  .offer-shell { padding: 12px; }
  .offer-header { flex-direction: column; }
  .offer-table-scroll { max-height: none; }
  .offer-cell { min-width: 100px; }
}
.offer-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px 16px;
  margin: 12px 0;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-md);
}
.offer-legend div { display: flex; gap: 8px; }
.offer-legend dt {
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}
.offer-legend dd { margin: 0; color: var(--color-text-secondary); font-size: var(--font-size-sm); }
.offer-input-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--color-text-secondary);
}
.offer-input-label span { color: var(--color-text-muted); }
.public-home-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f8f9fa;
}
.public-home {
  max-width: 680px;
  margin: 24px;
  padding: 32px;
  text-align: center;
  background: white;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.public-home-logo {
  width: 160px;
  height: 28px;
  object-fit: contain;
  margin-bottom: 24px;
}
.public-home p {
  margin: 0 0 20px;
  color: var(--color-text-secondary);
  font-size: var(--font-size-lg);
}
.public-home a {
  display: inline-block;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: white;
  text-decoration: none;
  font-weight: 700;
}
.public-home a:hover { background: var(--color-primary-dark); }
