:root{
  --ink:#0f172a;
  --muted:#64748b;
  --green:#0f766e;
  --green-dark:#0d5c56;
  --lime:#ccfbf1;
  --line:#e2e8f0;
  --paper:#f8fafc;
  --white:#ffffff;
  --danger:#dc2626;
  --danger-bg:#fef2f2;
  --shadow:0 1px 3px 0 rgb(0 0 0 / 0.1),0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md:0 4px 6px -1px rgb(0 0 0 / 0.1),0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius:16px;
  --font-sans:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;
}
*{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth}
body{
  margin:0;
  background:var(--paper);
  color:var(--ink);
  font:16px/1.55 var(--font-sans);
  -webkit-font-smoothing:antialiased;
}
.shell{
  max-width:1280px;
  margin:0 auto;
  padding:0 20px;
  min-height:100vh;
  display:flex;
  flex-direction:column;
}
header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:24px 0;
  border-bottom:1px solid var(--line);
  background:var(--white);
  position:sticky;
  top:0;
  z-index:10;
}
.brand{
  font-weight:800;
  font-size:20px;
  display:flex;
  align-items:center;
  gap:10px;
  text-decoration:none;
  color:var(--ink);
}
.mark{
  display:grid;
  place-items:center;
  width:40px;
  height:40px;
  background:var(--green);
  color:var(--lime);
  border-radius:12px;
  font-weight:900;
  font-size:18px;
}
.badge{
  font-size:11.5px;
  font-weight:700;
  background:#f1f5f9;
  color:var(--muted);
  padding:6px 12px;
  border-radius:20px;
  border:1px solid var(--line);
  white-space:nowrap;
}
nav{
  display:flex;
  gap:4px;
  border-bottom:1px solid var(--line);
  padding:18px 0 16px;
  overflow-x:auto;
  scrollbar-width:none;
  scroll-snap-type:x proximity;
}
nav::-webkit-scrollbar{display:none}
nav a{
  padding:10px 14px;
  text-decoration:none;
  color:var(--muted);
  font-size:13.5px;
  font-weight:600;
  white-space:nowrap;
  border-radius:8px;
  transition:all 0.2s;
  border:1px solid transparent;
  scroll-snap-align:center;
}
nav a[aria-current],nav a:hover{
  background:var(--green);
  color:#fff;
  border-color:var(--green);
}
main{
  padding:32px 0 80px;
  flex:1;
  min-height:60vh;
}
.account{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:12px;
  font-size:13px;
  color:var(--muted);
  margin-bottom:32px;
}
.account a{
  color:var(--green);
  text-decoration:none;
  font-weight:600;
  margin-left:0;
}
a{color:var(--green);text-decoration:none;text-underline-offset:3px}
a:hover{text-decoration:underline}
a:focus-visible,button:focus-visible,summary:focus-visible{outline:3px solid var(--green);outline-offset:3px}
h1{
  font-size:clamp(26px,5vw,40px);
  line-height:1.2;
  letter-spacing:-0.5px;
  margin:0 0 10px;
  color:var(--ink);
}
h2{
  font-size:20px;
  letter-spacing:-0.3px;
  margin:0 0 16px;
  color:var(--ink);
  font-weight:700;
}
h3{
  font-size:16px;
  margin:0 0 12px;
  color:var(--ink);
  font-weight:600;
}
.eyebrow{
  text-transform:uppercase;
  letter-spacing:1.6px;
  font-size:10.5px;
  font-weight:800;
  color:var(--green);
  margin:0 0 8px;
  display:block;
}
.muted{color:var(--muted);font-size:13.5px}
.stats{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(170px,1fr));
  gap:16px;
  margin:24px 0;
}
.stat{
  background:var(--white);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:22px;
  box-shadow:var(--shadow);
  display:flex;
  flex-direction:column;
  gap:6px;
}
.stat:first-child{
  background:linear-gradient(135deg,var(--green),var(--green-dark));
  color:#fff;
  border-color:var(--green);
}
.stat span{
  display:block;
  font-size:11px;
  font-weight:700;
  letter-spacing:0.5px;
  text-transform:uppercase;
  opacity:0.9;
}
.stat strong{
  font-size:28px;
  font-weight:800;
  letter-spacing:-0.5px;
  white-space:nowrap;
}
.stat .button{
  font-size:13px;
  margin-top:10px;
}
.card{
  background:var(--white);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:26px;
  margin:22px 0;
  box-shadow:var(--shadow);
}
.card + .card{margin-top:0}
.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px}
.grid > .card{margin-top:0}
.grid > .card,.grid fieldset{min-width:0}
.filters{grid-template-columns:1.4fr repeat(4,minmax(0,1fr))}
.section-head{display:flex;justify-content:space-between;align-items:center;gap:16px;margin-bottom:16px}
.section-head h2{margin:0}
.supplier-list,.product-list{display:grid;gap:10px}
.supplier-row,.product-row{
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  padding:18px 20px;
}
.supplier-row{
  display:flex;align-items:center;gap:20px;
  color:var(--ink);text-decoration:none;
  transition:border-color .18s,background .18s,box-shadow .18s;
}
.supplier-row:hover,.supplier-row:focus-visible{border-color:var(--green);background:#f8fffd;box-shadow:var(--shadow);text-decoration:none}
.supplier-name{display:grid;gap:2px;min-width:190px;flex:1}
.supplier-name strong,.product-row strong{font-size:16px;line-height:1.3}
.supplier-name small,.supplier-figures small{display:block;color:var(--muted);font-size:11px;font-weight:650}
.supplier-figures{display:flex;align-items:center;gap:24px;font-size:14px;font-variant-numeric:tabular-nums}
.supplier-figures>span{display:grid;gap:3px;white-space:nowrap}
.supplier-owed{padding-inline-start:18px;border-inline-start:1px solid var(--line)}
.supplier-owed strong{font-size:19px;color:var(--green)}
.product-row{display:flex;align-items:center;justify-content:space-between;gap:16px}
.product-row p{color:var(--muted);font-size:13px;margin-top:4px}
.row-actions{display:flex;align-items:center;gap:16px;flex-wrap:wrap}
.row-actions form{margin:0}
.row-actions a{font-weight:650}
.supplier-stats .stat:first-child{background:var(--white);color:var(--ink);border-color:var(--line)}
.supplier-stats .stat:last-child{background:linear-gradient(135deg,var(--green),var(--green-dark));color:#fff;border-color:var(--green)}
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}
.allocation-table-wrap{max-width:100%}
.allocation-scroll-hint{margin-bottom:8px}
table{
  width:100%;
  border-collapse:collapse;
  font-size:13.5px;
  text-align:left;
}
th{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:1px;
  color:var(--muted);
  background:var(--paper);
  padding:12px 14px;
  border-bottom:1px solid var(--line);
  font-weight:700;
}
td{
  padding:14px;
  border-bottom:1px solid var(--line);
  vertical-align:top;
}
tr:last-child td{border-bottom:0}
tr:hover td{background:#fafbfc}
.num{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap;font-size:13.5px}
small{color:var(--muted)}
.price-help{
  display:block;
  margin-top:6px;
  font-size:11.5px;
  font-weight:400;
  line-height:1.4;
  color:var(--muted);
}
input[readonly]{background:#f1f5f9;color:#475569;cursor:not-allowed}
label{
  display:block;
  font-size:13px;
  font-weight:650;
  margin-bottom:8px;
  color:var(--ink);
}
input,select{
  display:block;
  width:100%;
  margin-top:5px;
  min-height:48px;
  border:1px solid #cbd5e1;
  border-radius:8px;
  padding:10px 14px;
  background:var(--white);
  color:var(--ink);
  font:inherit;
  transition:border-color 0.2s,box-shadow 0.2s;
}
input:focus,select:focus{
  outline:none;
  border-color:var(--green);
  box-shadow:0 0 0 3px rgb(15 118 110 / 0.15);
}
button,.button{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  background:var(--green);
  color:#fff;
  border:1px solid var(--green);
  border-radius:8px;
  padding:11px 20px;
  font:650 14px/1.3 var(--font-sans);
  cursor:pointer;
  text-decoration:none;
  min-height:46px;
  gap:6px;
  transition:all 0.2s;
}
button:hover,.button:hover{
  background:var(--green-dark);
  border-color:var(--green-dark);
  transform:translateY(-1px);
}
button:active{transform:translateY(0)}
button:disabled,.button:disabled{
  opacity:0.6;
  cursor:not-allowed;
  transform:none;
}
.secondary{
  color:var(--green);
  background:#fff;
  border-color:#cbd5e1;
}
.secondary:hover{
  background:#f1f5f9;
  border-color:var(--green);
}
.text-button{
  padding:6px 0;
  min-height:auto;
  background:none;
  color:var(--muted);
  border:0;
  font-size:12px;
  text-decoration:none;
}
.text-button:hover{color:var(--green);background:transparent}
.danger{
  background:var(--danger);
  border-color:var(--danger);
}
.danger:hover{background:#b91c1c;border-color:#b91c1c}
.actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin:24px 0;
}
.purchase-line{
  display:grid;
  grid-template-columns:2fr 1fr 1fr 1fr auto;
  gap:14px;
  align-items:center;
  padding:16px 0;
  border-bottom:1px solid var(--line);
}
.line-total{
  font-size:14px;
  font-weight:750;
  font-variant-numeric:tabular-nums;
  color:var(--ink);
}
.purchase-total{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:24px 0;
  margin:16px 0;
  font-size:18px;
  border-top:1px solid var(--line);
  border-bottom:1px solid var(--line);
}
.purchase-total strong{
  font-size:26px;
  font-weight:800;
}
.notice{
  padding:14px 18px;
  border-radius:10px;
  background:#f0fdf4;
  color:#166534;
  border:1px solid #bbf7d0;
  font-size:13.5px;
  margin:16px 0;
}
[role="alert"].notice{background:#fef2f2;color:#991b1b;border-color:#fecaca}
[role="status"].notice{background:#eff6ff;color:#1e40af;border-color:#bfdbfe}
.empty{
  text-align:center;
  padding:48px 24px;
  color:var(--muted);
}
.empty h3{color:var(--ink)}
.welcome{
  max-width:720px;
  padding:48px 0;
}
.welcome h1{font-size:clamp(36px,8vw,56px)}
.welcome p{max-width:560px;font-size:17px;line-height:1.6;color:var(--muted)}
.welcome .button{margin-top:24px}
.statement-head{
  margin:24px 0 20px;
  padding-bottom:16px;
  border-bottom:1px solid var(--line);
}
.statement-head h2{font-size:22px;margin:0}
.statement-head p{color:var(--muted);font-size:13.5px;margin:4px 0 0}
details{max-width:340px}
summary{cursor:pointer;color:var(--green);font-weight:600;font-size:13px}
details form{margin-top:12px;min-width:240px}
pre{
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  font-size:11px;
  font-family:var(--font-mono);
  background:#f1f5f9;
  padding:12px;
  border-radius:8px;
  border:1px solid var(--line);
  color:var(--muted);
}
footer{
  border-top:1px solid var(--line);
  padding:26px 0 40px;
  font-size:12px;
  color:var(--muted);
  margin-top:auto;
}
@media (min-width:721px) and (max-width:960px){
  .filters{grid-template-columns:repeat(2,minmax(0,1fr))}
  .supplier-row{flex-wrap:wrap}
  .supplier-name{flex-basis:100%}
}
/* Mobile-first */
@media(max-width:720px){
  .shell{padding:0 16px}
  header{padding:18px 0;align-items:flex-start;flex-wrap:wrap}
  .brand{font-size:17px}
  .mark{width:36px;height:36px;font-size:16px}
  .badge{font-size:10px;padding:5px 10px}
  nav{gap:2px}
  nav a{font-size:12px;padding:10px 12px;min-height:44px;display:inline-flex;align-items:center}
  main{padding:20px 0 60px}
  .account{font-size:12px;margin-bottom:24px}
  .grid,.filters{grid-template-columns:minmax(0,1fr);gap:0}
  .card{padding:20px;margin:16px 0}
  .stats{gap:12px;margin:20px 0}
  .stats .stat:last-child{grid-column:1/-1}
  .stat{padding:18px;min-width:140px}
  .stat strong{font-size:22px}
  .purchase-line{
    grid-template-columns:1fr 1fr;
    gap:10px;
  }
  .purchase-line>label:first-child{grid-column:1/-1}
  .purchase-line .remove-line{grid-column:2}
  .purchase-line label{margin-bottom:4px}
  .purchase-total{font-size:15px}
  .purchase-total strong{font-size:21px}
  td,th{padding:12px 10px;font-size:12px}
  h1{letter-spacing:-0.4px}
  h2{font-size:18px}
  .actions>*{flex:1;min-width:130px;justify-content:center}
  .badge{max-width:100px;white-space:normal}
  .supplier-row,.product-row{padding:16px;align-items:flex-start}
  .supplier-row{flex-wrap:wrap;gap:10px}
  .supplier-name{min-width:0;flex-basis:100%}
  .supplier-figures{width:100%;display:grid;grid-template-columns:1fr 1fr;gap:10px;font-size:13px}
  .supplier-owed{grid-column:1/-1;padding:10px 0 0;border-inline-start:0;border-top:1px solid var(--line)}
  .supplier-owed strong{font-size:16px}
  .supplier-row>span:last-child{display:none}
  .product-row{flex-direction:column}
  .section-head{align-items:flex-start}
}
/* Print */
@media print{
  body{background:#fff;color:#000;font-size:10pt}
  .shell{max-width:none;padding:0}
  header{padding:0 0 15px;border-bottom:none}
  nav,.account,.no-print,footer,.actions,button,.secondary,.text-button,.remove-line{display:none!important}
  .card{border:0;padding:0;margin:20px 0;box-shadow:none}
  .stats{gap:5px}
  .stat,.stat:first-child{color:#000;background:#fff;border:1px solid #999;padding:10px;min-width:100px}
  .stat strong{font-size:14pt}
  .table-wrap{overflow:visible}
  table{font-size:9pt}
  thead{display:table-header-group}
  tr{break-inside:avoid}
  h1{font-size:22pt}
  main{padding:0}
  .badge{display:none}
}
/* RTL support */
[dir="rtl"]{
  direction:rtl;
  unicode-bidi:embed;
}
[dir="rtl"] .account{justify-content:flex-start;text-align:left}
[dir="rtl"] .account a{margin-left:12px;margin-right:0}
[dir="rtl"] table{text-align:right}
[dir="rtl"] .num{text-align:left}
[dir="rtl"] .purchase-line{
  grid-template-columns:2fr 1fr 1fr 1fr auto;
}
[dir="rtl"] .purchase-line>label:first-child{grid-column:auto}
[dir="rtl"] .purchase-line .remove-line{grid-column:1}
[dir="rtl"] label{text-align:right}
[dir="rtl"] .eyebrow{letter-spacing:0}
[dir="rtl"] .brand{flex-direction:row-reverse}
[dir="rtl"] .mark{margin-right:10px;margin-left:0}
[dir="rtl"] nav a{padding:10px 14px}
[dir="rtl"] .stats{direction:rtl}
[dir="rtl"] .card{text-align:right}
[dir="rtl"] .button,.secondary{text-align:right}
[dir="rtl"] .line-total,[dir="rtl"] .purchase-total strong{unicode-bidi:isolate;direction:ltr}
[dir="rtl"] input,[dir="rtl"] select{text-align:right}
[dir="rtl"] .price-help{text-align:right}
[dir="rtl"] .muted{text-align:right}
[dir="rtl"] h1,[dir="rtl"] h2,[dir="rtl"] h3{text-align:right}
[dir="rtl"] .empty{text-align:right}
[dir="rtl"] .stat{text-align:right}
[dir="rtl"] .stat strong{unicode-bidi:isolate;direction:ltr}
[dir="rtl"] footer{text-align:right}
[dir="rtl"] .actions{flex-direction:row-reverse}
@media(max-width:720px){
  [dir="rtl"] .purchase-line{grid-template-columns:1fr 1fr}
  [dir="rtl"] .purchase-line>label:first-child{grid-column:1/-1}
  [dir="rtl"] .purchase-line .remove-line{grid-column:2}
  [dir="rtl"] nav a{padding:10px 12px}
}

/* v0.5.0: supplier directory and separate catalogue forms. */
.stat-link{display:block;text-decoration:none;color:inherit}
.stat-link:hover{box-shadow:var(--shadow-md);border-color:var(--green)}
.stat-link:focus-visible,.directory-row:focus-visible{outline:3px solid var(--green);outline-offset:3px}
.catalogue-nav{flex-wrap:wrap}
.catalogue-form{max-width:760px}
.supplier-search{display:flex;align-items:end;gap:16px;flex-wrap:wrap}
.supplier-search label{flex:1;min-width:0;margin:0}
.supplier-search a{padding-block:12px}
.supplier-status{font-weight:600;color:var(--green)}
.is-archived{border-inline-start:4px solid var(--muted);background:#f1f5f9}
.is-archived .supplier-status{color:#475569}
.directory-row{overflow-wrap:anywhere}
.directory-balance{display:flex;flex-direction:column;margin-inline-start:auto;flex-shrink:0}
.directory-balance small{color:var(--muted)}
@media(max-width:720px){.supplier-search{align-items:stretch}.supplier-search label{flex-basis:100%}.directory-balance{margin-inline-start:0}.catalogue-nav .button{white-space:normal}}

label[hidden]{display:none!important}
.purchase-line .quantity-unit select{min-width:0;max-width:100%}

/* v0.5.0 Phase 2B: product search and repeat purchase */
.repeat-list{display:flex;flex-direction:column;gap:12px}
.repeat-row{border:1px solid var(--line);border-radius:12px;background:#fff;padding:16px 20px;display:flex;flex-wrap:wrap;gap:12px;align-items:center}
.repeat-info{flex:1;min-width:200px;font-size:13.5px;color:var(--ink)}
.repeat-info strong{color:var(--green)}
.repeat-items{flex:2;min-width:150px;font-size:12.5px;color:var(--muted)}
.repeat-item{display:inline-block;margin:2px 6px 2px 0;padding:4px 8px;background:#f1f5f9;border-radius:6px;border:1px solid var(--line)}
.repeat-actions{flex-shrink:0}
.repeat-line{display:flex;flex-wrap:wrap;gap:12px;align-items:center;padding:12px 0;border-bottom:1px solid var(--line)}
.repeat-line-info{flex:1;min-width:180px;font-size:13px;color:var(--ink)}
.repeat-line-info strong{color:var(--ink)}
.repeat-line-compare{flex:1;min-width:150px;font-size:12.5px;color:var(--muted)}
.repeat-line-fields{flex:1;min-width:160px}
.problem{color:var(--danger);font-size:11.5px;font-weight:600}
.price-changed{color:#b45309;font-size:11.5px;font-weight:600}
@media(max-width:720px){
  .repeat-row{flex-direction:column;align-items:flex-start}
  .repeat-actions{align-self:stretch}
  .repeat-actions .button{width:100%}
  .repeat-line{flex-direction:column;align-items:flex-start}
}

#product-matches:not([hidden]) { display: grid; gap: .25rem; margin-block: .5rem 1rem; }
#product-matches button { text-align: start; overflow-wrap: anywhere; min-height: 44px; white-space: normal; }
#product-matches [aria-selected="true"] { outline: 2px solid currentColor; outline-offset: -3px; }
