:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1e231c;
  background: #f5f3ed;
  font-size: 16px;
  line-height: 1.5;
  --accent: #aa531d;
  --line: #dcdcd0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-wrap: break-word;
}

:where(a, code) {
  overflow-wrap: anywhere;
}

a {
  color: var(--accent);
  font-weight: 600;
}

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

button, .button {
  cursor: pointer;
  background: #243b2e;
  color: #ffffff;
  border: 0;
  border-radius: 7px;
  padding: 9px 15px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover, .button:hover {
  filter: brightness(1.1);
}

button:disabled {
  opacity: 0.5;
  cursor: wait;
}

button.secondary {
  color: #243b2e;
  background: #e6ebe2;
  border: 1px solid #c9d1c3;
}

button.danger {
  background: #8b3030;
}

input, select, textarea {
  padding: 9px 11px;
  border: 1px solid #b8beb0;
  border-radius: 6px;
  background: #ffffff;
  max-width: 100%;
  color: #1e231c;
  font-size: 0.95rem;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.96rem;
  font-weight: 700;
  color: #252b22;
}

textarea {
  min-height: 92px;
}

form {
  display: grid;
  gap: 16px;
}

h1, h2, h3 {
  text-wrap: balance;
  color: #181d16;
}

h1 {
  font-size: clamp(1.65rem, 1.3rem + 1.2vw, 2.15rem);
  letter-spacing: -0.03em;
  margin: 0.25em 0;
}

h2 {
  font-size: 1.3rem;
  margin: 0 0 16px;
}

h3 {
  font-size: 1.1rem;
}

p, li {
  line-height: 1.6;
  text-wrap: pretty;
}

.muted, small {
  color: #4f584d;
  font-size: 0.94rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  color: #8c6533;
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: 235px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #243b2e;
  color: #f5f2e7;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  font-size: 1.55rem;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.sidebar nav {
  display: grid;
  gap: 10px;
}

.sidebar nav button {
  text-align: left;
  justify-content: flex-start;
  background: transparent;
  color: #d6e0d3;
  padding: 13px 14px;
  font-size: 1rem;
}

.sidebar nav button.active {
  background: #3c5443;
  color: #ffffff;
}

.sidebar a {
  color: #d6e0d3;
}

.sidebar footer {
  margin-top: auto;
  font-size: 0.88rem;
  line-height: 2;
}

.content {
  padding: 32px 40px;
  min-width: 0;
  max-width: 1600px;
}

.topbar, .row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 26px;
}

