:root {
  --background: #f6f8f7;
  --background-strong: #edf2ef;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --text: #1e2930;
  --muted: #5f6b75;
  --muted-strong: #43515b;
  --border: #d8dee3;
  --border-strong: #c4ccd3;
  --primary: #216a73;
  --primary-dark: #174d54;
  --primary-soft: #e7f2f3;
  --accent: #b95f36;
  --accent-soft: #f8ece6;
  --warning: #9a6300;
  --warning-soft: #fff0c2;
  --info: #285f8f;
  --info-soft: #e6f1fb;
  --danger: #a33b3b;
  --danger-soft: #fbe8e8;
  --success: #2f6b4f;
  --success-soft: #e7f3ec;
  --shadow: 0 14px 34px rgba(30, 41, 48, 0.1);
  --shadow-soft: 0 4px 14px rgba(30, 41, 48, 0.07);
  --radius: 8px;
  --space-xs: 6px;
  --space-sm: 10px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --content-width: 1240px;
  --compact-control-height: 46px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, var(--background-strong) 0, var(--background) 280px);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 17px;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: var(--primary-dark);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--primary);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  padding: 14px clamp(16px, 4vw, 56px);
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  width: min(var(--content-width), 100%);
  margin: 0 auto;
}

.app-title-group {
  min-width: 280px;
}

.app-label {
  margin: 0;
  color: var(--muted-strong);
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.2;
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: var(--space-md);
  font-size: 1.5rem;
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  margin-bottom: var(--space-sm);
  font-size: 1.15rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  flex: 1 1 auto;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  max-width: none;
}

.main-nav a,
.logout-form button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.main-nav a:hover,
.logout-form button:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.main-nav a[aria-current="page"] {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.logout-form {
  display: flex;
  max-width: none;
  margin: 0;
}

.logout-form button {
  color: var(--muted-strong);
}

.page {
  display: grid;
  gap: var(--space-lg);
  width: min(var(--content-width), calc(100% - 32px));
  margin: var(--space-xl) auto 56px;
}

.toast-stack {
  position: fixed;
  z-index: 1000;
  top: var(--space-lg);
  right: var(--space-lg);
  display: grid;
  width: min(420px, calc(100vw - 32px));
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-sm);
  align-items: start;
  padding: var(--space-md);
  border: 1px solid var(--border-strong);
  border-left-width: 6px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: auto;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast-removing {
  opacity: 0;
  transform: translateX(12px);
}

.toast-title {
  margin-bottom: 2px;
  font-weight: 800;
}

.toast-detail {
  margin-bottom: 0;
  color: var(--muted-strong);
  font-size: 0.95rem;
}

.toast-close {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-strong);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}

.toast-close:hover {
  border-color: var(--border);
  background: var(--surface-muted);
  color: var(--text);
}

.toast-success {
  border-color: var(--success);
  background: var(--success-soft);
}

.toast-error {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.toast-warning {
  border-color: var(--warning);
  background: var(--warning-soft);
}

.toast-info {
  border-color: var(--info);
  background: var(--info-soft);
}

.action-panel,
.summary-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.action-panel {
  padding: clamp(20px, 4vw, 32px);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
  align-items: stretch;
}

.common-actions-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-sm);
}

.action-grid form {
  display: flex;
  margin: 0;
}

.action-button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: 100%;
  padding: 13px 18px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  white-space: normal;
  overflow-wrap: anywhere;
}

.action-grid .action-button,
.auth-panel .action-button {
  width: 100%;
}

.common-actions-grid .action-button {
  min-height: 58px;
  padding: 10px 12px;
  font-size: 1rem;
  white-space: nowrap;
  overflow-wrap: normal;
}

.action-button:hover {
  background: var(--primary-soft);
}

.action-button-primary {
  background: var(--primary);
  color: var(--surface);
}

.action-button-primary:hover {
  background: var(--primary-dark);
  color: var(--surface);
}

.action-button:focus-visible,
.compact-action-button:focus-visible,
.icon-action-button:focus-visible,
.action-menu-item:focus-visible,
.main-nav a:focus-visible,
.logout-form button:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-lg);
}

