:root {
  --background: #f4f6f8;
  --surface: #ffffff;
  --text: #18212b;
  --muted: #66717e;
  --border: #d9dfe6;
  --primary: #165d50;
  --primary-dark: #10483e;
  --danger: #b42318;
  --danger-dark: #8f1c13;
  --warning: #a15c00;
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--background); }
a { color: var(--primary); }
h1, h2 { line-height: 1.2; }
h1 { margin: 0 0 .4rem; font-size: clamp(1.7rem, 4vw, 2.25rem); }
h2 { font-size: 1.2rem; }

.site-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .75rem max(1rem, calc((100vw - 1180px) / 2));
  background: #123b35;
  color: white;
}
.site-header a { color: white; text-decoration: none; }
.brand { font-size: 1.25rem; font-weight: 750; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 1rem; }
.account { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.account form { margin: 0; }

.container { width: min(1180px, calc(100% - 2rem)); margin: 2rem auto 4rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; }
.muted, .help-text { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: .75rem; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: .6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: #edf1f3; }
.button.primary { color: white; border-color: var(--primary); background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.danger { color: white; border-color: var(--danger); background: var(--danger); }
.button.danger:hover { background: var(--danger-dark); }
.button.secondary { background: transparent; }
.link-button { border: 0; padding: 0; background: transparent; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.button-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.inline-action-form { margin: 0; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.summary-card { display: flex; flex-direction: column; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.summary-card strong { font-size: 1.7rem; }
.summary-card.warning strong { color: var(--warning); }

.filter-bar { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filter-bar .grow { flex: 1 1 280px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: .35rem; }
.field label { font-weight: 650; }
input, select { min-height: 42px; padding: .55rem .65rem; border: 1px solid #abb5c0; border-radius: 7px; background: white; color: var(--text); font: inherit; }
input[type="checkbox"] { min-height: auto; align-self: flex-start; }
input[type="file"] {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: auto;
  overflow: hidden;
  padding: .7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-error label { color: var(--danger); }
.field-error input, .field-error select { border: 2px solid var(--danger); }
.error-text, .form-errors { color: var(--danger); }
.help-text, .error-text { font-size: .9rem; }
.error-text { font-weight: 650; }
.validation-summary { display: flex; flex-direction: column; gap: .25rem; padding: .85rem 1rem; border: 1px solid #efb3ad; border-radius: 8px; background: #fee4e2; color: var(--danger-dark); }

.table-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: 1rem 0 .5rem; }
.table-result-count { color: var(--muted); font-size: .9rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: .8rem .9rem; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #edf1f3; font-size: .88rem; }
tbody tr:last-child td { border-bottom: 0; }

.filterable-table { table-layout: fixed; white-space: normal; }
.filterable-table .column-product { width: 14%; }
.filterable-table .column-category { width: 10%; }
.filterable-table .column-seller { width: 24%; }
.filterable-table .column-purchase-date { width: 12%; }
.filterable-table .column-total { width: 8%; }
.filterable-table .column-expiry-date { width: 12%; }
.filterable-table .column-status { width: 11%; }
.filterable-table .column-creator { width: 9%; }
.filterable-table th { padding: .35rem .3rem .35rem .5rem; }
.filterable-table td { padding: .7rem .65rem; overflow-wrap: anywhere; vertical-align: top; }
.filterable-table td:nth-child(4),
.filterable-table td:nth-child(5),
.filterable-table td:nth-child(6) { white-space: nowrap; }
.table-column-heading { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: .1rem; }
.table-sort-button, .table-filter-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.table-sort-button { display: flex; min-width: 0; flex: 1; align-items: center; gap: .2rem; padding: .35rem .2rem; line-height: 1.2; overflow-wrap: anywhere; text-align: left; white-space: normal; }
.table-sort-button:hover, .table-filter-button:hover { background: #dfe6ea; }
.table-sort-button:focus-visible, .table-filter-button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.sort-indicator { display: inline-block; min-width: .85rem; color: var(--primary); font-size: .8rem; }
th[aria-sort="ascending"] .sort-indicator::before { content: "▲"; }
th[aria-sort="descending"] .sort-indicator::before { content: "▼"; }
.table-filter-button { display: grid; width: 34px; flex: 0 0 34px; place-items: center; padding: 0; }
.filter-icon { position: relative; width: 14px; height: 12px; }
.filter-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 62% 46%, 62% 100%, 38% 82%, 38% 46%);
}
.table-filter-button.is-active { background: var(--primary); color: white; }
.table-filter-button.is-active:hover { background: var(--primary-dark); }

.table-filter-menu {
  position: fixed;
  z-index: 1000;
  width: min(330px, calc(100vw - 16px));
  overflow: hidden;
  border: 1px solid #aeb8c2;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 14px 35px rgb(24 33 43 / 22%);
  color: var(--text);
  white-space: normal;
}
.table-filter-menu[hidden] { display: none; }
.table-filter-menu-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .8rem .9rem .55rem; }
.table-filter-menu-header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-filter-close { border: 0; padding: .2rem .35rem; background: transparent; color: var(--muted); font: inherit; font-size: 1.2rem; cursor: pointer; }
.table-filter-search { width: calc(100% - 1.8rem); min-height: 38px; margin: 0 .9rem .6rem; }
.table-filter-quick-actions { display: flex; gap: .45rem; padding: 0 .9rem .6rem; }
.table-filter-quick-actions button { border: 0; padding: .15rem 0; background: transparent; color: var(--primary); font: inherit; font-size: .85rem; text-decoration: underline; cursor: pointer; }
.table-filter-options { max-height: min(320px, 45vh); overflow-y: auto; border-top: 1px solid var(--border); }
.table-filter-option { display: flex; align-items: flex-start; gap: .55rem; padding: .55rem .9rem; cursor: pointer; }
.table-filter-option:hover { background: #f1f5f6; }
.table-filter-option input { flex: 0 0 auto; margin-top: .2rem; }
.table-filter-option-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.table-filter-option-count { color: var(--muted); font-size: .82rem; }
.table-filter-no-values { padding: 1rem; color: var(--muted); text-align: center; }

.status { display: inline-block; padding: .25rem .55rem; border-radius: 999px; background: #e8eef0; font-size: .85rem; font-weight: 650; }
.status-active { background: #d8f3e8; color: #12634d; }
.status-pending_deletion { background: #fff0d5; color: #7a4300; }
.status-archived { background: #e7e9ec; color: #4d5661; }

.form-card, .auth-card, .confirm-card, .document-card, .danger-zone { padding: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stacked-form { display: grid; gap: 1rem; }
.form-card { max-width: 760px; }
.auth-card, .confirm-card { max-width: 480px; margin: 4rem auto; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; overflow: hidden; padding: 1px; background: var(--border); border-radius: var(--radius); }
.detail-grid div { padding: 1rem; background: var(--surface); }
.detail-grid dt { color: var(--muted); font-size: .85rem; }
.detail-grid dd { margin: .3rem 0 0; font-weight: 650; }
.document-card, .danger-zone { margin-top: 1.25rem; }
.danger-zone { border-color: #efb3ad; }

.two-column { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 1.5rem; align-items: start; }
.category-list, .notification-list { margin: 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.category-list li, .notification-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
.category-list li:last-child, .notification-list li:last-child { border-bottom: 0; }
.notification-list li { flex-direction: column; }
.notification-list li.unread { border-left: 4px solid var(--primary); background: #f1faf7; }
.notification-list time { color: var(--muted); font-size: .85rem; }
.empty-state { padding: 2rem; color: var(--muted); text-align: center; }
.messages { display: grid; gap: .5rem; margin-bottom: 1rem; }
.message { padding: .8rem 1rem; background: #e8eef0; border-radius: 8px; }
.message-success { background: #d8f3e8; }
.message-error { background: #fee4e2; }
.message-warning { background: #fff0d5; }

.scan-card { max-width: 680px; padding: 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.scan-card h2 { margin-top: .5rem; }
.scan-icon { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 12px; background: #d8f3e8; color: var(--primary); font-size: 1.8rem; }
.ocr-status { display: flex; flex-direction: column; gap: .25rem; max-width: 760px; margin-bottom: 1rem; padding: .85rem 1rem; border-radius: 8px; }
.ocr-status.success { background: #d8f3e8; color: #12634d; }
.ocr-status.warning { background: #fff0d5; color: #7a4300; }
.cancel-draft-form { margin-top: 1rem; }
.ocr-raw-text { max-width: 760px; margin-top: 1.25rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ocr-raw-text summary { cursor: pointer; font-weight: 650; }
.ocr-raw-text pre { max-height: 320px; overflow: auto; white-space: pre-wrap; }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-wrap: wrap; gap: .75rem 1rem; }
  .site-header nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: .25rem; }
  .account { margin-left: auto; }
  .container { margin-top: 1.25rem; }
  .page-heading { flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr; }
  .detail-grid, .two-column { grid-template-columns: 1fr; }
  .filter-bar > * { width: 100%; }
  .table-actions { align-items: flex-start; flex-direction: column; }
}