.card {
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px;
  margin: 22px 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.grid .card {
  margin: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat {
  background: #fffef9;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stat strong {
  display: block;
  font-size: 1.85rem;
  margin: 8px 0;
  color: #181d16;
}

.table-wrap {
  overflow: auto;
  max-height: 600px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
  white-space: nowrap;
}

td, th {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

td {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  color: #485140;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f4f3eb;
  position: sticky;
  top: 0;
}

td button, td a {
  font-size: 0.86rem;
  min-block-size: 2.25rem;
  padding: 6px 12px;
  margin-right: 6px;
}

#notice {
  position: sticky;
  top: 10px;
  z-index: 10;
  border-radius: 8px;
  padding: 14px 16px;
  font-weight: 600;
  background: #e3eed8;
  color: #1f3c26;
}

#notice.error {
  background: #ffe4dc;
  color: #782212;
}

[hidden] {
  display: none !important;
}

.login-shell {
  max-width: 460px;
  margin: 8vh auto;
  padding: 28px;
}

.login-shell .card {
  box-shadow: 0 15px 65px #243b2e0c;
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
}

.checks label {
  display: flex;
  align-items: center;
  font-weight: 600;
  min-block-size: 2.5rem;
}

.checks input {
  min-block-size: 1.25rem;
  width: 1.25rem;
}

.legal {
  max-width: 860px;
  margin: auto;
  padding: 40px 24px;
}

.legal section {
  background: white;
  border: 1px solid var(--line);
  padding: 25px;
  margin: 20px 0;
  border-radius: 8px;
}

.legal h2 {
  margin-top: 0;
}

.legal footer {
  margin: 35px 0;
}

.badge {
  background: #edf0e6;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.86rem;
  font-weight: 600;
}

.warning {
  background: #fff1cf;
  border-left: 4px solid #bf7b18;
  padding: 16px;
  font-weight: 600;
}

.secret {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  background: #edf0e6;
  padding: 16px;
  user-select: all;
}

.counter {
  max-width: 800px;
  margin: 30px auto;
  padding: 0 20px;
}

.counter header {
  margin-bottom: 25px;
}

.counter textarea {
  width: 100%;
}

.counter .result {
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 1.05rem;
}

.counter .result.warning {
  background: #fff1cf;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

details {
  margin: 16px 0;
}

summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 1.02rem;
  padding: 6px 0;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 800px) {
  .layout {
    display: block;
  }
  .sidebar {
    padding: 14px;
  }
  .sidebar nav {
    display: flex;
    overflow: auto;
  }
  .sidebar nav button {
    min-width: 140px;
    white-space: nowrap;
  }
  .sidebar footer {
    display: none;
  }
  .content {
    padding: 20px 14px;
  }
  .topbar {
    margin-bottom: 20px;
  }
  .card {
    padding: 18px;
  }
  .login-shell {
    margin: 24px auto;
    padding: 16px;
  }
}

@media print {
  button, nav, .sidebar, .topbar, .no-print {
    display: none;
  }
  .layout {
    display: block;
  }
  .content {
    padding: 0;
  }
  .card {
    break-inside: avoid;
  }
}

.order-lines {
  display: grid;
  gap: 14px;
}

.order-line {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) minmax(80px, 0.6fr) minmax(90px, 0.6fr) minmax(140px, 1.5fr) auto;
  gap: 12px;
  align-items: end;
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}

.order-line input, .order-line select {
  width: 100%;
  min-width: 0;
}

.order-alerts {
  white-space: pre-wrap;
  line-height: 1.6;
  margin: 12px 0;
}

#order-total {
  font-size: 1.25rem;
  font-weight: 800;
}

#order-editor .card {
  background: #f7f7f0;
}

#order-editor pre {
  max-height: 220px;
  overflow: auto;
}

@media (max-width: 1000px) {
  .order-line {
    grid-template-columns: minmax(0, 1fr) minmax(80px, 0.5fr);
  }
  .order-line label:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  .order-line {
    grid-template-columns: minmax(0, 1fr);
  }
  .order-line label:first-child {
    grid-column: auto;
  }
  #order-editor .topbar {
    align-items: flex-start;
  }
}

.order-line textarea {
  min-height: 44px;
  resize: vertical;
  width: 100%;
}

.customer-fields {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
  display: grid;
  gap: 15px;
}

.customer-active {
  display: flex;
  align-items: center;
  gap: 8px;
}

.customer-active input {
  width: auto;
  min-block-size: 1.25rem;
}

#terminal-qr {
  max-width: 100%;
  height: auto;
  background: white;
}

#terminal-link {
  overflow-wrap: anywhere;
}

#workspace {
  --ink: #243b2e;
  --soft: #eff3eb;
}

#workspace :is(button, a, input, select, textarea, summary):focus-visible {
  outline: 3px solid #aa531d;
  outline-offset: 3px;
}

#workspace :is(#page-title, #plan-day, #order-editor-title, #manual-order-title):focus {
  outline: none;
}

#workspace button, .backzettel .actions :is(button, a), #login button {
  min-block-size: 44px;
  font-size: 1rem;
}

#workspace .topbar :is(h1, h2) {
  margin: 0;
}

#workspace .sidebar {
  gap: 22px;
}

.workspace-brand .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.workspace-brand img {
  background: #fff8ee;
  border-radius: 9px;
}

#workspace-account {
  position: relative;
  align-self: center;
  margin: 6px 0 0;
}

#workspace-account summary {
  padding: 8px 0;
  font-size: .92rem;
}

#workspace-account button {
  position: absolute;
  z-index: 2;
  width: max-content;
  box-shadow: 0 4px 16px #18291c40;
}

#workspace .sidebar nav button {
  border: 1px solid transparent;
  line-height: 1.25;
}

#workspace .sidebar nav button.active {
  border-color: #789081;
}

