/* ==========================================================================
   Kaia Inventory — design system
   Hand-authored, compiled nowhere: one plain CSS file served from your own
   server. No Node build step, no CDN, no external font request.
   ========================================================================== */

:root {
  --green-50:  #f1f7f2;
  --green-100: #dcebdf;
  --green-200: #b9d7c0;
  --green-400: #6aa67c;
  --green-500: #4e8c61;
  --green-600: #3d7250;
  --green-700: #2f5a3f;

  --sand-50:  #faf8f4;
  --sand-100: #f3eee4;
  --sand-200: #e7dfd0;
  --sand-300: #d6cab3;

  --ink-900: #1c211e;
  --ink-700: #3c443f;
  --ink-500: #6b756f;
  --ink-400: #8d968f;
  --ink-300: #c3cac5;

  --red-50:  #fdf2f1;
  --red-100: #fbdedb;
  --red-500: #c0392b;
  --red-600: #a32c20;

  --orange-50:  #fdf6ec;
  --orange-100: #fae7cb;
  --orange-500: #c57b16;
  --orange-600: #a2640f;

  --white: #ffffff;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(28, 33, 30, .06), 0 1px 3px rgba(28, 33, 30, .04);
  --shadow: 0 2px 6px rgba(28, 33, 30, .07), 0 6px 16px rgba(28, 33, 30, .05);
  --shadow-lg: 0 8px 28px rgba(28, 33, 30, .12);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;

  --tap: 48px;           /* minimum touch target */
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* --------------------------------------------------------------- reset -- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-900);
  background: var(--sand-50);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
a { color: var(--green-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* -------------------------------------------------------------- layout -- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.container-narrow { max-width: 620px; }
.main { flex: 1; padding: 18px 0 96px; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--white);
  border-bottom: 1px solid var(--sand-200);
  min-height: var(--header-h);
  display: flex; align-items: center;
}
.topbar .container { display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--ink-900); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, var(--green-400), var(--green-600));
  color: var(--white); display: grid; place-items: center;
  font-size: .78rem; font-weight: 700; letter-spacing: .02em;
}
.brand-text { font-size: 1rem; }
.brand-sub { display: block; font-size: .7rem; color: var(--ink-500); font-weight: 500; }
.topbar-spacer { flex: 1; }

.navlinks { display: none; gap: 2px; }
@media (min-width: 900px) { .navlinks { display: flex; } }
.navlinks a {
  padding: 8px 11px; border-radius: 9px; color: var(--ink-700);
  font-size: .9rem; font-weight: 550;
}
.navlinks a:hover { background: var(--sand-100); text-decoration: none; }
.navlinks a.active { background: var(--green-50); color: var(--green-700); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--sand-200);
  background: var(--white); display: grid; place-items: center; cursor: pointer;
  position: relative; color: var(--ink-700);
}
.icon-btn:hover { background: var(--sand-100); }
.badge-dot {
  position: absolute; top: 5px; right: 5px; min-width: 17px; height: 17px;
  border-radius: 9px; background: var(--red-500); color: #fff;
  font-size: .62rem; font-weight: 700; display: grid; place-items: center; padding: 0 4px;
}

/* ------------------------------------------------------------ bottom nav */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--white); border-top: 1px solid var(--sand-200);
  display: flex; padding-bottom: var(--safe-bottom);
}
@media (min-width: 900px) { .tabbar { display: none; } }
.tabbar a {
  flex: 1; min-height: 58px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  font-size: .66rem; font-weight: 600; color: var(--ink-500); text-decoration: none;
}
.tabbar a.active { color: var(--green-600); }
.tabbar svg { width: 21px; height: 21px; }

/* --------------------------------------------------------------- cards -- */
.card {
  background: var(--white); border: 1px solid var(--sand-200);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 16px; margin-bottom: 14px;
}
.card-lg { padding: 20px; border-radius: var(--radius-lg); }
.card-flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-section { padding: 14px 16px; border-bottom: 1px solid var(--sand-100); }
.card-section:last-child { border-bottom: 0; }

