/* Small Supplier Orders — styled to match the Qt "Fusion" desktop look. */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans", Arial, sans-serif;
  font-size: 13px;
  color: #202020;
  background: #f0f0f0;
}

/* ── title bar ─────────────────────────────────────────────── */
.titlebar {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(#fafafa, #e6e6e6);
  border-bottom: 1px solid #b6b6b6;
  padding: 6px 12px;
}
.titlebar .title { font-weight: 600; }
.titlebar .spacer, .spacer { flex: 1; }
.titlebar .run-info { color: #555; font-size: 12px; }
.titlebar .user { color: #444; font-size: 12px; }
.titlebar a { color: #0a5dbb; text-decoration: none; }
.titlebar a:hover { text-decoration: underline; }

/* ── stock-on-hand warning bar ─────────────────────────────── */
.warnbar {
  background: linear-gradient(#fff3cd, #ffe69c);
  border-bottom: 2px solid #d9a400;
  color: #6b4e00;
  font-size: 15px; font-weight: 600;
  text-align: center;
  padding: 9px 14px;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  flex-wrap: wrap;
}
.warnbar .btn.refresh-soh {
  flex: 0 0 auto;
  height: 34px; padding: 0 18px;
  font-size: 14px; font-weight: 700;
  background: linear-gradient(#4ea3f2, #2f7ddb); color: #fff;
  border-color: #2f7ddb;
}
.warnbar .btn.refresh-soh:hover:not(:disabled) {
  background: linear-gradient(#5fadf5, #3a87e0); border-color: #2f7ddb;
}

/* ── loading ───────────────────────────────────────────────── */
.loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; height: calc(100vh - 40px);
}
.loading-label { font-size: 18px; font-weight: bold; }
.progress {
  width: 400px; height: 22px; background: #fff;
  border: 1px solid #a0a0a0; border-radius: 3px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(#4ea3f2, #2f7ddb);
  transition: width .2s ease;
}

/* ── content layout ────────────────────────────────────────── */
.content { padding: 10px 12px 14px; }
.frame {
  border: 1px solid #b6b6b6; border-radius: 3px;
  background: #f7f7f7; padding: 8px 10px; margin-bottom: 10px;
}
.controls { display: flex; align-items: flex-end; gap: 18px; }
.ctl { display: flex; flex-direction: column; gap: 4px; }
.ctl label { font-size: 12px; color: #333; min-height: 15px; }
.combo, .spin {
  height: 26px; padding: 2px 6px;
  border: 1px solid #a0a0a0; border-radius: 3px; background: #fff;
  font-size: 13px;
}
.combo { min-width: 320px; }
.spin { width: 70px; }
#min-order-value.sunken, .sunken {
  min-width: 110px; height: 26px; line-height: 22px; text-align: center;
  border: 1px solid #9a9a9a; border-radius: 3px;
  background: #ececec; box-shadow: inset 1px 1px 2px rgba(0,0,0,.12);
}

/* ── buttons (Fusion-like) ─────────────────────────────────── */
.btn {
  height: 28px; padding: 0 14px;
  border: 1px solid #adadad; border-radius: 3px;
  background: linear-gradient(#fdfdfd, #e8e8e8);
  font-size: 13px; cursor: pointer; color: #1d1d1d;
}
.btn:hover:not(:disabled) { background: linear-gradient(#ffffff, #ededed); border-color: #8aaedb; }
.btn:active:not(:disabled) { background: linear-gradient(#e4e4e4, #efefef); }
.btn:disabled { color: #9a9a9a; background: #f0f0f0; cursor: default; }
.btn.toggle.on { background: linear-gradient(#cfe3ff, #aecdf6); border-color: #5a8fd6; }
.btn.primary { background: linear-gradient(#4ea3f2, #2f7ddb); color: #fff; border-color: #2f7ddb; }
.actions { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; }
.col-chooser { position: relative; }
.col-panel {
  position: absolute; right: 0; top: 100%; z-index: 50; margin-top: 4px;
  background: #fff; border: 1px solid #9aa7b4; border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18); padding: 8px; min-width: 200px;
  max-height: 340px; overflow: auto;
}
.col-opt { display: flex; align-items: center; gap: 7px; padding: 3px 5px;
  font-size: 13px; white-space: nowrap; border-radius: 4px; cursor: pointer; }
.col-opt:hover { background: #eef4fb; }
.col-opt input { margin: 0; }
.order-label { margin: 4px 0; }

/* ── order table ───────────────────────────────────────────── */
.table-wrap { border: 1px solid #b6b6b6; background: #fff; overflow: auto; max-height: 38vh; }
.order-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.order-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: linear-gradient(#f6f6f6, #e9e9e9);
  border: 1px solid #d2d2d2; border-top: none;
  padding: 5px 8px; text-align: left; font-weight: 600; cursor: pointer; user-select: none;
  white-space: nowrap;
}
.order-table thead th.sorted-asc::after { content: " ▲"; font-size: 10px; color: #666; }
.order-table thead th.sorted-desc::after { content: " ▼"; font-size: 10px; color: #666; }
.order-table tbody td {
  border: 1px solid #e4e4e4; padding: 4px 8px; white-space: nowrap;
}
.order-table tbody tr:nth-child(even) { background: #f6f6f6; }   /* alternating rows */
.order-table tbody tr.selected { background: #cde3ff !important; }
.order-table td.desc-col, .order-table th.desc-col { white-space: normal; width: 40%; }
.order-table td.num { text-align: right; }
.order-table td.editable { background: #fffef0; cursor: text; }
.order-table td.editable:focus { outline: 2px solid #4ea3f2; background: #fff; }

/* ── totals ────────────────────────────────────────────────── */
.totals { display: flex; align-items: center; gap: 14px; box-shadow: inset 1px 1px 2px rgba(0,0,0,.10); }
.totals-label { font-weight: 600; }
.total-box {
  min-width: 90px; text-align: right; padding: 4px 10px;
  font-size: 15px; font-weight: bold;
  border: 1px solid #c2c2c2; border-radius: 3px; background: #fff;
}
.totals-gap { width: 60px; }

/* ── bottom split: usage table + chart ─────────────────────── */
.bottom { display: flex; gap: 10px; margin-top: 12px; align-items: stretch; }
.bottom-pane { flex: 1 1 50%; min-width: 0; border: 1px solid #b6b6b6; background: #fff; }
.chart-pane { display: flex; align-items: center; justify-content: center; padding: 6px; }
/* Bound the chart so it can't overgrow its pane and overlap the totals row above. */
.chart-pane img { max-width: 100%; max-height: 34vh; height: auto; width: auto; object-fit: contain; }

.usage-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.usage-table th {
  background: linear-gradient(#f6f6f6, #e9e9e9);
  border: 1px solid #d2d2d2; padding: 4px 2px; text-align: center; font-weight: 600;
}
.usage-table td {
  border: 1px solid #e0e0e0; padding: 4px 2px; text-align: center; min-width: 30px;
}
.usage-table td.year { background: #f0f0f0; font-weight: 600; }
/* historical colours by row (oldest→current): red, yellow, green; text #166534 */
.usage-table td.hist0 { background: rgb(254,215,215); color: #166534; }
.usage-table td.hist1 { background: rgb(254,240,190); color: #166534; }
.usage-table td.hist2 { background: rgb(210,250,215); color: #166534; }
/* forecast: blue */
.usage-table td.forecast { background: rgb(210,230,255); color: #1e40af; }

/* ── modal (Add Product) ───────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  background: #f0f0f0; border: 1px solid #888; border-radius: 4px;
  width: 680px; max-width: 92vw; max-height: 90vh; overflow: auto; padding: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.modal-title { font-weight: 600; font-size: 15px; margin-bottom: 12px; }
.search-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.search-row .combo { flex: 1; min-width: 0; }
.results-wrap { border: 1px solid #b6b6b6; background: #fff; max-height: 260px; overflow: auto; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.results-table th { position: sticky; top: 0; background: linear-gradient(#f6f6f6,#e9e9e9);
  border: 1px solid #d2d2d2; padding: 5px 8px; text-align: left; }
.results-table td { border: 1px solid #e4e4e4; padding: 4px 8px; }
.results-table tr.selected { background: #cde3ff; }
.results-table tr { cursor: pointer; }
.custom-group {
  margin: 12px 0; border: 1px solid #b6b6b6; border-radius: 3px; padding: 10px 12px;
}
.custom-group legend { padding: 0 6px; font-weight: 600; }
.form-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.form-row label { width: 110px; text-align: right; color: #333; }
.form-row .combo, .form-row .spin { flex: 1; min-width: 0; }
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }

/* ── login ─────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: #f7f7f7; border: 1px solid #b6b6b6; border-radius: 6px;
  padding: 28px 30px; width: 320px; box-shadow: 0 6px 24px rgba(0,0,0,.15);
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { font-size: 18px; margin: 0; }
.login-card .sub { margin: 0 0 6px; color: #666; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #333; }
.login-card input { height: 30px; padding: 2px 8px; border: 1px solid #a0a0a0; border-radius: 3px; }
.login-card .btn { height: 32px; margin-top: 6px; }
.login-error { background: #fde2e2; border: 1px solid #f1a9a9; color: #a12020;
  padding: 8px 10px; border-radius: 3px; font-size: 12px; }

/* ── toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 10px 16px; border-radius: 4px;
  font-size: 13px; z-index: 80; box-shadow: 0 4px 14px rgba(0,0,0,.3);
}

/* ── copilot ───────────────────────────────────────────────── */
.copilot-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  background: #2d6cdf; color: #fff; border: none; border-radius: 22px;
  padding: 10px 16px; font-size: 14px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.copilot-fab:hover { background: #2559bd; }
.copilot-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 95;
  width: 380px; max-width: calc(100vw - 40px); height: 560px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; background: #fff;
  border: 1px solid #b8b8b8; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.copilot-head {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: #2d6cdf; color: #fff; border-radius: 8px 8px 0 0;
}
.copilot-title { font-weight: 600; font-size: 14px; }
.copilot-iconbtn {
  background: transparent; border: none; color: #fff; font-size: 15px;
  cursor: pointer; padding: 2px 6px; border-radius: 3px;
}
.copilot-iconbtn:hover { background: rgba(255,255,255,.2); }
.copilot-messages {
  flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column;
  gap: 8px; background: #f6f7f9; font-size: 13px; line-height: 1.4;
}
.copilot-msg { padding: 8px 11px; border-radius: 10px; max-width: 88%; white-space: pre-wrap; word-wrap: break-word; }
.copilot-msg.bot { background: #fff; border: 1px solid #e2e2e2; align-self: flex-start; }
.copilot-msg.user { background: #2d6cdf; color: #fff; align-self: flex-end; }
.copilot-msg.tools { background: transparent; color: #888; font-size: 11px; align-self: flex-start; padding: 0 4px; }
.copilot-msg.err { background: #fde2e2; border: 1px solid #f1a9a9; color: #a12020; align-self: flex-start; }
.copilot-msg .dots::after { content: "…"; animation: copilotdots 1.2s steps(4,end) infinite; }
@keyframes copilotdots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }
.copilot-input-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #e2e2e2; }
.copilot-input {
  flex: 1; resize: none; border: 1px solid #a0a0a0; border-radius: 4px;
  padding: 6px 8px; font: inherit; font-size: 13px; max-height: 120px;
}

/* ════════════════════════════════════════════════════════════════════════
   MODERN THEME REFRESH (2026-06-11) — staff-engagement restyle.
   Appended as overrides so every existing class/DOM stays intact; only the
   look changes. Palette: teal primary on a soft slate canvas, rounded cards,
   pill buttons, roomier type.
   ════════════════════════════════════════════════════════════════════════ */
:root {
  --brand:    #2563eb;   --brand-dk: #1d4ed8;   --brand-lt: #93c5fd;
  --accent:   #2563eb;   --accent-dk: #1d4ed8;
  --ink:      #0f172a;   --muted: #64748b;
  --canvas:   #eef2f7;   --card: #ffffff;
  --line:     #e2e8f0;   --line-dk: #cbd5e1;
  --good:     #16a34a;   --good-bg: #dcfce7;
  --warn:     #b45309;   --bad: #dc2626;
  --shadow:   0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
  --radius:   10px;
}
body {
  background:
    radial-gradient(1200px 500px at 100% -10%, #e0f2fe 0, transparent 60%),
    var(--canvas);
  color: var(--ink);
  font-size: 13.5px;
}

/* Header → branded bar */
.titlebar {
  background: linear-gradient(90deg, var(--brand-dk), var(--brand));
  border-bottom: none; color: #fff; padding: 11px 18px;
  box-shadow: var(--shadow);
}
.titlebar .title { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.titlebar .title::before { content: "💊 "; }
.titlebar .run-info, .titlebar .user { color: #d7faf3; }
.titlebar a { color: #fff; text-decoration: underline; text-underline-offset: 2px; }

/* Warning bar → cleaner amber notice */
.warnbar {
  background: #fef9c3; border-bottom: 1px solid #fde047;
  color: #854d0e; font-weight: 600; font-size: 14px; padding: 11px 16px;
}
.warnbar .btn.refresh-soh {
  height: 36px; border-radius: 999px; font-weight: 700; border: none;
  background: linear-gradient(var(--accent), var(--accent-dk)); color: #fff;
  box-shadow: var(--shadow);
}
.warnbar .btn.refresh-soh:hover:not(:disabled) { filter: brightness(1.06); }

/* Cards / frames */
.content { padding: 16px 18px 20px; max-width: 1500px; margin: 0 auto; }
.frame {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); padding: 14px 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.controls { gap: 22px; }
.ctl label { color: var(--muted); font-weight: 600; }
.combo, .spin, .login-card input {
  height: 34px; border: 1px solid var(--line-dk); border-radius: 8px;
  font-size: 13.5px; transition: border-color .12s, box-shadow .12s;
}
.combo:focus, .spin:focus, .login-card input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.sunken, #min-order-value.sunken {
  height: 34px; line-height: 30px; border-radius: 8px;
  border: 1px solid var(--line-dk); background: #f1f5f9; box-shadow: none;
  font-weight: 700; color: var(--brand-dk);
}

/* Buttons → pill style */
.btn {
  height: 34px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line-dk); background: #fff; color: var(--ink);
  font-size: 13.5px; font-weight: 600; transition: all .12s;
}
.btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand-dk); background: #eff6ff; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { color: #94a3b8; background: #f1f5f9; border-color: var(--line); }
.btn.toggle.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary, .btn-primary {
  background: linear-gradient(var(--brand), var(--brand-dk)); color: #fff;
  border: none; box-shadow: var(--shadow); font-weight: 700;
}
.btn.primary:hover:not(:disabled), .btn-primary:hover:not(:disabled) {
  filter: brightness(1.07); color: #fff;
  background: linear-gradient(var(--brand), var(--brand-dk)); border-color: transparent;
}
#order-now-btn { font-size: 14px; padding: 0 22px; }
.actions { gap: 10px; }

/* Order table */
.order-label { font-weight: 700; color: var(--muted); text-transform: uppercase;
  font-size: 11.5px; letter-spacing: .6px; }
.table-wrap, .bottom-pane, .results-wrap {
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 42vh;
}
.order-table thead th {
  background: #f1f5f9; border: none; border-bottom: 2px solid var(--line-dk);
  color: var(--muted); text-transform: uppercase; font-size: 11px;
  letter-spacing: .4px; padding: 9px 10px;
}
.order-table tbody td { border: none; border-bottom: 1px solid var(--line); padding: 7px 10px; }
.order-table tbody tr:nth-child(even) { background: #f8fafc; }
.order-table tbody tr:hover { background: #eff6ff; }
.order-table tbody tr.selected { background: #dbeafe !important; box-shadow: inset 3px 0 0 var(--brand); }
.order-table td.editable { background: #fffbeb; border-radius: 6px; }
.order-table td.editable:focus { outline: 2px solid var(--brand); }

/* Portal-data cells */
td.portal-cheaper { color: var(--good); font-weight: 700; background: var(--good-bg); }
td.portal-cheaper::after { content: " ▼"; font-size: 10px; }
.stock-yes { color: var(--good); font-weight: 700; }
.stock-no  { color: var(--bad);  font-weight: 700; }

/* Totals */
.totals { box-shadow: none; gap: 14px; }
.totals-label { color: var(--muted); text-transform: uppercase; font-size: 11.5px; letter-spacing: .6px; }
.total-box {
  border: 1px solid var(--line-dk); border-radius: 8px; background: #f8fafc;
  color: var(--brand-dk); font-size: 16px;
}

/* Loading + progress */
.progress { border-radius: 999px; border: none; background: #e2e8f0; height: 12px; }
.progress-bar { background: linear-gradient(90deg, var(--brand), var(--brand-lt)); }

/* Copilot + FAB → brand colours */
.copilot-fab { background: linear-gradient(var(--brand), var(--brand-dk)); border-radius: 999px; box-shadow: var(--shadow); }
.copilot-fab:hover { filter: brightness(1.07); }
.copilot-head { background: linear-gradient(90deg, var(--brand-dk), var(--brand)); border-radius: 8px 8px 0 0; }
.copilot-msg.user { background: var(--brand); }
.copilot-panel { border-radius: 12px; }

/* Login card */
.login-card { border-radius: var(--radius); box-shadow: var(--shadow); border-color: var(--line); }
.login-card h1 { color: var(--brand-dk); }

/* Modal */
.modal-card { border-radius: 12px; border-color: var(--line-dk); }
.toast { border-radius: 999px; background: var(--ink); }

/* ── Drag-to-reorder column headers ─────────────────────────────── */
.order-table thead th { cursor: pointer; user-select: none; }
.order-table thead th[draggable="true"]:hover { background: #e2e8f0; }
.order-table thead th.th-dragging { opacity: .45; }
.order-table thead th.th-drop-before { box-shadow: inset 3px 0 0 var(--accent); }
.order-table thead th.th-drop-after  { box-shadow: inset -3px 0 0 var(--accent); }

/* ── Make the order table's scrollability obvious ───────────────── */
/* Always-visible, styled scrollbar (overlay scrollbars otherwise hide it). */
.table-wrap { scrollbar-width: thin; scrollbar-color: var(--line-dk) transparent; scroll-behavior: smooth; }
.table-wrap::-webkit-scrollbar { width: 12px; height: 12px; }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--line-dk); border-radius: 8px; border: 3px solid #fff;
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted); }
/* Bottom fade cue: shown only while there's more to scroll (.has-more toggled in JS). */
.table-scroll { position: relative; }
.table-scroll::after {
  content: "↓ scroll down in this window for more"; position: absolute; left: 0; right: 12px; bottom: 0; height: 30px;
  display: flex; align-items: flex-end; justify-content: center;
  font-size: 10.5px; font-weight: 700; letter-spacing: .4px; color: var(--accent);
  padding-bottom: 3px; text-transform: uppercase;
  background: linear-gradient(rgba(255,255,255,0), rgba(255,255,255,.95) 70%);
  border-radius: 0 0 var(--radius) var(--radius);
  pointer-events: none; opacity: 0; transition: opacity .15s;
}
.table-scroll.has-more::after { opacity: 1; }

/* Busy buttons (Generate / Show All while the server works) */
@keyframes btn-busy-pulse { 0%,100% { opacity: .65; } 50% { opacity: 1; } }
.btn.busy { animation: btn-busy-pulse 1s ease-in-out infinite; cursor: progress; }

/* Negative SOH (oversell / data error) — flagged red; doesn't inflate the order qty */
td.soh-neg { color: var(--bad); font-weight: 700; background: #fee2e2; }

/* Order Now: a line that couldn't be auto-added to the marketplace cart — amber
   row with a ⚠ marker so staff add it manually. */
.order-table tbody tr.cart-missing { background: #fffbeb; box-shadow: inset 3px 0 0 var(--warn); }
.order-table tbody tr.cart-missing.selected { background: #fef3c7 !important; }
.order-table tbody tr.cart-missing td:first-child::before { content: "⚠ "; color: var(--warn); }
.cart-flag-note {
  margin: 6px 0; padding: 8px 12px; border-radius: 6px;
  background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; font-size: 13px;
}
.cart-flag-note ul.flag-reasons { margin: 4px 0 0; padding-left: 20px; }
.cart-flag-note ul.flag-reasons li { margin: 1px 0; }
