:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #d8dee9;
  --text: #1f2937;
  --topbar-h: 80px;
  --muted: #6b7280;
  --accent: #5a5f5c;
  --accent-soft: #e4e5e3;
  --accent-dark: #3a3d3b;
  --accent-soft-2: #eeefee;
  --brand: #325a3e;
  --red: #a83232;
}
* { box-sizing: border-box; }
html { overflow-y: scroll; scrollbar-gutter: stable; }
body { margin: 0; font-family: Arial, sans-serif; font-size: 16px; font-weight: 600; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 18px 28px; background: #111827; color: white; position: sticky; top: 0; z-index: 100; }
.topbar h1 { margin: 0; font-size: 24px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0; }
.topbar p { margin: 4px 0 0; color: #cbd5e1; }
.topbar nav { display: flex; gap: 10px; }
.topbar nav a { color: white; padding: 10px 14px; border-radius: 10px; background: rgba(255,255,255,0.08); }
.topbar nav a.active { background: var(--brand); }
.page { padding: 24px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-head h2 { margin: 0; }
.section-head p { margin: 6px 0 0; color: var(--muted); }
.slicers-container { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 8px 18px rgba(0,0,0,0.04); position: sticky; top: calc(var(--topbar-h) + 24px); height: calc(100vh - var(--topbar-h) - 48px); overflow: hidden; display: flex; flex-direction: column; flex-shrink: 0; width: 420px; order: 2; margin-left: 4px; }
.slicers-container form { margin: 0; flex: 1; overflow-y: auto; min-height: 0; }
.slicer-actions { display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.clear { white-space: nowrap; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: white; font-size: 14px; color: var(--text); }
.filter-config-btn { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 14px; color: var(--muted); font-weight: normal; }
.filter-config-btn:hover { background: var(--bg); color: var(--text); filter: none; }
.filter-config { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; display: none; }
.filter-config.open { display: block; }
.filter-config-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.filter-config-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; cursor: pointer; }
.date-filter-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.date-filter-label { font-size: 13px; color: var(--muted); width: 28px; flex-shrink: 0; }
.date-filter-input { flex: 1; min-width: 0; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; width: 100%; }
.slicers-body { display: flex !important; flex-direction: row !important; gap: 16px !important; }
.slicer-col { flex: 1 !important; min-width: 0 !important; }
.slicer-col.dragging { opacity: 0.35; }
.slicer-col.drag-over { outline: 2px dashed var(--accent); border-radius: 8px; }
.slicer-title { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--card); z-index: 1; padding-bottom: 4px; }
.drag-handle { cursor: grab; color: var(--muted); opacity: 0.4; user-select: none; display: inline-flex; align-items: center; vertical-align: middle; }
.drag-handle:hover { opacity: 0.9; }
.slicer-grid { display: flex; flex-direction: column; gap: 4px; }
.slicer { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 7px 11px; cursor: pointer; background: white; font-size: 15px; width: 100%; overflow: hidden; }
.slicer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.slicer.selected { background: var(--accent-soft); border-color: var(--accent); border-left: 3px solid var(--accent); color: var(--accent-dark); font-weight: 700; }
.slicer input { display: none; }
.content-with-slicer { display: flex; flex-direction: row; align-items: flex-start; gap: 0; }
.content-with-slicer .table-wrap { flex: 1; min-width: 0; margin-right: 4px; max-height: calc(100vh - var(--topbar-h) - 48px); overflow-y: auto; scrollbar-gutter: stable; }
.slicer-resize-handle { order: 1; width: 8px; flex-shrink: 0; cursor: col-resize; position: sticky; top: calc(var(--topbar-h) + 24px); height: calc(100vh - var(--topbar-h) - 48px); border-radius: 4px; transition: background 0.15s; }
.slicer-resize-handle:hover, .slicer-resize-handle.active { background: rgba(90, 95, 92, 0.18); }
.table-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 18px rgba(0,0,0,0.04); }
.data-table { border-collapse: collapse; width: 100%; min-width: 700px; font-size: 16px; }
.data-table thead { position: sticky; top: 0; z-index: 4; }
.data-table th { background: var(--accent-soft-2); color: #111827; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.sort-arrow { display: inline-block; width: 1em; text-align: center; visibility: hidden; }
.sort-arrow.active { visibility: visible; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr.clickable-row { cursor: pointer; }
.data-table td.farm a { color: inherit; }
.inline-input { width: 112px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.inline-input.number, .number { text-align: right; }
.data-table td.number { text-align: right; }
.data-table th.number { text-align: right; }
.summary-row th { background: var(--accent-soft-2); font-size: 13px; color: var(--muted); padding: 14px 10px; border-bottom: none; }
.summary-row .button, .summary-row button { padding: 10px 22px; font-size: 15px; }
.summary-stat { color: #111827 !important; text-align: center; display: block; line-height: 1.2; }
.summary-stat-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: block; }
#summary-tons { font-size: 30px; font-weight: 800; color: var(--accent-dark); display: block; }
.calculated { font-weight: 700; background: #f9fafb; }
.button, button { display: inline-block; background: var(--accent); color: white; border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 700; }
.button:hover, button:hover { text-decoration: none; filter: brightness(0.95); }
.button.small { padding: 6px 10px; font-size: 14px; }
.edit-form { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 14px; max-width: 1100px; }
.edit-form label { display: grid; gap: 6px; font-weight: 700; }
.edit-form input, .edit-form select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; font-family: inherit; background: var(--card); color: var(--text); }
.edit-form .wide { grid-column: span 2; }
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; margin-top: 8px; }
@media (max-width: 900px) {
  .topbar, .section-head { align-items: flex-start; flex-direction: column; }
  .slicer-col { width: 50%; }
  .edit-form { grid-template-columns: 1fr; }
  .edit-form .wide { grid-column: auto; }
  .content-with-slicer { flex-direction: column; }
  .content-with-slicer .table-wrap { margin-right: 0; max-height: none; }
  .slicer-resize-handle { display: none; }
  .content-with-slicer .slicers-container { order: 0; width: auto !important; margin-left: 0; position: static; height: auto; }
}
.danger { background: #a83232; }
button.small { padding: 6px 10px; font-size: 13px; }
.error-box { max-width: 1100px; margin: 0 0 14px; padding: 12px 14px; border: 1px solid #fecaca; background: #fef2f2; color: #991b1b; border-radius: 10px; font-weight: 700; }
.data-table form { margin: 0; }

.ctx-menu { display: none; position: fixed; z-index: 500; background: white; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); padding: 4px; min-width: 140px; }
.ctx-menu.open { display: block; }
.ctx-menu-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--text); }
.ctx-menu-item:hover { background: var(--bg); filter: none; }
.ctx-menu-item.danger-item { color: #991b1b; }
.ctx-menu-item.danger-item:hover { background: #fef2f2; }

.danger-row { background-color: #a83232; }
.sel-cell { outline: 2px solid var(--accent); outline-offset: -2px; background-color: rgba(90, 95, 92, 0.12) !important; }
.selection-status { position: fixed; bottom: 0; right: 0; background: #1e293b; color: #e2e8f0; font-size: 13px; font-weight: 600; padding: 6px 20px; letter-spacing: 0.04em; z-index: 200; border-top-left-radius: 8px; }

.save-error-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #991b1b; color: white; padding: 12px 20px; border-radius: 10px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 999; }
.save-error-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

.nav-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 1000; opacity: 0; transition: width 0.2s ease, opacity 0.15s; }
.nav-progress.active { opacity: 1; width: 70%; transition: width 4s cubic-bezier(0.1, 0.5, 0.1, 1), opacity 0.15s; }
.nav-progress.done { width: 100%; transition: width 0.2s ease; }


/* Inline editable fields: blend into table until focused */
.inline-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid transparent;
    background: transparent;
    padding: 4px 6px;
    font: inherit;
    color: inherit;
    border-radius: 6px;
    outline: none;
}

.inline-input:hover {
    border-color: #d0d7de;
    background: rgba(255, 255, 255, 0.45);
}

.inline-input.input-error { border-color: #dc2626 !important; background: #fef2f2 !important; }

/* Farm name search box: always visible, distinct from blend-in inline inputs */
.farm-search-input {
    border: 1px solid var(--line) !important;
    background: #ffffff !important;
    padding: 8px 12px !important;
    border-radius: 8px !important;
    font-size: 15px;
}
.farm-search-input:hover {
    border-color: #9ca3af !important;
}
.farm-search-input:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(90, 95, 92, 0.18);
}
.inline-input:focus {
    border-color: #6b7280;
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.18);
}

/* Keep number fields aligned like table values */
.inline-input.number {
    text-align: right;
}

/* Remove spinner visual noise on numeric inline fields */
.inline-input[type="number"]::-webkit-outer-spin-button,
.inline-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.inline-input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* API-locked fields: read-only, same appearance as regular cell text */
.api-locked {
    display: block;
    padding: 4px 6px;
}

/* Critical rows: color every cell, including calculated cells and inline inputs */
.danger-row td {
    background-color: #a83232 !important;
    color: white !important;
}

.danger-row:hover td {
    background-color: #a83232 !important;
    color: white !important;
}

.danger-row .inline-input {
    background: transparent;
}

.danger-row .inline-input:hover {
    background: rgba(255, 255, 255, 0.35);
}

.danger-row .inline-input:focus {
    background: #ffffff;
    color: #111827;
}


/* Zebra striping */
.data-table tbody tr.row-even td {
    background-color: #e9eae8;
}

.data-table tbody tr.row-odd td {
    background-color: #ffffff;
}

.data-table tbody tr:not(.danger-row):hover td {
    background-color: #f1f1f0;
}

/* Days Left bar: red at 2.0 and under, yellow through 7-ish, green by 10+ */
.days-left-cell {
    position: relative;
    min-width: 80px;
    padding: 5px 8px !important;
}

.days-bar {
    position: relative;
    overflow: hidden;
    min-width: 60px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid rgba(31, 41, 55, 0.12);
    background: white;
}

.days-bar::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--days-pct);
    border-radius: 999px;
}

.days-bar.days-red::before {
    background: #fca5a5;
}

.days-bar.days-yellow::before {
    background: linear-gradient(90deg, #fdba74 0%, #fde68a 70%);
}

.api-type-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}

.api-type-badge:empty {
    display: none;
}

.api-type-farmlink {
    background: var(--accent-soft);
    color: var(--accent);
}

.api-type-binsentry {
    background: #ede9fe;
    color: #6d28d9;
}

.days-bar.days-green::before {
    background: linear-gradient(90deg, #fde68a 0%, #86efac 100%);
}

.days-bar .days-left {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    text-align: right;
    padding: 3px 9px;
    font-weight: 800;
    color: #111827;
}


.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg) 0%, var(--accent-soft) 100%);
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.04);
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.auth-logo {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  margin: 0 auto 1rem;
}

