:root {
  --green: #2f6b3a;
  --green-dark: #1f4a27;
  --bg: #f5f6f2;
  --card: #ffffff;
  --border: #dfe3d8;
  --text: #23291f;
  --muted: #667062;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--green);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  flex-wrap: wrap;
  gap: .5rem;
}
.topbar .brand a { color: white; font-weight: 700; font-size: 1.3rem; }
.topbar .brand .sub { color: #cfe3d1; font-size: .8rem; margin-left: .6rem; }
.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}
.topbar nav a {
  color: #eaf3e8;
  margin-left: 1rem;
  font-size: .95rem;
}
.topbar nav a:first-child { margin-left: 0; }
.topbar nav a:hover { color: white; }
.company-switch {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding-left: 1rem;
  border-left: 1px solid rgba(255,255,255,0.3);
}
.company-switch select {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 5px;
  padding: .3rem .5rem;
  font-size: .85rem;
}
.company-switch select option { color: #23291f; }
.company-switch a {
  color: #eaf3e8;
  font-size: .9rem;
}
.company-switch a:hover { color: white; }

.profile-menu { position: relative; }
.profile-trigger {
  display: flex;
  align-items: center;
  gap: .45rem;
  background: none;
  border: none;
  color: #eaf3e8;
  cursor: pointer;
  font-size: .9rem;
  padding: .25rem .4rem;
  border-radius: 6px;
}
.profile-trigger:hover { color: white; background: rgba(255,255,255,0.15); }
.profile-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255,255,255,0.25);
  flex-shrink: 0;
}
.profile-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
}
.profile-caret { font-size: .65rem; opacity: .85; }
.profile-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  min-width: 150px;
  z-index: 30;
  overflow: hidden;
}
.profile-menu.open .profile-menu-dropdown { display: block; }
.profile-menu-dropdown a {
  display: block;
  padding: .65rem 1rem;
  color: var(--text);
  font-size: .9rem;
}
.profile-menu-dropdown a:hover { background: var(--bg); text-decoration: none; }

.nav-toggle {
  display: none;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  border-radius: 6px;
  padding: .4rem .7rem;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.container { max-width: 1800px; margin: 0 auto; padding: 1.2rem; }

/* Admin panel tabs (Companies / Users / Debugging) -- plain links with a
   ?tab= query param, so each tab is a normal server-rendered page (works
   with no JS, and a form redirect naturally lands back on the right tab). */
.tab-bar {
  display: flex;
  gap: .3rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.3rem;
  flex-wrap: wrap;
}
.tab-link {
  padding: .6rem 1.1rem;
  color: var(--muted);
  font-weight: 600;
  font-size: .95rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab-link:hover { color: var(--green-dark); text-decoration: none; }
.tab-link.active { color: var(--green-dark); border-bottom-color: var(--green); }

.sub-tab-bar {
  display: flex;
  gap: .3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}
.sub-tab-link {
  padding: .4rem .8rem;
  color: var(--muted);
  font-weight: 600;
  font-size: .85rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.sub-tab-link:hover { color: var(--green-dark); text-decoration: none; }
.sub-tab-link.active { color: var(--green-dark); border-bottom-color: var(--green); }

/* Companies tab: Add/Clone/Delete side by side instead of stacked. */
.action-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 1.5rem; }
.action-row > .card { flex: 1; min-width: 300px; margin-top: 0; margin-bottom: 0; }

/* Tables get wrapped in this at runtime (see app.js) so wide report/ticket
   tables scroll horizontally on a phone instead of forcing the whole page
   to zoom out or squeezing every column unreadably thin. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: .8rem; }
.table-scroll table { margin-bottom: 0; }
@media print {
  /* Printed output should show the full table, not a scroll-clipped view. */
  .table-scroll { overflow: visible; }
}

/* Reusable stand-in for the one-off `style="display:flex; gap:.4rem"` forms
   scattered through the admin panel -- always wraps instead of overflowing
   on narrow screens. */
.inline-form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 1rem 1rem; }

h1 { font-size: 1.5rem; margin-top: 0; }
h2 { font-size: 1.15rem; color: var(--green-dark); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1.2rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .9rem;
  text-align: center;
}
.stat .num { font-size: 1.6rem; font-weight: 700; color: var(--green); }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; }

