:root {
  --bg: #f4faf4;
  --surface: #ffffff;
  --surface-soft: #f7fbf7;
  --line: #d8e7d9;
  --text: #1b3425;
  --muted: #5b6f62;
  --primary: #1f8c4d;
  --primary-dark: #15643a;
  --primary-soft: #e7f5eb;
  --green-strong: #0f6e39;
  --blue: #2f7de1;
  --blue-soft: #eef5ff;
  --warn: #c58a00;
  --warn-soft: #fff5dd;
  --danger: #cf453d;
  --danger-soft: #fff0ee;
  --shadow: 0 20px 44px rgba(19, 67, 37, 0.08);
  --radius: 18px;
  --radius-lg: 24px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(180deg, #f8fcf8 0%, var(--bg) 100%);
  color: var(--text);
}

a {
  color: var(--primary-dark);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

button, input, select, textarea {
  font: inherit;
}

button { cursor: pointer; }

h1, h2, h3, h4, p { margin: 0; }

small { color: var(--muted); }

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  padding: 28px 22px;
  background: linear-gradient(180deg, #0d4f2c 0%, #176b3c 54%, #1f8c4d 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 22px 0 40px rgba(17, 70, 38, 0.10);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-logo {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  object-fit: cover;
  background: #fff;
  border: 3px solid rgba(255, 255, 255, 0.2);
}

.brand strong {
  display: block;
  font-size: 1.15rem;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.95rem;
  line-height: 1.4;
}

.nav {
  display: grid;
  gap: 10px;
}

.nav-link {
  padding: 13px 15px;
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.88);
  font-weight: 600;
  transition: 0.2s ease;
  border: 1px solid transparent;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
  text-decoration: none;
}

.sidebar-user {
  margin-top: auto;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  display: grid;
  gap: 12px;
}

.sidebar-user strong {
  display: block;
  margin-top: 4px;
  color: #fff;
}

.sidebar-user span {
  display: block;
  margin-top: 3px;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.84);
}

.layout-main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}

.topbar h1 {
  margin-top: 8px;
  font-size: clamp(1.7rem, 3vw, 2.55rem);
  line-height: 1.08;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
  max-width: 920px;
  line-height: 1.55;
}

.topbar-side {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 1px solid #d3ead8;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.empty-state {
  text-align: center;
  padding: 40px 24px;
}

.empty-state p {
  margin: 10px 0 18px;
  color: var(--muted);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card, .preview-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.metric-card::after,
.preview-card::after {
  content: '';
  position: absolute;
  right: -18px;
  top: -18px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(31, 140, 77, 0.14), rgba(31, 140, 77, 0.02));
}

