/* Farmilyne — field-green POS theme */
@font-face { font-family: 'Bricolage'; src: url('/vendor/fonts/bricolage.woff2') format('woff2'); font-weight: 200 800; font-display: swap; }
@font-face { font-family: 'Public Sans'; src: url('/vendor/fonts/public-sans.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }

:root {
  --ink: #17271f;
  --ink-2: #2b3d33;
  --muted: #5f6e64;
  --paper: #f3f6f0;
  --surface: #ffffff;
  --line: #dce3d6;
  --line-2: #eaefe6;
  --leaf: #2f7d4a;
  --leaf-deep: #1f5c35;
  --leaf-wash: #e6f1e8;
  --turmeric: #e4a11b;
  --turmeric-wash: #fdf4de;
  --danger: #b83227;
  --danger-wash: #fbe9e7;
  --info: #2d6a8a;
  --radius-s: 6px;
  --radius: 10px;
  --radius-l: 16px;
  --shadow: 0 1px 2px rgba(23, 39, 31, .06), 0 4px 16px rgba(23, 39, 31, .06);
  --shadow-pop: 0 12px 40px rgba(23, 39, 31, .18);
  --display: 'Bricolage', 'Segoe UI', system-ui, sans-serif;
  --body: 'Public Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --sidebar: 232px;
  --t: 160ms cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--body); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--paper);
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.65rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
a { color: var(--leaf-deep); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--leaf); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #dfe8e1; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px;
}
.brand { padding: 4px 10px 18px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 12px; }
.brand-mark { display: flex; align-items: center; gap: 10px; }
.brand-mark svg { width: 30px; height: 30px; }
.brand-name { font-family: var(--display); font-weight: 750; font-size: 1.05rem; color: #fff; letter-spacing: .01em; line-height: 1.05; }
.brand-name small { display: block; font-weight: 500; font-size: .72rem; color: #9fb5a6; letter-spacing: .08em; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-s); color: #c6d4ca; text-decoration: none;
  font-weight: 500; transition: background var(--t), color var(--t);
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--leaf); color: #fff; }
.nav a.active .icon { color: var(--turmeric); }
.nav .sep { height: 1px; background: rgba(255,255,255,.08); margin: 8px 6px; }
.whoami { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 10px 0; font-size: .85rem; }
.whoami strong { color: #fff; display: block; font-weight: 600; }
.whoami .loc { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 99px; background: rgba(228,161,27,.16); color: var(--turmeric); font-weight: 600; font-size: .75rem; }
.whoami button { background: none; border: 0; color: #9fb5a6; padding: 6px 0 0; cursor: pointer; font-size: .82rem; text-decoration: underline; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar-mobile { display: none; }
.content { padding: 26px 30px 16px; flex: 1; animation: pageIn .22s var(--t); }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.footer { padding: 14px 30px 20px; color: var(--muted); font-size: .8rem; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Controls ---------- */
.btn, a.btn { text-decoration: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background var(--t), border-color var(--t), transform 80ms;
}
.btn:hover { border-color: #bcc8b8; background: #fafcf8; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn.primary:hover { background: var(--leaf-deep); border-color: var(--leaf-deep); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: .85rem; }
.btn.icon-only { width: 34px; padding: 0; }
.btn.lg { height: 48px; font-size: 1.02rem; padding: 0 22px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-size: .78rem; }
.input, select.input, textarea.input {
  height: 38px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); padding: 0 11px; width: 100%;
  transition: border-color var(--t), box-shadow var(--t);
}
textarea.input { height: auto; padding: 8px 11px; }
.input:focus { outline: none; border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(47,125,74,.14); }
.input[readonly] { background: var(--line-2); }
.input.num { text-align: right; }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(184,50,39,.12); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--leaf); }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid-form .full { grid-column: 1 / -1; }

/* ---------- Cards / panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 18px 20px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.filters .field { width: 150px; }
.filters .field.wide { width: 230px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th {
  text-align: left; font-weight: 600; font-size: .78rem; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: #fafbf8; position: sticky; top: 0; white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th .sort-ind { opacity: .5; margin-left: 3px; }
table.data td.code { white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr { transition: background var(--t); }
table.data tbody tr:hover { background: #f8faf6; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbf8; }
.code { font-weight: 600; color: var(--leaf-deep); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--line-2); color: var(--ink-2); }
.pill.ok { background: var(--leaf-wash); color: var(--leaf-deep); }
.pill.off { background: #eeeeee; color: #6b6b6b; }
.pill.warn { background: var(--turmeric-wash); color: #8a5c00; }
.pill.admin { background: #e3eef4; color: var(--info); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; font-size: .85rem; color: var(--muted); flex-wrap: wrap; }
.pager .btns { display: flex; gap: 6px; align-items: center; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .icon { width: 34px; height: 34px; color: #b5c3b8; margin-bottom: 8px; }
.empty strong { display: block; color: var(--ink); font-size: 1rem; margin-bottom: 4px; }
.skeleton { height: 14px; border-radius: 4px; background: linear-gradient(90deg, #edf1ea 25%, #f6f8f4 37%, #edf1ea 63%); background-size: 400% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- Autocomplete ---------- */
.ac { position: relative; }
.ac-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-pop); max-height: 320px; overflow-y: auto; padding: 4px; margin: 0; list-style: none;
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.ac-list li { padding: 8px 10px; border-radius: var(--radius-s); cursor: pointer; display: flex; align-items: center; gap: 10px; }
.ac-list li[aria-selected="true"] { background: var(--leaf-wash); }
.ac-list li.ac-empty { color: var(--muted); cursor: default; }
.ac-main { flex: 1; min-width: 0; }
.ac-main b { font-weight: 600; }
.ac-sub { font-size: .78rem; color: var(--muted); }
.ac-price { font-weight: 700; font-family: var(--display); }
mark { background: #fbe7b6; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---------- Bill screen ---------- */
.bill { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.bill-head { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; padding: 16px 18px; }
.bill-head > .field:nth-child(-n+3) { grid-column: span 2; }
.bill-head > .field:nth-child(n+4) { grid-column: span 3; }
.bill-head .input[readonly] { font-variant-numeric: tabular-nums; }
@media (min-width: 1560px) { .bill-head { grid-template-columns: 1.2fr 1fr .7fr 1.2fr 1.3fr; } .bill-head > .field { grid-column: auto !important; } }
.bill-entry { padding: 14px 18px; border-top: 1px solid var(--line-2); background: #fbfcf9; display: flex; gap: 10px; align-items: flex-end; }
.bill-entry .ac { flex: 1; }
.bill-entry .input { height: 46px; font-size: 1.02rem; }
.bill-entry .ac .icon { position: absolute; left: 13px; top: 14px; color: var(--muted); }
.bill-entry .ac .input { padding-left: 40px; }
.kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: .72rem; font-weight: 600; color: var(--muted); background: #fff; }
.hints { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); padding: 8px 18px 12px; }
table.lines th, table.lines td { padding: 7px 6px; }
table.lines th:first-child, table.lines td:first-child { padding-left: 14px; color: var(--muted); }
table.lines td:last-child { padding-right: 10px; }
table.lines td { font-size: .9rem; white-space: nowrap; }
table.lines td.line-item { white-space: normal; min-width: 150px; }
table.lines .qty { width: 66px; height: 34px; }
table.lines tbody tr { animation: rowIn .18s ease-out; }
@keyframes rowIn { from { background: var(--turmeric-wash); } to { background: transparent; } }
.line-item b { display: block; font-weight: 600; }
.line-item small { color: var(--muted); }

/* Receipt panel — the tear-off slip */
.receipt { position: sticky; top: 18px; }
.slip {
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius-l) var(--radius-l) 0 0;
  box-shadow: var(--shadow); padding: 20px 22px 18px; position: relative;
}
.slip::after {
  content: ''; position: absolute; left: -1px; right: -1px; bottom: -10px; height: 10px;
  background: linear-gradient(-45deg, transparent 6px, var(--surface) 0) 0 0 / 12px 10px repeat-x,
              linear-gradient(45deg, transparent 6px, var(--surface) 0) 0 0 / 12px 10px repeat-x;
  filter: drop-shadow(0 1px 0 var(--line));
}
.slip-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: .9rem; color: var(--ink-2); }
.slip-row.minus span:last-child { color: var(--leaf-deep); }
.slip-rule { border-top: 1px dashed #c9d3c4; margin: 10px 0; }
.grand { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 0 2px; }
.grand { gap: 10px; }
.grand span:first-child { font-weight: 600; white-space: nowrap; }
.grand-amt { font-family: var(--display); font-size: clamp(1.6rem, 2.4vw, 2.3rem); white-space: nowrap; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.grand-amt.bump { animation: bump .25s ease-out; }
@keyframes bump { 40% { color: var(--leaf); } }
.pay { margin-top: 22px; padding: 16px 22px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow); }
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pay .input { height: 44px; font-size: 1.05rem; font-weight: 600; }
.credit-box { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-radius: var(--radius-s); background: var(--turmeric-wash); }
.credit-box.zero { background: var(--leaf-wash); }
.credit-box b { font-family: var(--display); font-size: 1.2rem; }
.pay-error { color: var(--danger); font-size: .84rem; margin-top: 8px; font-weight: 600; }
.pay-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 14px; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); animation: kpiIn .4s both; }
.kpi:nth-child(2) { animation-delay: 40ms; } .kpi:nth-child(3) { animation-delay: 80ms; } .kpi:nth-child(4) { animation-delay: 120ms; }
.kpi:nth-child(5) { animation-delay: 160ms; } .kpi:nth-child(6) { animation-delay: 200ms; }
@keyframes kpiIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.kpi .k-label { font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.kpi .k-label .icon { width: 16px; height: 16px; color: var(--leaf); }
.kpi .k-value { font-family: var(--display); font-size: 1.6rem; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.kpi.hero { background: var(--ink); color: #fff; border-color: var(--ink); grid-column: span 2; }
.kpi.hero .k-label { color: #a9bdb0; } .kpi.hero .k-label .icon { color: var(--turmeric); }
.kpi.hero .k-value { font-size: 2.3rem; }
.kpi.hero .k-sub { color: #c6d4ca; font-size: .85rem; margin-top: 4px; }
.charts { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.chart-box { padding: 16px 18px; }
.chart-box h3 { margin-bottom: 12px; }
.chart-canvas { position: relative; height: 260px; }

/* ---------- Reports ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs button { background: none; border: 0; padding: 12px 12px 10px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--leaf); }

/* ---------- Modal / toast ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(23,39,31,.42); display: flex; align-items: flex-start; justify-content: center; z-index: 100;
  padding: 6vh 16px 16px; overflow-y: auto; animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-pop); width: 100%; max-width: 560px; animation: rise .18s var(--t); }
.modal.wide { max-width: 980px; }
@keyframes rise { from { transform: translateY(10px) scale(.99); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line-2); background: #fafbf8; border-radius: 0 0 var(--radius-l) var(--radius-l); }
.success-hero { text-align: center; padding: 10px 0 4px; }
.success-hero .tick { width: 58px; height: 58px; border-radius: 50%; background: var(--leaf-wash); color: var(--leaf); display: inline-flex; align-items: center; justify-content: center; animation: tick .35s var(--t); }
.success-hero .tick .icon { width: 30px; height: 30px; stroke-width: 2.4; }
@keyframes tick { from { transform: scale(.6); opacity: 0; } }
.success-hero .inv-no { font-family: var(--display); font-size: 1.6rem; font-weight: 750; margin-top: 10px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.summary-grid div { background: var(--paper); border-radius: var(--radius-s); padding: 8px 10px; text-align: left; }
.summary-grid small { display: block; color: var(--muted); font-size: .75rem; }
.summary-grid b { font-family: var(--display); }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 420px; padding: 11px 14px; border-radius: var(--radius);
  background: var(--ink); color: #fff; box-shadow: var(--shadow-pop); animation: toastIn .2s var(--t); font-size: .9rem;
}
.toast.error { background: var(--danger); }
.toast.ok .icon { color: #9fe0b1; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: linear-gradient(rgba(246, 243, 236, .35), rgba(246, 243, 236, .35)), #f6f3ec url('/img/login-bg.svg') center / cover no-repeat; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 32px 30px 24px; box-shadow: 0 2px 4px rgba(23, 39, 31, .05), 0 18px 48px rgba(23, 39, 31, .12); }
.login-logo { display: flex; justify-content: center; margin-bottom: 22px; }
.login-logo img { display: block; max-width: 200px; max-height: 72px; width: auto; height: auto; }
.login-logo-text { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 750; font-size: 1.5rem; color: var(--ink); }
.login-logo-text svg { width: 36px; height: 36px; }
.login-card h2 { font-size: 1.35rem; margin-bottom: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.login-error { background: var(--danger-wash); color: var(--danger); padding: 9px 12px; border-radius: var(--radius-s); font-size: .88rem; font-weight: 600; }
.login-foot { margin-top: 24px; font-size: .8rem; color: var(--muted); text-align: center; }

/* ---------- Invoice view ---------- */
.inv-view { font-size: .9rem; }
#print-root { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .bill { grid-template-columns: minmax(0, 1fr); }
  .receipt { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .pay { margin-top: 0; }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 90; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .22s var(--t); }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .topbar-mobile { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 50; }
  .topbar-mobile .brand-name { font-size: .95rem; }
  .topbar-mobile button { background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; }
  .content { padding: 18px 14px 10px; }
  .footer { padding: 12px 14px 18px; }
  .receipt { grid-template-columns: 1fr; }
  .bill-head { grid-template-columns: 1fr 1fr; }
  .bill-head > .field { grid-column: auto !important; }
  .login-card { padding: 26px 20px 20px; }
  .grid-form { grid-template-columns: 1fr; }
  .kpi.hero { grid-column: auto; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .filters .field, .filters .field.wide { width: calc(50% - 5px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
}
table.data td.wide-cell { min-width: 170px; }