.workspace-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  align-items: end;
}

.workspace-tools {
  align-items: end;
  min-width: 0;
}

#workspace select, #workspace input:not([type=checkbox]) {
  min-block-size: 44px;
  min-width: 0;
}

#branch-field {
  min-width: 0;
  max-width: 100%;
}

.plan-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 315px);
  gap: 20px;
  align-items: start;
}

.plan-layout:has(#plan-sheet[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

.plan-layout > .card {
  margin: 0;
}

.plan-heading {
  align-items: end;
  margin-bottom: 12px;
}

#plan-day {
  font-size: clamp(1.4rem, 1.1rem + .65vw, 1.85rem);
}

#plan-state, #backzettel-status {
  font-weight: 700;
}

#plan-review {
  gap: 0;
}

#plan-review details {
  margin: 0;
}

.sheet-card {
  background: var(--soft);
}

.sheet-card ul {
  padding-left: 21px;
}

.sheet-card li + li {
  margin-top: 6px;
}

.warning-text {
  color: #7b3a16;
}

.quiet-button {
  background: transparent;
  color: var(--ink);
  text-decoration: underline;
  padding-inline: 0;
  text-align: left;
}

.setup-next, .inline-feedback {
  border-radius: 8px;
  background: var(--soft);
  padding: 14px 16px;
  margin: 16px 0;
}

.setup-next p {
  margin: 0 0 10px;
}

.inline-feedback.error {
  color: #782212;
  background: #ffe4dc;
}

.section-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.section-switch button {
  background: #fffef9;
  border: 1px solid #bcc7b9;
  color: var(--ink);
}

.section-switch button[aria-pressed=true] {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

#workspace #tab-b2b > .section-switch + .card,
#workspace #b2b-orders > .card:first-child {
  margin-top: 0;
}

#workspace #order-editor {
  scroll-margin-top: 16px;
}

#order-customer-notes {
  white-space: pre-wrap;
}

#workspace .stacked-table :is(table, td, th) {
  white-space: normal;
}

#workspace .stacked-table td {
  overflow: visible;
}

.quantity-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

#workspace .quantity-field input {
  width: 7ch;
  min-width: 80px;
}

#workspace #plan-table td:first-child {
  font-weight: 700;
}

@media (max-width: 1180px) {
  .plan-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 800px) {
  #workspace .sidebar {
    gap: 12px;
  }

  .workspace-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  #workspace-account {
    margin: 0;
    text-align: right;
  }

  #workspace-account button {
    right: 0;
  }

  #workspace .sidebar nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  #workspace .sidebar nav button {
    min-width: 0;
    white-space: normal;
    padding: 8px 10px;
    hyphens: auto;
  }

  .workspace-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .workspace-tools {
    display: contents;
  }

  #branch-field {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #refresh {
    grid-column: 2;
    grid-row: 1;
  }

  .plan-layout {
    gap: 14px;
  }
}

@media (max-width: 680px) {
  #workspace .stacked-table {
    max-height: none;
    overflow: visible;
  }

  #workspace .stacked-table :is(table, tbody) {
    display: block;
  }

  #workspace .stacked-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  #workspace .stacked-table tbody tr {
    display: grid;
    gap: 6px;
    padding: 12px;
    margin-block: 10px;
    background: #f8f8f0;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  #workspace .stacked-table tbody td {
    display: block;
    max-width: none;
    padding: 0;
    border: 0;
    overflow-wrap: anywhere;
  }

  #workspace .stacked-table td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    margin-right: 8px;
    color: #4f584d;
    font-size: .94rem;
    font-weight: 600;
  }

  #workspace .stacked-table :is([data-column=name], [data-column=company_name], [data-column=productName]) {
    grid-row: 1;
    font-size: 1.08rem;
    font-weight: 750;
    order: -1;
  }

  #workspace .stacked-table td:is([data-column=name], [data-column=company_name], [data-column=productName])::before {
    content: none;
  }

  #workspace #orders-table [data-column=id] {
    display: none;
  }

  #workspace .stacked-table td[data-column=actions] button {
    width: 100%;
    margin: 4px 0 0;
  }

  #workspace #plan-table td[data-column=production] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
}