.summary-panel {
  min-height: 160px;
  overflow-x: auto;
  padding: var(--space-lg);
}

.entry-panel {
  justify-self: center;
  width: fit-content;
  max-width: 100%;
}

.summary-panel > :last-child,
.action-panel > :last-child {
  margin-bottom: 0;
}

.page-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.page-panel-header h2 {
  margin-bottom: 0;
}

.page-panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin: 0;
}

.page-panel-header .action-button {
  min-width: 180px;
}

.invoice-preview-panel {
  max-width: 1040px;
  margin-inline: auto;
  overflow-x: hidden;
}

.invoice-preview-panel .page-panel-header {
  align-items: center;
}

.invoice-preview-panel .page-panel-header p {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-bottom: 0;
}

.invoice-preview-frame {
  width: 100%;
  height: min(86vh, 980px);
  min-height: 720px;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.confirmation-panel .invoice-preview-frame {
  height: min(76vh, 860px);
  min-height: 640px;
}

.detail-header {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  margin-bottom: var(--space-xs);
}

.summary-panel .detail-header p {
  margin-bottom: 0;
  color: var(--muted-strong);
  font-weight: 700;
}

.detail-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
  justify-content: flex-end;
}

.compact-action-button,
.icon-action-button {
  height: var(--compact-control-height);
  min-height: var(--compact-control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.compact-action-button {
  padding: 0 13px;
  gap: 8px;
  font-size: 1rem;
}

.compact-action-button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--surface);
}

.compact-action-button span {
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.icon-action-button {
  width: var(--compact-control-height);
  min-width: var(--compact-control-height);
  padding: 0;
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1;
}

.compact-action-button:hover,
.icon-action-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.compact-action-button-primary:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
  color: var(--surface);
}