table { border-collapse: collapse; width: 100%; background: var(--card); }
table th, table td {
  border: 1px solid var(--border);
  padding: .4rem .6rem;
  font-size: .9rem;
  text-align: left;
}
table th { background: #eef2ea; color: var(--green-dark); }
table tr:hover td { background: #fbfdf9; }

.toolbar { display: flex; gap: .6rem; align-items: center; margin-bottom: .8rem; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 6px; }
.toolbar input.wide-search { min-width: 280px; }

.btn {
  display: inline-block;
  background: var(--green);
  color: white;
  padding: .45rem .9rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: .9rem;
}
.btn:hover { background: var(--green-dark); text-decoration: none; }
.btn.secondary { background: #7a8271; }
.btn.danger { background: #b3392f; }
.btn.danger:hover { background: #8f281f; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.bulk-bar { display: flex; align-items: center; gap: .8rem; margin: .6rem 0; }
td.check-col, th.check-col { width: 2rem; text-align: center; }

form.entry-form { max-width: 640px; }
form.entry-form label { display: block; margin-top: .7rem; font-weight: 600; font-size: .85rem; color: var(--muted); }
form.entry-form input, form.entry-form select {
  width: 100%; padding: .5rem .6rem; margin-top: .25rem;
  border: 1px solid var(--border); border-radius: 6px; font-size: .95rem;
}
form.entry-form .row { display: flex; gap: 1rem; }
form.entry-form .row > div { flex: 1; }
form.entry-form .actions { margin-top: 1.2rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; margin-top: .9rem; }
.checkbox-row input { width: auto; }

/* Lightweight custom autocomplete for the ticket form's License Plate /
   Number fields -- native <datalist> doesn't render any suggestion list
   at all on iOS Safari, so tapping a truck from the list never worked on
   mobile. This plain positioned list works the same on desktop and touch
   devices. */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}
.autocomplete-list.open { display: block; }
.autocomplete-item { padding: .55rem .7rem; cursor: pointer; font-size: .9rem; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--bg); }

.flash-wrap { margin-bottom: 1rem; }
.flash { padding: .6rem .9rem; border-radius: 6px; margin-bottom: .5rem; font-size: .9rem; }
.flash-success { background: #e3f3e1; color: #276b21; border: 1px solid #b9dfb4; }
.flash-error { background: #fbe4e1; color: #9c2b1f; border: 1px solid #f2b6ac; }

.report-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 1rem; }
.report-links a.card { display: block; }
.report-links a.card:hover { border-color: var(--green); text-decoration: none; }

.pill { display: inline-block; background: #eef2ea; border-radius: 999px; padding: .1rem .6rem; font-size: .78rem; color: var(--green-dark); }

/* Landing / company-login / admin-login pages */
.landing-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 88% 78%, #f4c860 0%, #e0a83e 28%, rgba(224,168,62,0) 62%),
    linear-gradient(155deg, var(--green) 0%, var(--green-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}
.landing-box {
  background: white;
  border-radius: 12px;
  padding: 2.5rem 2.5rem 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.landing-box h1 {
  margin: 0 0 .4rem;
  line-height: 1;
}
.landing-box .brand-mark {
  display: inline-block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.75rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--green-dark);
  line-height: 1;
}
.landing-box .brand-mark::after {
  content: "";
  display: block;
  height: 3px;
  width: 56%;
  margin: .35rem auto 0;
  background: linear-gradient(90deg, var(--green), #e0a83e);
  border-radius: 2px;
}
.landing-box .brand-sub {
  display: block;
  margin-top: .55rem;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}
.landing-box .tagline {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 1.8rem;
}
.landing-box select,
.landing-box input[type="password"],
.landing-box input[type="email"],
.landing-box input[type="text"] {
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 1rem;
}
.landing-box .btn { width: 100%; padding: .6rem; font-size: 1rem; }
.landing-box .admin-link { display: block; margin-top: 1.4rem; font-size: .85rem; color: var(--muted); }
.landing-box .company-name { color: var(--green-dark); font-weight: 700; }
.landing-box .back-link { display: block; margin-top: 1rem; font-size: .85rem; }
.landing-box .divider {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: .8rem;
  margin: 1.2rem 0;
}
.landing-box .divider::before,
.landing-box .divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.landing-box .divider span { padding: 0 .75rem; }

/* Small-screen layout: collapsible nav, stacked form rows, roomier touch
   targets, and inputs kept at >=16px so iOS Safari doesn't auto-zoom on
   focus. */
@media (max-width: 780px) {
  .nav-toggle { display: inline-block; }
  .topbar-right {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: .8rem;
    margin-top: .6rem;
  }
  body.nav-open .topbar-right { display: flex; }
  .topbar nav { display: flex; flex-direction: column; gap: .5rem; }
  .topbar nav a { margin-left: 0; }
  .company-switch {
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.3);
    padding-left: 0;
    padding-top: .6rem;
    flex-wrap: wrap;
  }

  .container { padding: .8rem; }

  form.entry-form .row { flex-direction: column; gap: 0; }

  .toolbar input.wide-search { min-width: 0; width: 100%; }

  .btn { padding: .6rem 1rem; }

  .landing-box { padding: 1.8rem 1.5rem 1.5rem; }
}

form.entry-form input, form.entry-form select,
.toolbar input, .toolbar select,
.inline-form input, .inline-form select {
  font-size: 1rem;
}

/* Lot identification banner at the top of the By Lot report (Tickets by
   Field) -- shows on screen too, but its main job is to make a printed
   page self-identifying (lot #, field, variety, grower) without needing
   the filter bar above it, which is hidden when printing. */
.lot-print-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin: .5rem 0 1rem;
  padding: .6rem .9rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px;
  background: var(--panel, #f7f7f5);
  font-size: .95rem;
}

/* "Print just this one table" support (Truck Settlement's Tickets / By
   Truck / Truck Pay sections, and any future page that wants it): mark the
   printable blocks with class="print-section" and a unique id, then call
   printSection(id) or printSelectedTickets() from base.html's shared JS. */
@media print {
  body.printing .topbar,
  body.printing footer,
  body.printing .flash-wrap {
    display: none !important;
  }
  body.printing main > *:not(.print-section) {
    display: none !important;
  }
  body.printing .print-section:not(.print-target) {
    display: none !important;
  }
  body.printing .print-section .toolbar,
  body.printing .print-section form.toolbar,
  body.printing .print-section .bulk-bar,
  body.printing .print-section .check-col {
    display: none !important;
  }
  body.printing .print-hide-row {
    display: none !important;
  }

  /* Wide report tables (10+ columns, like Truck Settlement or the new By
     Lot tables) were overflowing a portrait page's printable width -- the
     .card's own border/rounded corners/padding ate into the @page margin
     on top of the table itself needing more room, so browsers either
     clipped the right-hand columns or auto-shrunk the whole page unevenly,
     which looked like "the margins are off." Stripping the card chrome and
     tightening the table's own font/padding just for the printed target
     gives every column room to fit inside the page margin at 100% scale. */
  .print-section.print-target {
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }
  .print-section.print-target table {
    font-size: 8pt;
  }
  .print-section.print-target table th,
  .print-section.print-target table td {
    padding: .2rem .35rem;
  }
}

/* Printed date (top-left) + company name (top-center), and the printed-on
   date again at the very bottom -- see the .print-header/.print-footer
   divs in base.html. Hidden on screen. Deliberately placed in the normal
   document flow (not
   position: fixed) rather than relying on the browser reserving a @page
   margin box for them: that depended on both the browser and the print
   driver actually honoring the CSS @page margin, and several
   printers/browsers in the field were instead using their own default
   print margins, so the fixed-position header ended up overlapping the
   first rows of the table instead of sitting above it. In-flow means it
   only appears once -- above the table on the first printed page, and
   below it at the very end -- rather than repeating on every physical
   page, but it can never overlap content. The page number still comes
   from the browser's native @page margin-box counter where supported
   (Chrome/Edge 131+, Safari 18.2+); older/other browsers just won't show
   the "Page X of Y" line, which fails safely with no layout impact. */
.print-header, .print-footer { display: none; }
@media print {
  @page {
    margin: 0.5in;
    @bottom-right {
      content: "Page " counter(page) " of " counter(pages);
      font-size: 9pt;
      color: #444;
    }
  }
  .print-header {
    display: flex;
    align-items: baseline;
    margin-bottom: 0.2in;
  }
  .print-header-date {
    flex: 1;
    text-align: left;
    font-size: 9pt;
    font-weight: 400;
    color: var(--muted);
  }
  .print-header-title {
    flex: 1;
    text-align: center;
    font-size: 15pt;
    font-weight: 700;
    color: var(--green-dark);
  }
  .print-header-spacer {
    flex: 1;
  }
  .print-footer {
    display: block;
    margin-top: 0.2in;
    font-size: 9pt;
    color: var(--muted);
  }
}