.metric-card small,
.preview-card small {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric-card strong,
.preview-card strong {
  display: block;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.1;
  color: var(--text);
}

.metric-card span,
.preview-card span {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  grid-column: 1 / -1;
  margin-bottom: 4px;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.section-header h2 {
  font-size: 1.22rem;
  margin-bottom: 6px;
}

.section-header p {
  color: var(--muted);
  line-height: 1.55;
  max-width: 860px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label,
.checkbox-label {
  font-weight: 700;
  color: var(--text);
}

input, select, textarea {
  width: 100%;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea {
  resize: vertical;
  min-height: 110px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(31, 140, 77, 0.6);
  box-shadow: 0 0 0 4px rgba(31, 140, 77, 0.12);
  background: #fff;
}

.checkbox-field {
  align-content: end;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-weight: 700;
  transition: 0.18s ease;
  text-decoration: none;
}

.btn:hover { text-decoration: none; transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 12px 24px rgba(21, 100, 58, 0.18);
}

.btn-primary:hover { color: #fff; }

.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #ffd1cb;
  color: #8e241e;
}

.btn-small {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 0.92rem;
}

.btn-block {
  width: 100%;
}

.filters-grid {
  align-items: end;
}

.top-gap { margin-top: 20px; }
.top-gap-sm { margin-top: 8px; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
}

.small-table {
  min-width: 640px;
}

.data-table th,
.data-table td {
  border-top: 1px solid #edf3ee;
  padding: 14px 12px;
  vertical-align: top;
  text-align: left;
}

.data-table th {
  background: #f9fcf9;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-top: none;
  position: sticky;
  top: 0;
}

.data-table tbody tr:hover {
  background: #fbfefb;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill, .tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-pill { margin-bottom: 6px; }

.status-programada {
  background: #eef4ff;
  border-color: #d9e5ff;
  color: #335ba8;
}

.status-carregando,
.status-aguardando_descarga {
  background: var(--warn-soft);
  border-color: #ffe2a8;
  color: #8b6200;
}

.status-em_transito {
  background: var(--primary-soft);
  border-color: #cfe8d6;
  color: var(--green-strong);
}

.status-finalizada {
  background: #e9f7ef;
  border-color: #caebd7;
  color: #137141;
}

.status-cancelada {
  background: var(--danger-soft);
  border-color: #ffd1cb;
  color: #a0312c;
}

.tag-green {
  background: var(--primary-soft);
  color: var(--green-strong);
  border-color: #d1ebd9;
}

.tag-blue {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #dceaff;
}

.tag-warn {
  background: var(--warn-soft);
  color: #8b6200;
  border-color: #f5d28c;
}

.tag-red {
  background: var(--danger-soft);
  color: #8e241e;
  border-color: #ffd0cb;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-weight: 600;
}

.flash.success {
  background: #ebf8ef;
  border-color: #cdebd7;
  color: #176c3d;
}

.flash.danger {
  background: #fff1ef;
  border-color: #ffd3cd;
  color: #992d27;
}

.flash.warning {
  background: #fff7e4;
  border-color: #f9dea5;
  color: #856000;
}

.flash.info {
  background: #edf5ff;
  border-color: #d8e8ff;
  color: #2358a5;
}

.links-list {
  display: grid;
  gap: 6px;
}

.alert-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.alert-card {
  background: var(--warn-soft);
  border: 1px solid #f5d28c;
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 6px;
}

.alert-card strong { color: #8a6100; }

.empty-inline {
  padding: 14px 0;
  color: var(--muted);
  text-align: center;
}

.anchor-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.anchor-tabs a {
  padding: 12px 15px;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  font-weight: 700;
  box-shadow: var(--shadow);
}

.grid-columns.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.metrics-inline {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.metrics-inline div {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  min-width: 180px;
}

.metrics-inline small {
  display: block;
  margin-bottom: 8px;
}

.metrics-inline strong {
  font-size: 1.2rem;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.attachment-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.attachment-card strong {
  display: block;
  margin-bottom: 8px;
}

.login-body {
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(31, 140, 77, 0.22), transparent 30%), linear-gradient(180deg, #eff7f0 0%, #f8fcf8 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(560px, 100%);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: 0 30px 60px rgba(19, 67, 37, 0.12);
  padding: 28px;
}

.login-logo {
  width: min(100%, 260px);
  margin: 0 auto 12px;
  border-radius: 18px;
}

.login-brand {
  text-align: center;
  margin-bottom: 18px;
}

.login-brand h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.login-brand p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.55;
}

.login-panel {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
}

.login-panel h2 {
  margin-bottom: 6px;
}

.login-panel p {
  margin-bottom: 16px;
  color: var(--muted);
  line-height: 1.5;
}

.login-flashes {
  margin-bottom: 14px;
}

.menu-toggle {
  display: none;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

@media (max-width: 1280px) {
  .metrics-grid,
  .preview-grid,
  .form-grid,
  .form-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

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

  .layout-main {
    padding: 18px;
  }

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

  .topbar {
    gap: 12px;
  }

  .grid-columns.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .metrics-grid,
  .preview-grid,
  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  .layout-main,
  .card,
  .login-card {
    padding-left: 16px;
    padding-right: 16px;
  }

  .card {
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .topbar {
    flex-direction: column;
  }

  .actions-row,
  .table-actions,
  .topbar-side {
    width: 100%;
  }

  .actions-row .btn,
  .table-actions .btn,
  .topbar-side .btn {
    width: 100%;
  }

  .metrics-inline div {
    width: 100%;
  }
}


/* v10 additions */
.grid-columns.three {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.mini-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.mini-kpis > div {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.mini-kpis small,
.mini-kpis span {
  display: block;
  color: var(--muted);
}

.mini-kpis strong {
  display: block;
  margin: 6px 0 4px;
  font-size: 1.35rem;
}

.rank-list {
  display: grid;
  gap: 12px;
}

.rank-item {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.rank-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.rank-head span {
  color: var(--primary-dark);
  font-weight: 700;
}

.progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e6f2e8;
  overflow: hidden;
}

.progress.compact {
  margin-top: 8px;
  height: 8px;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green-strong) 0%, var(--primary) 100%);
}

.selectable-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.selectable-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.selectable-item input {
  margin-top: 2px;
}

.selectable-item strong,
.selectable-item span,
.selectable-item small {
  display: block;
}

.selectable-item span {
  margin-top: 4px;
}

.selectable-item small {
  margin-top: 6px;
}

.login-card.simple {
  width: min(480px, 100%);
}

.login-brand.compact p {
  margin-top: 8px;
}

@media (max-width: 1280px) {
  .grid-columns.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .grid-columns.three,
  .grid-columns.two,
  .metrics-grid,
  .preview-grid,
  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  .mini-kpis {
    grid-template-columns: 1fr 1fr;
  }
}


/* v11 additions */
.metrics-grid.six {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-form select,
.inline-form input {
  min-width: 120px;
  flex: 1 1 120px;
}

.compact-inline {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.compact-inline .btn {
  min-height: 36px;
}

.analytics-wide {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.analytics-wide .card,
.grid-columns.two > .card,
.grid-columns.three > .card {
  min-width: 0;
}

.topbar-side .tag {
  min-height: 46px;
}

@media (max-width: 1440px) {
  .metrics-grid.six {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .metrics-grid.six {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-inline,
  .inline-form {
    width: 100%;
  }

  .compact-inline select,
  .compact-inline input,
  .compact-inline .btn,
  .inline-form select,
  .inline-form input,
  .inline-form .btn {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .metrics-grid.six {
    grid-template-columns: 1fr;
  }
}

/* v13 CRM + clean layout */
.topbar p,
.section-header p {
  display: none;
}

.section-header {
  margin-bottom: 12px;
}

.wide-table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
}

.wide-table-wrap .data-table {
  min-width: max(100%, 1280px);
}

.matrix-table {
  min-width: max(100%, 1560px);
  font-size: 0.92rem;
}

.matrix-table th,
.matrix-table td {
  white-space: nowrap;
}

.matrix-table th:first-child,
.matrix-table td:first-child,
.wide-table-wrap .data-table th:first-child,
.wide-table-wrap .data-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
}

.wide-table-wrap .data-table thead th:first-child,
.matrix-table thead th:first-child {
  background: #f9fcf9;
  z-index: 4;
}

.analytics-wide > .card,
section.card,
.grid-columns.two > .card,
.grid-columns.three > .card {
  min-width: 0;
}

@media (min-width: 1500px) {
  .layout-main {
    padding-left: 24px;
    padding-right: 24px;
  }

  .analytics-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