.status-pill {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill-active {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.status-pill-inactive {
  border-color: var(--muted);
  background: var(--surface-muted);
  color: var(--muted-strong);
}

.status-pill-warning {
  border-color: var(--warning);
  background: var(--warning-soft);
  color: var(--warning);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.detail-item {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.detail-item-wide {
  grid-column: 1 / -1;
}

.detail-item span {
  color: var(--muted-strong);
  font-size: 0.92rem;
  font-weight: 800;
}

.detail-item strong {
  color: var(--text);
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

.status-text-active,
.detail-item .detail-status-active {
  color: var(--success);
}

.status-text-inactive,
.detail-item .detail-status-inactive {
  color: var(--danger);
}

.recipe-status-incomplete,
.detail-item .recipe-status-incomplete {
  color: var(--danger);
  font-weight: 800;
}

.recipe-completion-warning {
  display: grid;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
  padding: var(--space-md);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
}

.recipe-completion-warning > strong {
  font-size: 1.05rem;
}

.recipe-completion-warning ul {
  display: grid;
  gap: var(--space-sm);
  margin: 0;
  padding: 0;
  list-style: none;
}

.recipe-completion-warning li {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) var(--space-md);
  align-items: center;
  justify-content: space-between;
}

.recipe-completion-action {
  color: var(--primary-dark);
  font-weight: 800;
  white-space: nowrap;
}

.status-text {
  font-weight: 800;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-md);
  align-items: stretch;
}

.detail-actions {
  margin-bottom: var(--space-md);
}

.detail-actions .action-button {
  width: 100%;
}

.confirmation-panel {
  display: grid;
  gap: var(--space-lg);
}

.confirmation-header {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.confirmation-header h2 {
  margin-bottom: 0;
}

.confirmation-name {
  display: grid;
  gap: 4px;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.confirmation-name span {
  color: var(--muted-strong);
  font-size: 0.92rem;
  font-weight: 800;
}

.confirmation-name strong {
  color: var(--text);
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

.preview-block {
  display: grid;
  gap: var(--space-sm);
}

.preview-block h3 {
  margin-bottom: 0;
}

.preview-table {
  table-layout: fixed;
}

.preview-stock-status {
  font-weight: 800;
  white-space: nowrap;
}

.preview-stock-status-ok {
  color: var(--success);
}

.preview-stock-status-low {
  color: var(--danger);
}

.confirmation-form {
  max-width: none;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

.confirmation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: stretch;
  justify-content: flex-end;
  margin-bottom: 0;
}

.confirmation-actions .action-button {
  min-width: min(240px, 100%);
}

.summary-panel p {
  margin-bottom: var(--space-md);
  color: var(--muted);
}

.summary-panel p:last-child {
  margin-bottom: 0;
}

#ingredients,
#packaging,
#products {
  border-top: 6px solid var(--warning-soft);
}

#history {
  grid-column: 1 / -1;
}

form {
  display: grid;
  gap: var(--space-md);
  max-width: 760px;
}

form p,
form label {
  margin-bottom: 0;
}

form > p {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  align-items: end;
}

form > p > label {
  min-width: min(220px, 100%);
}

form > p > a {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

form > p br {
  display: none;
}

[hidden] {
  display: none !important;
}

.entry-form {
  width: fit-content;
  max-width: none;
}

.entry-panel:has(.sale-entry-form),
.entry-panel:has(.sample-entry-form) {
  width: min(68rem, 100%);
}

.sale-entry-form,
.sample-entry-form {
  width: 100%;
}

.entry-section {
  width: fit-content;
  max-width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.sale-entry-form .entry-section {
  width: 100%;
}

.entry-section summary {
  cursor: pointer;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.25;
}

.entry-section summary::marker {
  color: var(--primary);
}

.entry-section summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.entry-section-body {
  display: grid;
  gap: var(--space-md);
  padding-top: var(--space-md);
}

.entry-section-body > h3:first-child {
  margin-top: 0;
}

.entry-field-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  align-items: end;
  margin-bottom: 0;
}

.entry-field-row > label {
  min-width: min(220px, 100%);
}

.entry-title-field {
  max-width: 560px;
}

.entry-note {
  display: grid;
  gap: var(--space-sm);
  max-width: 560px;
}

.entry-note-toggle {
  justify-self: start;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}

.entry-note-toggle:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.entry-note-area {
  display: grid;
  gap: var(--space-xs);
}

.entry-note-area textarea {
  min-height: 120px;
  resize: none;
}

.entry-form h3 {
  margin: var(--space-sm) 0 0;
}

.entry-form .line-list {
  max-width: none;
}

.entry-form .line-row {
  grid-template-columns: minmax(260px, 48rem) minmax(9.5rem, 12rem) auto;
  justify-content: start;
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}

.production-entry-form .line-row {
  grid-template-columns:
    minmax(260px, 48rem)
    minmax(9.5rem, 12rem)
    minmax(96px, max-content);
}

.sale-entry-form .line-row,
.sample-entry-form .line-row {
  grid-template-columns:
    minmax(260px, 48rem)
    minmax(9.5rem, 12rem)
    auto;
}

.sale-entry-form .line-row.line-row-no-custom-logo {
  grid-template-columns: minmax(260px, 48rem) minmax(9.5rem, 12rem) auto;
}

.sale-entry-form .line-row:not(.line-row-no-custom-logo) {
  grid-template-columns:
    minmax(260px, 48rem)
    minmax(9.5rem, 12rem)
    minmax(10rem, 12rem)
    auto;
}

.sale-entry-form button[data-remove-line],
.sample-entry-form button[data-remove-line] {
  height: 46px;
  min-height: 46px;
  align-self: end;
  padding-top: 10px;
  padding-bottom: 10px;
}

.sale-entry-form .line-row > .product-stock-summary,
.sample-entry-form .line-row > .product-stock-summary {
  grid-column: 1 / span 3;
}

.sale-entry-form .line-row.line-row-no-custom-logo > .product-stock-summary,
.sample-entry-form .line-row > .product-stock-summary {
  grid-column: 1 / span 2;
}

.entry-add-actions {
  margin-bottom: 0;
}

.entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: stretch;
  justify-content: flex-end;
  margin-bottom: 0;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

.entry-actions .action-button {
  min-width: min(220px, 100%);
}

.summary-panel > form[method="get"] {
  max-width: none;
  margin-bottom: var(--space-lg);
}

.summary-panel > form[method="get"] input,
.summary-panel > form[method="get"] select {
  width: min(260px, 100%);
}

.filter-bar {
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.filter-bar > p {
  margin-bottom: 0;
}

.filter-stack {
  display: grid;
  gap: var(--space-md);
}

.filter-field {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  min-width: min(240px, 100%);
}

.filter-field > label {
  flex: 0 0 140px;
  white-space: nowrap;
}

.filter-field > input,
.filter-field > select {
  flex: 1 1 auto;
  min-width: 0;
}

.summary-panel > form.filter-bar .filter-field-search input {
  width: 100%;
  max-width: none;
}

.filter-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  align-items: end;
}

.filter-actions-row .filter-field {
  flex: 0 1 390px;
  gap: var(--space-sm);
}

.filter-actions-row .filter-field > label {
  flex: 0 0 auto;
}

.filter-actions-row .filter-field-search {
  flex: 1 1 520px;
}

.filter-actions-row .filter-field-stock {
  flex: 0 1 340px;
}

.filter-actions-row .filter-field-category {
  flex: 0 1 320px;
}

.filter-actions-row a {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
}

.filter-actions-row a[data-live-filter-clear] {
  min-width: 110px;
  justify-content: center;
  white-space: nowrap;
}

.filter-bar button:not(.action-button) {
  min-height: 46px;
  min-width: 130px;
}

.live-filter-results {
  width: 100%;
}

.live-filter-results[aria-busy="true"] {
  cursor: progress;
  opacity: 0.65;
}

label {
  display: grid;
  gap: var(--space-xs);
  color: var(--muted-strong);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  max-width: 560px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

label input,
label select,
label textarea {
  max-width: none;
}

.searchable-combobox {
  position: relative;
  width: 100%;
  min-width: 0;
}

.searchable-combobox-input {
  width: 100%;
  max-width: none;
  height: var(--compact-control-height);
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted-strong) 50%),
    linear-gradient(135deg, var(--muted-strong) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

.searchable-combobox-listbox {
  position: absolute;
  z-index: 70;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.searchable-combobox-option,
.searchable-combobox-empty {
  padding: 10px 12px;
  border-radius: var(--radius);
}

.searchable-combobox-option {
  color: var(--text);
  cursor: pointer;
}

.searchable-combobox-option:hover,
.searchable-combobox-option.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.searchable-combobox-option.is-selected {
  font-weight: 800;
}

.searchable-combobox-empty {
  color: var(--muted-strong);
}

.searchable-select-native {
  display: none;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

select {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  height: var(--compact-control-height);
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted-strong) 50%),
    linear-gradient(135deg, var(--muted-strong) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

@media (forced-colors: active) {
  select {
    -webkit-appearance: auto;
    appearance: auto;
    padding-right: 12px;
    background-image: none;
  }

  .searchable-combobox-input {
    padding-right: 12px;
    background-image: none;
  }

  .searchable-combobox-option.is-active {
    outline: 2px solid CanvasText;
  }
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--muted);
}

button {
  max-width: 100%;
  border-radius: var(--radius);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.summary-panel button:not(.action-button),
.action-panel button:not(.action-button) {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.summary-panel button:not(.action-button):hover,
.action-panel button:not(.action-button):hover {
  background: var(--surface-muted);
}

.summary-panel form.filter-bar button:not(.action-button) {
  min-height: var(--compact-control-height);
  min-width: 130px;
}

.summary-panel .icon-action-button {
  height: var(--compact-control-height);
  min-height: var(--compact-control-height);
  width: var(--compact-control-height);
  min-width: var(--compact-control-height);
  padding: 0;
  border-color: var(--border-strong);
  color: var(--primary-dark);
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
}

.summary-panel .icon-action-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.action-menu {
  position: relative;
  display: inline-flex;
}

.action-menu-panel {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 900;
  display: grid;
  min-width: 230px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: var(--space-xs);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.action-menu-panel[hidden] {
  display: none;
}

.action-menu form {
  display: block;
  max-width: none;
  margin: 0;
}

.summary-panel .action-menu .action-menu-item {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}

.summary-panel .action-menu .action-menu-item:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.summary-panel .action-menu .action-menu-item-danger {
  color: var(--danger);
}

.summary-panel .action-menu .action-menu-item-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.destructive-action-form button,
.status-action-form button {
  width: 100%;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  align-items: center;
  min-width: 220px;
}

.row-actions form {
  display: flex;
  max-width: none;
  margin: 0;
}

.row-actions a,
.row-actions button {
  height: var(--compact-control-height);
  min-height: var(--compact-control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.row-actions a:hover,
.row-actions button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.row-actions .destructive-action-form button {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.row-actions .destructive-action-form button:hover {
  background: var(--surface);
}

.stock-adjustment-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: var(--space-lg);
  background: rgba(30, 41, 48, 0.45);
}

.stock-adjustment-modal[hidden] {
  display: none;
}

.stock-adjustment-dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - (2 * var(--space-lg)));
  overflow-y: auto;
  white-space: normal;
  padding: var(--space-lg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stock-adjustment-header {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

.stock-adjustment-header h2 {
  margin: 0;
}

.stock-adjustment-close {
  min-width: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
}

.stock-adjustment-close:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.stock-adjustment-current {
  margin: 0 0 var(--space-lg);
  color: var(--muted-strong);
  font-weight: 800;
}

.stock-adjustment-form {
  display: grid;
  gap: var(--space-md);
  max-width: none;
}

.stock-adjustment-form label {
  display: grid;
  gap: var(--space-xs);
  font-weight: 800;
}

.stock-adjustment-form input,
.stock-adjustment-form textarea {
  width: 100%;
}

.stock-adjustment-form textarea {
  min-height: 120px;
  resize: none;
}

.stock-adjustment-note-toggle {
  justify-self: start;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}

.stock-adjustment-note-toggle:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.stock-adjustment-note-area {
  display: grid;
  gap: var(--space-xs);
}

.stock-adjustment-note-area[hidden] {
  display: none;
}

.field-hint {
  margin: 0;
  color: var(--muted-strong);
  font-size: 0.9rem;
  font-weight: 700;
}

.stock-adjustment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-sm);
}

.stock-adjustment-actions .action-button {
  min-width: 120px;
}

.stock-adjustment-actions .action-button-primary {
  min-width: 170px;
}

.create-item-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: var(--space-lg);
  background: rgba(30, 41, 48, 0.45);
}

.create-item-modal[hidden] {
  display: none;
}

.create-item-dialog {
  width: min(620px, 100%);
  max-height: calc(100vh - (2 * var(--space-lg)));
  overflow-y: auto;
  padding: var(--space-lg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.create-product-dialog {
  width: min(820px, 100%);
}

.create-item-header {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.create-item-header h2 {
  margin: 0;
}

.create-item-close {
  min-width: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
}

.create-item-close:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.create-item-form {
  display: grid;
  gap: var(--space-md);
  max-width: none;
}

.create-product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-md);
}

.create-item-form label {
  display: grid;
  gap: var(--space-xs);
  font-weight: 800;
}

.create-item-form input,
.create-item-form select,
.create-item-form textarea {
  width: 100%;
}

.create-item-form textarea {
  min-height: 120px;
  resize: none;
}

.create-item-note-toggle {
  justify-self: start;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}

.create-item-note-toggle:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.create-item-note-area {
  display: grid;
  gap: var(--space-xs);
}

.create-item-note-area[hidden] {
  display: none;
}

.create-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-sm);
}

.create-item-actions .action-button {
  min-width: 120px;
}

.create-item-actions .action-button-primary {
  min-width: 170px;
}

@media (max-width: 760px) {
  .create-product-grid {
    grid-template-columns: 1fr;
  }
}

div[role="alert"] {
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
}

div[role="alert"].alert-warning {
  border-color: var(--warning);
  background: var(--warning-soft);
  color: var(--warning);
}

div[role="alert"] p,
div[role="alert"] ul {
  margin: 0;
  color: inherit;
}

div[role="alert"] p + p,
div[role="alert"] p + ul,
div[role="alert"] ul + p,
div[role="alert"] ul + ul {
  margin-top: var(--space-sm);
}

div[role="alert"] ul {
  display: grid;
  gap: var(--space-xs);
  padding-left: 0;
  list-style: none;
}

div[role="alert"] li {
  margin: 0;
}

div[role="alert"] :last-child {
  margin-bottom: 0;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table:not(:has(thead)) {
  min-width: 0;
}

.requirements-table {
  table-layout: fixed;
}

.requirements-panel-header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.requirements-panel-header h2 {
  margin: 0;
}

.requirements-panel-header .compact-action-button {
  margin-left: auto;
}

.requirements-table th:nth-child(1),
.requirements-table td:nth-child(1) {
  width: 38%;
}

.requirements-table th:nth-child(2),
.requirements-table td:nth-child(2) {
  width: 24%;
}

.requirements-table th:nth-child(3),
.requirements-table td:nth-child(3) {
  width: 38%;
}

.products-table .products-can-make-cell {
  min-width: 150px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.products-table .products-name-cell {
  width: 15rem;
  max-width: 15rem;
  overflow-wrap: anywhere;
  word-break: normal;
}

.products-table .products-status-cell {
  white-space: nowrap;
  overflow-wrap: normal;
}

.products-table .products-actions-cell {
  width: 1%;
  min-width: 140px;
  white-space: nowrap;
}

.products-table .products-actions-cell .row-actions {
  min-width: 0;
  flex-wrap: nowrap;
}

.stock-status-cell {
  min-width: 130px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.production-list-table .overview-recorded-cell,
.sales-list-table .overview-recorded-cell {
  width: 132px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.sales-list-table .sales-sold-cell {
  width: 118px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.sales-list-table .sales-payment-status-cell {
  width: 132px;
  min-width: 132px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.payment-status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 66px;
  padding: 5px 9px;
  border: 1px solid currentColor;
  border-radius: 6px;
  font-weight: 800;
  line-height: 1.2;
}

.payment-status-paid {
  background: var(--success-soft);
  color: var(--success);
}

.payment-status-open {
  background: var(--warning-soft);
  color: var(--warning);
}

.production-list-table .overview-note-preview-cell {
  width: 24%;
  max-width: 280px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.sales-list-table .sales-note-preview-cell {
  width: 170px;
  max-width: 170px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

tbody th,
tbody td {
  vertical-align: middle;
}

thead th {
  background: var(--surface-muted);
  color: var(--muted-strong);
  font-size: 0.9rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.change-text {
  font-weight: 800;
}

.change-text-increase {
  color: var(--success);
}

.change-text-decrease {
  color: var(--danger);
}

.change-text-unknown {
  color: var(--muted-strong);
}

.history-table {
  table-layout: fixed;
  min-width: 1080px;
}

.history-table .history-when-cell {
  width: 190px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.history-table .history-type-cell {
  width: 130px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.history-table .history-source-cell {
  width: 180px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.history-table .history-change-cell {
  width: 120px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.history-table .history-note-cell {
  width: 260px;
  max-width: 260px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.history-table .history-item-cell {
  overflow-wrap: anywhere;
}

.history-note-preview {
  overflow-wrap: anywhere;
}

.history-note-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: var(--space-xs);
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
}

.history-note-more:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.history-note-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: var(--space-lg);
  background: rgba(30, 41, 48, 0.45);
}

.history-note-modal[hidden] {
  display: none;
}

.history-note-dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - (2 * var(--space-lg)));
  overflow-y: auto;
  padding: var(--space-lg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.history-note-header {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.history-note-header h2 {
  margin: 0;
}

.history-note-close {
  min-width: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
}

.history-note-close:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.history-note-full {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-note-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-lg);
}

.stock-status {
  font-weight: 800;
}

.stock-status-ok,
.detail-item .stock-status-ok {
  color: var(--success);
}

.stock-status-low,
.detail-item .stock-status-low {
  color: var(--warning);
}

tbody tr:nth-child(even) {
  background: var(--surface-muted);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

td form,
td .logout-form {
  display: inline-grid;
  margin: var(--space-xs) var(--space-xs) 0 0;
}

td a {
  display: inline-block;
  margin: var(--space-xs) var(--space-sm) var(--space-xs) 0;
}

td:last-child {
  min-width: 180px;
}

.line-list {
  display: grid;
  gap: var(--space-md);
  max-width: 920px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(240px, 36rem) minmax(10rem, 14rem) auto;
  gap: var(--space-md);
  align-items: end;
  justify-content: start;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.line-row .production-requirement-hint {
  grid-column: 1 / span 2;
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  border-left: 4px solid var(--info);
  border-radius: var(--radius);
  background: var(--info-soft);
  color: var(--muted-strong);
}

.line-row .production-requirement-hint p {
  margin: 0;
}

.line-row .production-requirement-hint.line-hint-warning {
  border-left-color: var(--warning);
  background: var(--warning-soft);
  color: var(--warning);
}

.line-row > .product-stock-summary {
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  border-left: 4px solid var(--info);
  border-radius: var(--radius);
  background: var(--info-soft);
  color: var(--muted-strong);
}

.production-requirement-title {
  font-weight: 700;
}

.production-requirement-group {
  margin-top: var(--space-sm);
}

.production-requirement-group h4 {
  margin: 0 0 4px;
  color: inherit;
  font-size: 1rem;
}

.production-requirement-group ul {
  margin: 0;
  padding-left: 1.5rem;
}

.line-row button {
  min-width: 96px;
}

.auth-panel {
  width: min(520px, 100%);
  margin: 0 auto;
}

.auth-panel form {
  max-width: none;
}

@media (max-width: 980px) {
  .action-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .line-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .entry-form .line-row {
    grid-template-columns: 1fr;
    justify-self: stretch;
    width: auto;
  }

  .sale-entry-form .line-row,
  .sample-entry-form .line-row {
    grid-template-columns: 1fr;
  }

  .production-entry-form .line-row {
    grid-template-columns: 1fr;
  }

  .line-row .production-requirement-hint {
    grid-column: 1;
  }

  .entry-panel,
  .entry-form {
    justify-self: stretch;
    width: auto;
  }

  .entry-panel:has(.sale-entry-form),
  .entry-panel:has(.sample-entry-form),
  .sale-entry-form,
  .sample-entry-form {
    width: auto;
  }

  .sale-entry-form .line-row > .product-stock-summary,
  .sample-entry-form .line-row > .product-stock-summary {
    grid-column: 1;
  }
}

@media (max-width: 820px) {
  .app-header-inner {
    align-items: stretch;
    flex-direction: column;
  }

  .main-nav {
    justify-content: flex-start;
  }

  .action-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .page {
    width: min(100% - 20px, var(--content-width));
    margin: var(--space-md) auto;
  }

  .summary-panel,
  .action-panel {
    padding: var(--space-md);
  }

  input,
  select,
  textarea {
    max-width: none;
  }

  form {
    max-width: none;
  }

  .page-panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .page-panel-header .action-button {
    width: 100%;
  }

  .invoice-preview-frame {
    min-height: 540px;
  }

  .confirmation-panel .invoice-preview-frame {
    min-height: 500px;
  }

  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-header-actions {
    justify-content: flex-start;
  }

  .confirmation-header {
    align-items: stretch;
    flex-direction: column;
  }

  .status-pill {
    align-self: flex-start;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 16px;
  }

  .app-header {
    padding: var(--space-md);
  }

  .main-nav a,
  .logout-form button {
    width: 100%;
  }

  .main-nav,
  .logout-form {
    width: 100%;
  }

  form > p {
    align-items: stretch;
    flex-direction: column;
  }

  form > p > a,
  form > p > button,
  form > p > .action-button {
    width: 100%;
  }

  .summary-panel > form.filter-bar input,
  .summary-panel > form.filter-bar select,
  .summary-panel > form.filter-bar button {
    width: 100%;
  }

  .summary-panel > form.filter-bar .filter-actions-row {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-panel > form.filter-bar .filter-field {
    align-items: stretch;
    flex-direction: column;
    gap: var(--space-xs);
  }

  .summary-panel > form.filter-bar .filter-field > label {
    flex: 1 1 auto;
  }

  .summary-panel > form.filter-bar .filter-actions-row .filter-field {
    flex: 1 1 auto;
    width: 100%;
  }

  .summary-panel > form.filter-bar .filter-actions-row a {
    width: 100%;
  }

  .confirmation-actions,
  .entry-actions {
    flex-direction: column;
  }

  .confirmation-actions .action-button,
  .entry-actions .action-button {
    width: 100%;
  }

  table {
    min-width: 640px;
  }
}
