* { box-sizing: border-box; }

html { font-size: 90%; }

:root {
  --color-primary: #1d4ed8;
  --color-primary-dark: #1e3a8a;
  --color-grey-bg: #f5f5f5;
  --color-grey-border: #d1d5db;
  --color-grey-text: #6b7280;
}

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  background: var(--color-grey-bg);
  color: #1a1a1a;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--color-primary-dark);
  color: white;
}

.brand-row { display: flex; align-items: center; gap: 1rem; }
.brand-row .logo { height: 80px; width: auto; }

.topbar a { color: white; margin-left: 1rem; text-decoration: none; }
.topbar nav { display: flex; align-items: center; }
.topbar .user { margin-left: 1rem; opacity: 0.8; }

main { padding: 2rem; max-width: 960px; margin: 0 auto; }

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  max-width: 420px;
  margin: 0 auto;
}

.login-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.login-form input { padding: 0.6rem; font-size: 1.1rem; }
.login-form button {
  padding: 0.7rem;
  font-size: 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.flashes { list-style: none; padding: 0; }
.flash-error { color: #b91c1c; background: #fee2e2; padding: 0.5rem 1rem; border-radius: 4px; }

.panel {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 1.5rem;
}

.header-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1rem; }
.header-row h1 { margin: 0; }
.meta { color: #6b7280; font-size: 0.9rem; }

.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: #e5e7eb; color: #1a1a1a; }
.btn-danger { background: #b91c1c; }
.btn-small { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; }
.field label { font-size: 0.9rem; }
.field input, .field select { padding: 0.5rem; font-size: 1rem; }
.field input[readonly] { background: #f3f4f6; color: #4b5563; }
.field-row { display: flex; gap: 1rem; }
.field-row .field { flex: 1; }
.field-narrow { max-width: 20%; }
.field-row .field-narrow { flex: 0 0 20%; }
#bales-fields, #loose-fields { display: contents; }

.search-wrap { position: relative; }
.search-results {
  position: absolute;
  z-index: 10;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #d1d5db;
  border-top: none;
  max-height: 300px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}
.search-results li {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.search-results li:hover { background: #f3f4f6; }
.search-results .product-meta { font-size: 0.8rem; color: #6b7280; }
.search-results .search-no-match { cursor: default; color: #b91c1c; }
.search-results .search-no-match:hover { background: white; }

.selected-product {
  background: #eff6ff;
  padding: 0.75rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

table.lines-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
table.lines-table th, table.lines-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e5e7eb;
}
table.lines-table tfoot td { font-weight: bold; border-top: 2px solid var(--color-primary-dark); }
table.lines-table .text-center { text-align: center; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-posted { background: #dcfce7; color: #166534; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  position: relative;
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.modal ul { padding-left: 1.2rem; }
.modal .modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }
.hidden { display: none !important; }
.field-error { display: block; color: var(--color-danger, #c0392b); font-size: 0.85rem; margin-top: 0.25rem; }

.print-only { display: none; }

@media print {
  .topbar, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  .print-only { display: block; }
}
