:root {
  --bg: #EBE7DC;
  --surface: #FFFFFF;
  --surface-2: #F5F2EA;
  --ink: #20291F;
  --ink-soft: #5B6459;
  --primary: #24463A;
  --primary-light: #35604F;
  --accent: #B9832A;
  --accent-soft: #EFDCB0;
  --line: #D8D2C0;
  --danger: #A23B2E;
  --danger-soft: #F3DAD5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 8px 90px;
}

.app-narrow { max-width: 480px; }

.navbar {
  background: var(--primary);
  border-bottom: 3px solid var(--accent);
}

.navbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
}

.navbar-brand {
  font-family: 'Roboto Slab', serif;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
}

.navbar-links {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.navbar-links a {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
}

.navbar-links a:hover { color: #fff; background: rgba(255,255,255,0.08); }
.navbar-links a.active { color: #fff; background: rgba(255,255,255,0.16); }

.app-header, .page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.page-header-tight { margin-bottom: 18px; }

.app-header h1, .page-header h1 {
  font-family: 'Roboto Slab', serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.page-header { align-items: center; }

.subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-bottom: 20px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.tab.active { background: var(--primary); color: #fff; }

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.card-header h2 {
  font-family: 'Roboto Slab', serif;
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.badge {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.field { display: flex; flex-direction: column; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
.input:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 1px;
  border-color: var(--primary-light);
}

.numero-input { font-size: 17px; font-weight: 600; }

.linha-row {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  margin: 0 -6px 10px;
}

.linha-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.linha-label {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
}

.btn-remove-linha {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
}

.linha-grid {
  display: grid;
  grid-template-columns: 0.7fr 0.35fr 1.45fr 1.05fr 1.05fr 0.9fr;
  gap: 8px;
  width: 100%;
}

.field-wide { grid-column: span 1; }

.linha-grid .field label { font-size: 11px; }
.linha-grid .input { padding: 8px 9px; font-size: 13px; }

.btn-add {
  margin-top: 4px;
  width: 100%;
}

.btn-primary, .btn-ghost, .btn-danger, .btn-danger-text {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  padding: 11px 20px;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-light); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 6px 12px;
  font-size: 13px;
}

.btn-danger-text {
  background: transparent;
  color: var(--danger);
  padding: 8px 12px;
}
.btn-danger-text:hover { background: var(--danger-soft); }

.btn-small { padding: 8px 12px; font-size: 13px; }

.actions { display: flex; align-items: center; gap: 12px; }

.hidden { display: none !important; }

.search-box { margin-bottom: 14px; }

.empty-state, .loading {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

.guia-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}

.guia-card-header {
  width: 100%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.guia-card-info { display: flex; align-items: center; gap: 12px; min-width: 0; }

.stamp {
  font-family: 'Roboto Slab', serif;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid var(--accent);
  color: var(--accent);
  transform: rotate(-2deg);
  border-radius: 6px;
  padding: 4px 8px;
  flex-shrink: 0;
  white-space: nowrap;
}

.guia-card-text { min-width: 0; }

.guia-cliente {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guia-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.chevron { color: var(--ink-soft); flex-shrink: 0; font-size: 16px; }

.guia-card-body { padding: 0 14px 14px; }

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead tr { background: var(--surface-2); }

th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

td { padding: 8px 10px; border-top: 1px solid var(--line); }

.guia-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.confirm-delete {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  z-index: 50;
}

.error-box {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
}

.toast-static {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
}
.toast-static.success { background: var(--accent-soft); color: var(--accent); }

.list-card { padding: 0; overflow: hidden; }
.list-card table { font-size: 14px; }
.list-card th { padding: 10px 16px; }
.list-card td { padding: 12px 16px; }
.list-card tbody tr:hover { background: var(--surface-2); }

.col-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}

.inline-form { display: inline; }

.form-page { max-width: 100%; }
.form-page .field { margin-bottom: 16px; }
.form-page .field:last-of-type { margin-bottom: 20px; }

select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235B6459' stroke-width='1.6' fill='none' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

.linha-grid select.input { background-position: right 8px center; padding-right: 26px; }

.f-nrProdutor { background: var(--surface-2); color: var(--ink-soft); }

@media (max-width: 640px) {
  .grid-3 { grid-template-columns: 1fr; }
  .linha-grid { grid-template-columns: repeat(2, 1fr); }
  .field-wide { grid-column: span 2; }
}

@media (max-width: 900px) {
  .app {
    padding-left: 8px;
    padding-right: 8px;
  }

  .linha-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .field-wide {
    grid-column: span 2;
  }
}