.auth-card h1 {
  font-size: 1.1rem;
  color: var(--muted, #6b7280);
  margin: 0 0 0.25rem;
}

.auth-card h2 {
  font-size: 1.4rem;
  margin: 0 0 1.25rem;
}

.auth-card p {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted, #6b7280);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form label { display: grid; gap: 6px; font-weight: 700; }
.auth-form input:not([type=checkbox]) { padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; width: 100%; box-sizing: border-box; }
.auth-form .checkbox-row { display: flex; flex-direction: row; align-items: center; gap: 10px; cursor: pointer; }
.auth-form .form-actions { margin-top: 4px; }

.button.danger, button.danger { background: #b91c1c; }
.button.danger:hover, button.danger:hover { filter: brightness(0.9); }

.settings-section { max-width: 560px; margin-bottom: 2.5rem; }
.settings-section h3 { margin: 0 0 .25rem; }

.api-config-grid { display: flex; flex-direction: column; gap: .75rem; }
.api-config-field { display: flex; flex-direction: column; gap: .35rem; }
.field-label { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #6b7280); }
.api-config-field input { padding: 8px 10px; border: 1px solid var(--line, #d0d7de); border-radius: 7px; font: inherit; font-size: .95rem; background: #fff; transition: border-color .15s, box-shadow .15s; }
.api-config-field input:focus { outline: none; border-color: #6b7280; box-shadow: 0 0 0 3px rgba(107,114,128,.12); }

.col-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cols-panel { position: absolute; top: calc(100% + 6px); right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.1); z-index: 200; }
.col-item { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; cursor: default; user-select: none; }
.col-item.dragging { opacity: .4; }
.col-item.drag-over { border-color: var(--accent); }
.drag-handle { font-size: 1.2rem; color: var(--muted, #9ca3af); cursor: grab; line-height: 1; }
.drag-handle:active { cursor: grabbing; }
.col-label { font-weight: 600; }

.phase-input { width: 90px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 28px;
  min-width: 360px;
  max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  font-family: inherit;
  color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,0.4); }
.dialog-title { margin: 0 0 14px; font-size: 1.1rem; }
.modal-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin: 4px 0 16px;
}
.modal-form label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 700; }
.modal-form input, .modal-form select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; font-weight: 600; background: var(--card); color: var(--text); }
.modal-form .wide { grid-column: 1 / -1; }
.modal-actions { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 4px; }
button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.btn-working { opacity: 0.55; cursor: default; }
.btn-done { background: var(--brand) !important; color: #fff !important; border-color: var(--brand) !important; transition: background .15s, color .15s, border-color .15s; }
.api-connected { display: inline-flex; align-items: center; margin-left: 5px; color: inherit; opacity: 0.6; vertical-align: middle; text-decoration: none; }
.api-connected:hover { opacity: 1; }

#live-feeds-wrap { max-width: 480px; }
#live-table { min-width: 0; }
#live-table th:last-child, #live-table td:last-child { width: 90px; text-align: center; }
#live-table tbody tr { cursor: pointer; }
#live-table tbody tr:nth-child(odd) td { background: #ffffff; }
#live-table tbody tr:nth-child(even) td { background: #e9eae8; }
#live-table tbody tr:hover td { background: var(--bg); }

.kv-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 4px 0 16px;
  max-height: 60vh;
  overflow-y: auto;
}
.kv-grid dt { font-weight: 700; color: var(--muted); white-space: nowrap; }
.kv-grid dd { margin: 0; }
.api-connected svg { width: 14px; height: 14px; }
.api-stale { opacity: 1; color: #d97706; }
.api-stale svg { stroke: #d97706; fill: #fef3c7; }
.loadout-alert { display: inline-flex; align-items: center; justify-content: center; margin-left: 6px; width: 22px; height: 22px; border-radius: 50%; background: #fef3c7; color: #d97706; vertical-align: middle; }
.loadout-alert svg { width: 14px; height: 14px; }
.loadout-overdue { background: #fee2e2; color: #a83232; }
.has-tooltip { position: relative; }
.has-tooltip::after { content: attr(data-tooltip); position: absolute; bottom: 125%; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; font-size: 12px; font-weight: 400; white-space: nowrap; padding: 4px 8px; border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity 0.1s; z-index: 10; }
.has-tooltip::before { content: ''; position: absolute; bottom: 125%; left: 50%; transform: translateX(-50%) translateY(100%); border: 5px solid transparent; border-top-color: #1f2937; opacity: 0; pointer-events: none; transition: opacity 0.1s; z-index: 10; }
.has-tooltip:hover::after, .has-tooltip:hover::before { opacity: 1; }