.grid { display: grid; gap: 14px; }
@media (min-width: 760px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* -------------------------------------------------------------- buttons -- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  font-size: .95rem; font-weight: 650; font-family: inherit;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); color: #fff; }
.btn-secondary { background: var(--white); color: var(--ink-900); border-color: var(--sand-300); }
.btn-secondary:hover { background: var(--sand-100); }
.btn-ghost { background: transparent; color: var(--ink-700); }
.btn-ghost:hover { background: var(--sand-100); }
.btn-danger { background: var(--red-500); color: #fff; }
.btn-danger:hover { background: var(--red-600); color: #fff; }
.btn-sm { min-height: 38px; padding: 0 13px; font-size: .85rem; border-radius: 10px; }
.btn-lg { min-height: 56px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* -------------------------------------------------------- action tiles -- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile {
  background: var(--white); border: 1px solid var(--sand-200); border-radius: var(--radius);
  padding: 14px 12px; display: flex; flex-direction: column; gap: 7px;
  color: var(--ink-900); min-height: 84px; box-shadow: var(--shadow-sm);
}
.tile:hover { text-decoration: none; border-color: var(--green-200); background: var(--green-50); }
.tile svg { width: 20px; height: 20px; color: var(--green-600); }
.tile-label { font-weight: 600; font-size: .88rem; line-height: 1.3; }

/* --------------------------------------------------------------- forms -- */
label, .label {
  display: block; font-size: .83rem; font-weight: 600;
  color: var(--ink-700); margin-bottom: 5px;
}
.help { font-size: .79rem; color: var(--ink-500); margin-top: 4px; }
input[type="text"], input[type="number"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], input[type="url"], input[type="tel"],
input[type="search"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--sand-300); border-radius: 11px;
  font-family: inherit; font-size: 1rem; color: var(--ink-900);
  background: var(--white); -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b756f'%3E%3Cpath d='M5.5 7.5l4.5 4.5 4.5-4.5' stroke='%236b756f' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
  padding-right: 34px;
}
textarea { min-height: 84px; padding-top: 10px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--green-400); outline-offset: 1px; border-color: var(--green-400);
}
.field { margin-bottom: 14px; }
.field-row { display: grid; gap: 12px; }
@media (min-width: 620px) { .field-row-2 { grid-template-columns: 1fr 1fr; } }
.checkline { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.checkline input[type="checkbox"], .checkline input[type="radio"] {
  width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--green-600);
}
.checkline label { margin: 0; font-weight: 500; color: var(--ink-900); }
/* A group of checkboxes: one tappable row per option, two columns when there's room. */
.checkgrid > div { display: grid; gap: 2px; }
@media (min-width: 560px) { .checkgrid > div { grid-template-columns: 1fr 1fr; gap: 2px 14px; } }
.checkgrid label {
  display: flex; align-items: center; gap: 9px; margin: 0;
  padding: 9px 10px; border-radius: 10px; min-height: 42px;
  font-weight: 500; color: var(--ink-900); font-size: .9rem; cursor: pointer;
  border: 1px solid transparent;
}
.checkgrid label:hover { background: var(--sand-100); }
.checkgrid input[type="checkbox"] {
  width: 20px; height: 20px; flex: none; margin: 0; accent-color: var(--green-600);
}
.checkgrid input[type="checkbox"]:checked + * ,
.checkgrid label:has(input:checked) { background: var(--green-50); border-color: var(--green-200); }

.errorlist { list-style: none; padding: 0; margin: 6px 0 0; color: var(--red-500); font-size: .83rem; }
.field-error input, .field-error select { border-color: var(--red-500); }

/* ------------------------------------------------------ counting screen -- */
.count-group { margin-bottom: 12px; }
.count-group summary {
  list-style: none; cursor: pointer; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; padding: 13px 16px;
  background: var(--white); border: 1px solid var(--sand-200); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); min-height: var(--tap);
}
.count-group summary::-webkit-details-marker { display: none; }
.count-group[open] summary { border-radius: var(--radius) var(--radius) 0 0; border-bottom-color: transparent; }
.count-group-title { font-weight: 650; font-size: .95rem; }
.count-group-meta { font-size: .8rem; color: var(--ink-500); font-variant-numeric: tabular-nums; }
.count-group-body {
  background: var(--white); border: 1px solid var(--sand-200); border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius); overflow: hidden;
}
.count-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-bottom: 1px solid var(--sand-100);
}
.count-row:last-child { border-bottom: 0; }
.count-row.is-counted { background: var(--green-50); }
.count-row.is-missing { background: var(--red-50); }

.count-name { flex: 1 1 auto; min-width: 0; }
.count-name strong {
  display: block; font-size: .94rem; font-weight: 600; line-height: 1.25;
  overflow-wrap: anywhere;
}
.count-unit { font-size: .76rem; color: var(--ink-500); }
.save-flag { margin-left: 6px; }

