:root {
  --ink: #17231f;
  --muted: #61706a;
  --line: #dfe6e1;
  --paper: #ffffff;
  --canvas: #f4f7f4;
  --teal: #0f766e;
  --teal-dark: #075f58;
  --teal-pale: #dff4ef;
  --gold: #bd7616;
  --danger: #b42318;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(20, 43, 35, .07);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 16px/1.48 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { letter-spacing: -.025em; line-height: 1.16; }
h1 { margin-bottom: .42rem; font-size: clamp(1.85rem, 7vw, 2.7rem); }
h2 { margin-bottom: .4rem; font-size: 1.25rem; }
h3 { margin-bottom: .2rem; font-size: 1.08rem; }

.site-header { min-height: 66px; padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); position: sticky; z-index: 10; top: 0; backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; letter-spacing: -.035em; font-size: 1.18rem; white-space: nowrap; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; color: white; background: var(--teal); border-radius: 8px; font-size: 19px; line-height: 1; }
.header-actions { display: flex; align-items: center; gap: 4px; }
.page-shell { width: min(100%, 1120px); margin: 0 auto; padding: 27px 18px max(44px, env(safe-area-inset-bottom)); }
.page-intro { margin-bottom: 24px; }
.compact-intro { margin-top: 14px; }
.eyebrow { margin-bottom: 5px; color: var(--teal); font-size: .73rem; font-weight: 800; letter-spacing: .1em; line-height: 1.2; text-transform: uppercase; }
.subtle { color: var(--muted); margin-bottom: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.button { min-height: 44px; padding: 10px 15px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 10px; color: var(--ink); background: transparent; font-weight: 750; text-decoration: none; transition: background .18s, border-color .18s, transform .18s; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(15,118,110,.27); outline-offset: 2px; }
.button-primary { color: #fff; background: var(--teal); box-shadow: 0 3px 8px rgba(15,118,110,.18); }
.button-primary:hover { background: var(--teal-dark); }
.button-secondary { border-color: #bdd0c8; background: var(--paper); }
.button-secondary:hover, .button-quiet:hover { background: #eaf1ed; }
.button-quiet { color: #2d4b40; }
.button-compact { min-height: 40px; padding: 8px 11px; font-size: .9rem; }
.icon-button { width: 42px; padding: 0; font-size: 1.35rem; }
.button-block { width: 100%; }

.category-nav { margin: 2px -18px 22px; padding: 0 18px 12px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.category-nav::-webkit-scrollbar { display: none; }
.category-tab { min-height: 44px; padding: 10px 16px; display: inline-flex; align-items: center; border: 1px solid #bdd0c8; border-radius: 99px; background: var(--paper); color: #2d4b40; font-weight: 750; font-size: .92rem; text-decoration: none; white-space: nowrap; transition: background .18s, border-color .18s, color .18s; }
.category-tab:hover { background: #eaf1ed; }
.category-tab.active { color: #fff; background: var(--teal); border-color: var(--teal); }

.catalog-tools { position: sticky; z-index: 4; top: 65px; margin: 0 -18px 19px; padding: 10px 18px 13px; background: rgba(244,247,244,.93); border-bottom: 1px solid rgba(223,230,225,.8); backdrop-filter: blur(12px); }
.catalog-tools--fixed .filter-row { grid-template-columns: 1fr 1fr; }
.search-field { min-height: 48px; padding: 0 13px; display: flex; align-items: center; gap: 10px; border: 1px solid #b9cbc2; border-radius: 12px; background: var(--paper); color: var(--teal); }
.search-field input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
.filter-row { margin-top: 9px; display: grid; grid-template-columns: minmax(0, 1.45fr) 1fr 1fr; gap: 8px; }
.field-label { display: grid; gap: 6px; color: #42564d; font-size: .81rem; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 46px; padding: 10px 11px; border: 1px solid #bdcdc5; border-radius: 10px; color: var(--ink); background: #fff; box-shadow: inset 0 1px 1px rgba(14,31,24,.02); }
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #9ba8a2; opacity: 1; }

.status-message { min-height: 0; margin: 0 0 10px; color: var(--muted); font-size: .9rem; }
.product-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.product-card { min-height: 133px; display: grid; grid-template-columns: 106px minmax(0, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 2px 8px rgba(20,43,35,.035); text-decoration: none; transition: transform .17s, box-shadow .17s, border-color .17s; }
.product-card:hover { transform: translateY(-2px); border-color: #b6cfc5; box-shadow: var(--shadow); }
.product-photo, .product-photo-placeholder { width: 100%; height: 100%; min-height: 133px; object-fit: cover; background: #e3eeea; }
.product-photo-placeholder { display: grid; place-items: center; color: #6b9b8f; font-size: 2rem; }
.product-card-body { min-width: 0; padding: 14px 14px 12px; display: flex; flex-direction: column; }
.product-category { margin: 0 0 3px; overflow: hidden; color: var(--teal); font-size: .73rem; font-weight: 800; letter-spacing: .06em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.product-name { margin: 0 0 8px; overflow: hidden; font-size: 1.05rem; text-overflow: ellipsis; white-space: nowrap; }
.price-pair { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.price-label { display: block; margin-bottom: 1px; color: var(--muted); font-size: .69rem; font-weight: 750; }
.price-value { font-size: .93rem; font-weight: 800; }
.rate-value { color: var(--gold); }
.load-more-wrap { display: flex; justify-content: center; padding-top: 22px; }
.empty-state { max-width: 380px; margin: 50px auto 0; padding: 30px 20px; border: 1px dashed #b8c9c0; border-radius: var(--radius); color: var(--muted); text-align: center; }
.empty-state h2 { color: var(--ink); }
.empty-state p { margin-bottom: 20px; }
.empty-icon { width: 48px; height: 48px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 50%; color: var(--teal); background: var(--teal-pale); font-size: 1.6rem; }

.back-link { display: inline-block; margin-bottom: 18px; color: var(--teal-dark); font-size: .92rem; font-weight: 750; text-decoration: none; }
.form-page { max-width: 760px; }
.product-form { display: grid; gap: 14px; }
.form-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 2px 10px rgba(20,43,35,.035); }
.form-card h2 { margin-bottom: 4px; }
.form-hint { margin: 0 0 15px; color: var(--muted); font-size: .87rem; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.field-wide { grid-column: 1 / -1; }
.required { color: var(--danger); }
.image-picker { display: grid; grid-template-columns: 72px 1fr; align-items: center; column-gap: 14px; row-gap: 5px; }
.image-preview, .image-placeholder { width: 72px; height: 72px; grid-row: span 2; border-radius: 12px; object-fit: cover; }
.image-placeholder { display: grid; place-items: center; color: #6b9b8f; background: #e6efeb; font-size: 1.8rem; }
.image-picker .button { width: fit-content; }
.file-name { margin: 0; overflow: hidden; color: var(--muted); font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.purchase-details { padding: 0; overflow: hidden; }
.purchase-details summary { min-height: 67px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer; }
.purchase-details summary::-webkit-details-marker { display: none; }
.purchase-details summary span { display: grid; gap: 2px; }
.purchase-details summary small { color: var(--muted); font-size: .8rem; }
.purchase-details[open] summary { border-bottom: 1px solid var(--line); }
.details-content { padding: 18px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.form-error { margin: 0; padding: 11px 12px; border-radius: 10px; color: #8f2018; background: #fff0ee; font-size: .9rem; }

.detail-layout { display: grid; gap: 15px; }
.product-hero { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.product-hero-image, .product-hero-placeholder { width: 100%; height: 215px; object-fit: cover; background: #e1ece7; }
.product-hero-placeholder { display: grid; place-items: center; color: #6b9b8f; font-size: 3rem; }
.product-hero-body { padding: 19px; }
.product-hero-body h1 { font-size: 1.8rem; }
.product-unit { margin: 0 0 16px; color: var(--muted); }
.detail-prices { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.detail-price { padding: 12px; border-radius: 12px; background: #f0f5f2; }
.detail-price .price-value { font-size: 1.08rem; }
.detail-notes { margin: 16px 0 0; padding-top: 15px; border-top: 1px solid var(--line); color: #40544b; white-space: pre-wrap; }
.purchase-form-card { align-self: start; }
.purchase-form-card .form-grid { margin-top: 15px; }
.history-heading { margin: 6px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.history-heading h2 { margin: 0; }
.history-count { color: var(--muted); font-size: .85rem; font-weight: 700; }
.purchase-history { display: grid; gap: 10px; }
.purchase-card { padding: 15px; display: grid; gap: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); }
.purchase-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.purchase-date { margin: 0; font-weight: 800; }
.purchase-supplier { margin: 1px 0 0; color: var(--muted); font-size: .85rem; }
.purchase-rate { color: var(--gold); font-size: 1.08rem; font-weight: 850; white-space: nowrap; }
.purchase-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 4px 8px; border-radius: 99px; color: #426154; background: #edf4ef; font-size: .78rem; font-weight: 750; }
.purchase-note { margin: 0; color: #4c5e56; font-size: .9rem; white-space: pre-wrap; }
.history-empty { padding: 23px; border: 1px dashed #b8c9c0; border-radius: 14px; color: var(--muted); text-align: center; }

.login-page { min-height: 100vh; background: var(--teal); }
.login-layout { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
.login-intro { min-height: 280px; padding: max(28px, env(safe-area-inset-top)) 25px 32px; display: flex; flex-direction: column; justify-content: space-between; color: #e9fbf4; background: radial-gradient(circle at 90% 4%, #2aa392 0, transparent 33%), linear-gradient(155deg, #075b55 0%, #0d776e 100%); }
.brand-light { color: white; }
.brand-light .brand-mark { color: var(--teal); background: #e8faf4; }
.login-intro .eyebrow { color: #b4e7da; }
.login-intro h1 { max-width: 440px; margin: 0 0 10px; font-size: clamp(1.85rem, 9vw, 2.7rem); }
.login-intro p:not(.eyebrow) { max-width: 380px; margin: 0; color: #d3f1e7; }
.login-panel { display: grid; place-items: center; padding: 30px 18px max(35px, env(safe-area-inset-bottom)); background: var(--canvas); }
.login-panel-inner { width: min(100%, 390px); padding: 24px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.login-panel-inner h2 { font-size: 1.6rem; }
.login-panel-inner .subtle { margin-bottom: 23px; }
.stack-form { display: grid; gap: 15px; }

@media (min-width: 600px) {
  .site-header { padding-inline: 30px; }
  .page-shell { padding: 36px 30px 55px; }
  .category-nav { margin-inline: -30px; padding-inline: 30px; }
  .catalog-tools { margin-inline: -30px; padding-inline: 30px; }
  .filter-row { display: flex; }
  .filter-row .field-label:first-child { flex: 1.35; }
  .filter-row .field-label:not(:first-child) { width: 150px; }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .product-card { grid-template-columns: 118px minmax(0, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-layout { grid-template-columns: minmax(0, 1.25fr) minmax(290px, .75fr); align-items: start; }
  .history-section { grid-column: 1 / -1; }
  .product-hero { display: grid; grid-template-columns: minmax(190px, .68fr) 1fr; }
  .product-hero-image, .product-hero-placeholder { height: 100%; min-height: 245px; }
}

@media (min-width: 900px) {
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .product-card { grid-template-columns: 1fr; }
  .product-photo, .product-photo-placeholder { height: 154px; min-height: 154px; }
  .product-card-body { min-height: 127px; }
  .login-layout { grid-template-columns: minmax(360px, 1fr) minmax(430px, .9fr); }
  .login-intro { min-height: 100vh; padding: 42px clamp(38px, 8vw, 120px); }
  .login-panel { padding: 40px; }
  .login-panel-inner { padding: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