.stepper { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.step-btn {
  width: 40px; height: 46px; flex: 0 0 40px; padding: 0;
  border-radius: 11px; border: 1px solid var(--sand-300);
  background: var(--white); font-size: 1.3rem; font-weight: 600; color: var(--ink-700);
  cursor: pointer; display: grid; place-items: center; font-family: inherit;
  -webkit-appearance: none; appearance: none; line-height: 1;
}
.step-btn:active { background: var(--sand-100); }

/* The element+attribute selector on the generic input rule outranks a bare
   class, so these are written as input.qty-input to win on specificity. */
input.qty-input {
  width: 72px; flex: 0 0 72px; height: 46px; min-height: 46px;
  text-align: center; font-size: 1.1rem; font-weight: 650;
  font-variant-numeric: tabular-nums; border-radius: 11px; padding: 0 2px;
}
input.qty-input::placeholder { color: var(--ink-300); font-weight: 400; }
input.qty-input.counted { border-color: var(--green-400); background: var(--white); }

/* Hide the browser's tiny spinner arrows — the big +/- buttons replace them. */
input.qty-input::-webkit-outer-spin-button,
input.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.qty-input { -moz-appearance: textfield; appearance: textfield; }

/* Very narrow phones: keep the whole row on one line. */
@media (max-width: 360px) {
  .count-row { gap: 7px; padding: 10px 9px; }
  .step-btn { width: 36px; flex: 0 0 36px; }
  input.qty-input { width: 62px; flex: 0 0 62px; }
}

.progress-wrap {
  position: sticky; top: var(--header-h); z-index: 30;
  background: var(--sand-50); padding: 10px 0 12px; margin-bottom: 4px;
}
.progress-card {
  background: var(--white); border: 1px solid var(--sand-200); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.progress-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.progress-count { font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.progress-sub { font-size: .78rem; color: var(--ink-500); }
.progress-bar { height: 7px; border-radius: 4px; background: var(--sand-200); margin-top: 9px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--green-500); border-radius: 4px; transition: width .25s ease; }

.submit-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 46;
  background: var(--white); border-top: 1px solid var(--sand-200);
  padding: 10px 16px calc(10px + var(--safe-bottom));
  box-shadow: 0 -4px 16px rgba(28,33,30,.07);
}
.submit-dock .container { padding: 0; max-width: 620px; }

/* ------------------------------------------------------------- statuses -- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 650;
  border: 1px solid transparent;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill-green  { background: var(--green-50);  color: var(--green-700);  border-color: var(--green-200); }
.pill-orange { background: var(--orange-50); color: var(--orange-600); border-color: var(--orange-100); }
.pill-red    { background: var(--red-50);    color: var(--red-600);    border-color: var(--red-100); }
.pill-grey   { background: var(--sand-100);  color: var(--ink-500);    border-color: var(--sand-200); }
.pill-plain::before { display: none; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .76rem; color: var(--ink-500); font-weight: 550; }
.stat-red .stat-value { color: var(--red-500); }
.stat-orange .stat-value { color: var(--orange-600); }
.stat-green .stat-value { color: var(--green-600); }
.statrow { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-500); font-weight: 700; padding: 10px 12px;
  border-bottom: 1px solid var(--sand-200); white-space: nowrap; background: var(--sand-50);
}
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--sand-100); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--sand-50); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* -------------------------------------------------------------- misc ui -- */
.alert {
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  font-size: .9rem; border: 1px solid transparent; display: flex; gap: 10px; align-items: flex-start;
}
.alert-success { background: var(--green-50); border-color: var(--green-200); color: var(--green-700); }
.alert-error   { background: var(--red-50);  border-color: var(--red-100);  color: var(--red-600); }
.alert-warning { background: var(--orange-50); border-color: var(--orange-100); color: var(--orange-600); }
.alert-info    { background: var(--sand-100); border-color: var(--sand-200); color: var(--ink-700); }

.muted { color: var(--ink-500); }
.small { font-size: .82rem; }
.tiny  { font-size: .74rem; }
.strong { font-weight: 650; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; } .gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.center { text-align: center; }
.hidden { display: none !important; }

.page-head { margin-bottom: 16px; }
.page-head h1 { margin-bottom: 3px; }
.page-head .sub { color: var(--ink-500); font-size: .88rem; }
.back-link { display: inline-flex; align-items: center; gap: 5px; font-size: .85rem; color: var(--ink-500); margin-bottom: 10px; }

.segmented { display: inline-flex; background: var(--sand-100); border-radius: 12px; padding: 3px; gap: 3px; overflow-x: auto; max-width: 100%; }
.segmented a {
  padding: 8px 14px; border-radius: 9px; font-size: .86rem; font-weight: 600;
  color: var(--ink-700); white-space: nowrap; min-height: 38px; display: inline-flex; align-items: center;
}
.segmented a:hover { text-decoration: none; }
.segmented a.active { background: var(--white); color: var(--green-700); box-shadow: var(--shadow-sm); }

.empty { text-align: center; padding: 34px 18px; color: var(--ink-500); }
.empty svg { width: 36px; height: 36px; color: var(--ink-300); margin-bottom: 10px; }
.empty h3 { color: var(--ink-700); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; flex: 1 1 150px; }
.filters .field label { font-size: .74rem; }
.filters select, .filters input { min-height: 42px; }

.list-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--sand-100);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--sand-50); text-decoration: none; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: .94rem; }
.list-sub { font-size: .8rem; color: var(--ink-500); }

.chart { width: 100%; height: 190px; }
.chart-grid line { stroke: var(--sand-200); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--green-500); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--green-600); }
.chart-gap { stroke: var(--ink-300); stroke-dasharray: 3 3; stroke-width: 1.5; fill: none; }
.chart-label { font-size: 10px; fill: var(--ink-500); }

.toast-ok { color: var(--green-600); font-size: .76rem; font-weight: 600; }
.toast-err { color: var(--red-500); font-size: .76rem; font-weight: 600; }

.htmx-indicator { opacity: 0; transition: opacity .15s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* --------------------------------------------------------------- print -- */
@media print {
  .topbar, .tabbar, .submit-dock, .no-print, .btn-row, .filters { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; page-break-inside: avoid; }
  .main { padding: 0; }
  .container { max-width: 100%; padding: 0; }
  table.data th { background: #f3f3f3; }
  a { color: #000; text-decoration: none; }
  .print-header { display: block !important; margin-bottom: 14px; }
}
.print-header { display: none; }
