:root {
  --bg: #eaf4ee;
  --bg-strong: #ddeee3;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --surface-soft: rgba(232, 245, 237, 0.92);
  --line: rgba(39, 84, 56, 0.14);
  --ink: #183126;
  --muted: #5e7768;
  --accent: #3f8a5a;
  --accent-strong: #2b6841;
  --accent-soft: rgba(63, 138, 90, 0.14);
  --accent-cool: #2f6f66;
  --danger: #b04444;
  --shadow: 0 18px 42px rgba(35, 74, 50, 0.12);
  --radius: 24px;
  --panel-width: min(560px, 100vw);
  --rail-width: 280px;
  --rail-collapsed: 88px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: Calibri, Candara, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(63, 138, 90, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(47, 111, 102, 0.1), transparent 32%),
    linear-gradient(180deg, #f5fbf7 0%, var(--bg) 46%, var(--bg-strong) 100%);
}

body {
  padding: 18px;
}

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

.app-shell {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  gap: 24px;
  min-height: calc(100vh - 36px);
  transition: grid-template-columns 200ms ease;
}

.app-shell.nav-collapsed {
  grid-template-columns: var(--rail-collapsed) minmax(0, 1fr);
}

.tool-rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-radius: 32px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(243, 250, 246, 0.76)),
    linear-gradient(180deg, rgba(63, 138, 90, 0.08), transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tool-rail__top {
  display: flex;
  justify-content: flex-end;
}

.tool-rail__brand-wrap {
  display: flex;
  justify-content: center;
  padding: 4px 0 6px;
}

.tool-rail__brand {
  display: block;
  width: min(100%, 220px);
  height: auto;
  object-fit: contain;
}

.nav-toggle {
  display: inline-grid;
  gap: 4px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 0;
  border-radius: 14px;
  background: rgba(63, 138, 90, 0.08);
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: var(--accent-strong);
}

.tool-rail__actions {
  display: grid;
  gap: 10px;
}

.rail-button,
.icon-button,
.primary,
.secondary,
.ghost,
.danger {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.rail-button:hover,
.icon-button:hover,
.primary:hover,
.secondary:hover,
.ghost:hover,
.danger:hover {
  transform: translateY(-1px);
}

.rail-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  text-align: left;
  background: rgba(63, 138, 90, 0.08);
  color: var(--ink);
  font-weight: 700;
}

.rail-button.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #f4fff7;
  box-shadow: 0 12px 24px rgba(43, 104, 65, 0.22);
}

.rail-icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.rail-icon--invoice {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b6841' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2h9l5 5v15H6z'/%3E%3Cpath d='M14 2v6h6'/%3E%3Cpath d='M9 13h6'/%3E%3Cpath d='M9 17h6'/%3E%3C/svg%3E");
}

.rail-icon--customers {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b6841' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='9.5' cy='7' r='4'/%3E%3Cpath d='M20 8v6'/%3E%3Cpath d='M23 11h-6'/%3E%3C/svg%3E");
}

.rail-icon--articles {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b6841' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z'/%3E%3Cpath d='M3.3 7l8.7 5 8.7-5'/%3E%3Cpath d='M12 22V12'/%3E%3C/svg%3E");
}

.rail-icon--settings {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b6841' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06A2 2 0 1 1 7.04 3.4l.06.06a1.65 1.65 0 0 0 1.82.33h.08A1.65 1.65 0 0 0 10 2.28V2a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51h.08a1.65 1.65 0 0 0 1.82-.33l.06-.06A2 2 0 1 1 19.79 6l-.06.06a1.65 1.65 0 0 0-.33 1.82v.08a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z'/%3E%3C/svg%3E");
}

.rail-icon--logout {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b04444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='M16 17l5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E");
}

.app-shell.nav-collapsed .rail-button {
  justify-content: center;
  padding-inline: 12px;
}

.app-shell.nav-collapsed .rail-label,
.app-shell.nav-collapsed .tool-rail__brand-wrap,
.app-shell.nav-collapsed .tool-rail__footer {
  display: none;
}

.tool-rail__footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.logout-button {
  width: 100%;
  background: rgba(176, 68, 68, 0.12);
  color: var(--danger);
}

.logout-button:hover {
  background: rgba(176, 68, 68, 0.18);
}

.hero-status {
  padding: 16px;
  border-radius: 20px;
  background: rgba(47, 111, 102, 0.1);
  color: var(--accent-cool);
  font-weight: 700;
}

.app-version {
  padding: 0 8px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}

.settings-version {
  padding: 6px 8px 2px;
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}

.logo-preview-card {
  position: relative;
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 14px;
  border: 1px solid rgba(39, 84, 56, 0.12);
  border-radius: 18px;
  background: rgba(247, 252, 249, 0.9);
}

.logo-preview-card__image {
  display: block;
  width: 100%;
  max-width: 180px;
  aspect-ratio: 2 / 1;
  object-fit: contain;
}

.logo-preview-card__empty {
  display: none;
  align-self: center;
  justify-self: center;
  min-height: 90px;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.logo-preview-card__label {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.logo-preview-card.is-empty .logo-preview-card__image {
  display: none;
}

.logo-preview-card.is-empty .logo-preview-card__empty {
  display: inline-flex;
}

.logo-remove-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(176, 68, 68, 0.22);
  background: rgba(255, 239, 239, 0.96);
  color: #b04444;
  font-size: 1.2rem;
  line-height: 1;
}

.logo-remove-button:hover:not(:disabled) {
  background: rgba(255, 222, 222, 0.98);
  border-color: rgba(176, 68, 68, 0.34);
}

.logo-remove-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.change-password-button {
  justify-self: start;
  margin-top: 10px;
}

.content-shell {
  min-width: 0;
}

.main-card,
.side-card,
.preview-card,
.side-panel,
.auth-card,
.dialog-card,
.signature-card {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.main-card {
  padding: 24px;
  border-radius: 32px;
  min-height: calc(100vh - 36px);
}

.section-head,
.preview-head,
.invoice-toolbar,
.side-panel__head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.section-head {
  margin-bottom: 18px;
}

.section-kicker {
  margin: 0 0 8px;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-cool);
}

h2,
h3 {
  margin: 0;
  font-family: Calibri, Candara, "Segoe UI", Arial, sans-serif;
  font-weight: 700;
}

h2 {
  font-size: clamp(1.4rem, 3vw, 2rem);
}

h3 {
  font-size: 1.2rem;
}

.section-note,
.panel-note {
  max-width: 460px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.muted-note {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.auth-overlay,
.dialog-overlay {
  position: fixed;
  inset: 0;
  padding: 18px;
  background: rgba(20, 34, 28, 0.4);
  backdrop-filter: blur(10px);
  z-index: 60;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(234, 244, 238, 0.72);
  backdrop-filter: blur(8px);
  z-index: 59;
}

.loading-overlay__card {
  display: grid;
  justify-items: center;
  gap: 14px;
  min-width: min(280px, 100%);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.loading-overlay__spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(63, 138, 90, 0.14);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: loading-spin 900ms linear infinite;
}

.loading-overlay__text {
  margin: 0;
  color: var(--accent-cool);
  font-weight: 700;
  text-align: center;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.install-sheet {
  position: fixed;
  inset: auto 18px 18px;
  z-index: 58;
}

.install-sheet__card {
  width: min(100%, 440px);
  margin-left: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.install-sheet__actions {
  margin-top: 16px;
  justify-content: flex-end;
}

.auth-overlay {
  display: grid;
  place-items: center;
}

.dialog-overlay {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.auth-card,
.dialog-card {
  width: min(100%, 860px);
  padding: 24px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.95);
}

.dialog-card {
  margin: auto 0;
  max-height: none;
  overflow: visible;
}

.auth-card {
  width: min(100%, 560px);
}

.dialog-card--compact {
  width: min(100%, 760px);
}

.dialog-card--preview {
  width: min(100%, 920px);
}

.auth-card__logo {
  display: block;
  width: 92px;
  height: 92px;
  margin: 0 auto 14px;
  object-fit: contain;
  object-position: center;
}

.auth-grid {
  margin-top: 18px;
}

.auth-actions {
  justify-content: flex-end;
}

.invoice-meta-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.form-inline-two,
.form-inline-three {
  display: grid;
  gap: 14px;
}

.form-inline-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-inline-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.settings-grid > .settings-section,
.settings-grid > .actions {
  grid-column: 1 / -1;
}

.settings-section__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.span-2 {
  grid-column: span 2;
}

label,
.static-field {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.field-title,
.label-with-action {
  display: flex;
  align-items: center;
  min-height: 32px;
}

.label-with-action {
  justify-content: space-between;
  gap: 10px;
}

.info-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  font-weight: 700;
}

.static-field__value {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(39, 84, 56, 0.15);
  border-radius: 16px;
  background: rgba(230, 243, 235, 0.9);
  color: var(--ink);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(39, 84, 56, 0.15);
  border-radius: 16px;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.password-toggle {
  white-space: nowrap;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
}

.password-toggle--icon::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  margin: 0 auto;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23183126' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12Z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
}

.password-toggle--icon.is-visible::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23183126' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.58 10.58a2 2 0 1 0 2.83 2.83'/%3E%3Cpath d='M16.68 16.67A10.94 10.94 0 0 1 12 18c-7 0-11-6-11-6a21.77 21.77 0 0 1 5.17-5.94'/%3E%3Cpath d='M9.9 4.24A10.94 10.94 0 0 1 12 4c7 0 11 8 11 8a21.8 21.8 0 0 1-1.67 2.68'/%3E%3Cpath d='M1 1l22 22'/%3E%3C/svg%3E");
}

.field-feedback {
  min-height: 18px;
  font-size: 0.84rem;
  color: var(--muted);
}

.field-feedback.is-error {
  color: #b04444;
  font-weight: 700;
}

input.is-invalid,
textarea.is-invalid,
select.is-invalid {
  border-color: rgba(176, 68, 68, 0.75);
  background: rgba(255, 241, 241, 0.96);
  color: #7a1d1d;
}

.cc-list {
  display: grid;
  gap: 10px;
}

.cc-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.cc-row__input {
  min-width: 0;
}

.ghost.cc-row__remove {
  align-self: start;
  background: rgba(176, 68, 68, 0.18);
  color: var(--danger);
}

.ghost.cc-row__remove:hover {
  background: rgba(176, 68, 68, 0.24);
  color: #922f2f;
}

.cc-add-button {
  align-self: start;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(63, 138, 90, 0.5);
  box-shadow: 0 0 0 4px rgba(63, 138, 90, 0.13);
}

textarea {
  resize: vertical;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 30px;
}

.checkbox input {
  width: 18px;
  height: 18px;
}

.actions,
.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.panel-form-actions {
  position: sticky;
  bottom: calc(var(--panel-padding, 0px) * -1);
  z-index: 6;
  margin-top: 14px;
  margin-inline: calc(var(--panel-padding, 0px) * -1);
  padding: 12px var(--panel-padding, 0px) calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(247, 252, 249, 0), rgba(247, 252, 249, 0.94) 24%, rgba(247, 252, 249, 0.98));
}

.primary,
.secondary,
.ghost,
.danger,
.icon-button {
  padding: 12px 18px;
  border-radius: 999px;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #f7fff9;
  box-shadow: 0 12px 24px rgba(43, 104, 65, 0.22);
}

.secondary {
  background: rgba(47, 111, 102, 0.12);
  color: var(--accent-cool);
}

.ghost {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

.danger {
  background: rgba(176, 68, 68, 0.12);
  color: var(--danger);
}

.ghost-danger {
  background: rgba(176, 68, 68, 0.06);
  color: var(--danger);
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.6rem;
  line-height: 1;
  background: rgba(39, 84, 56, 0.08);
  color: var(--ink);
}

.invoice-toolbar {
  margin: 18px 0 16px;
  align-items: center;
}

.totals-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 20px;
  border: 1px solid rgba(39, 84, 56, 0.1);
  background: rgba(255, 255, 255, 0.65);
}

.invoice-items-wrap {
  padding: 6px;
}

.invoice-items-actions,
.panel-table__actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.invoice-items-actions .secondary {
  order: 1;
}

.invoice-items-actions .totals-chip {
  order: 2;
  margin-left: auto;
}

.panel-table {
  margin-top: 18px;
}

.panel-search {
  padding: 12px 12px 0;
}

.panel-search input {
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid rgba(39, 84, 56, 0.14);
  background: rgba(255, 255, 255, 0.96);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(39, 84, 56, 0.08);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(47, 111, 102, 0.06);
}

.invoice-table {
  min-width: 1100px;
  table-layout: fixed;
}

.invoice-table th,
.invoice-table td {
  padding: 10px;
}

.invoice-table td[data-label="Artikel"] {
  width: 18%;
}

.invoice-table td[data-label="Beschreibung"] {
  width: 28%;
}

.invoice-table td[data-label="Menge & Einheit"] {
  width: 20%;
}

.invoice-table td[data-label="Preis, MwSt. & Rabatt"] {
  width: 24%;
}

.invoice-table td[data-label="Summe"] {
  width: 10%;
}

.invoice-table td[data-label="Aktion"] {
  width: 8%;
}

.invoice-table input,
.invoice-table select {
  min-height: 44px;
}

.quantity-stepper {
  display: grid;
  grid-template-columns: 52px minmax(84px, 1fr) 52px;
  gap: 8px;
  align-items: center;
}

.quantity-stepper__button {
  min-height: 44px;
  border-radius: 14px;
  font-size: 1.15rem;
  font-weight: 700;
}

.invoice-table input[type="number"] {
  padding-right: 10px;
}

.invoice-description-fields {
  display: grid;
  gap: 8px;
}

.invoice-description-fields--two {
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
}

.form-inline-two--equal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.invoice-field-row {
  display: grid;
  gap: 10px;
}

.invoice-field-row--two {
  grid-template-columns: minmax(0, 4fr) minmax(0, 0.9fr);
}

.invoice-field-row--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.invoice-field-stack {
  display: grid;
  gap: 6px;
}

.invoice-field-caption {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.readonly-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  background: rgba(63, 138, 90, 0.1);
  color: var(--accent-strong);
  font-weight: 700;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.admin-user-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 0;
  background: transparent;
  color: inherit;
  border-radius: 0;
  text-align: left;
}

.admin-user-summary strong {
  font-size: 1rem;
}

.admin-user-summary__meta {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

@media (min-width: 1181px) {
  .admin-user-summary {
    padding: 0;
    background: transparent;
  }

  .admin-user-summary__meta {
    display: none;
  }
}

.preview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(300px, 0.9fr);
  gap: 20px;
  margin-top: 18px;
}

.preview-card,
.side-card {
  padding: 18px;
  border-radius: 24px;
  background: var(--surface-strong);
}

.preview-head {
  margin-bottom: 16px;
  align-items: center;
}

.preview-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.preview-actions .primary {
  min-width: 220px;
}

#invoiceCanvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 18px;
  border: 1px solid rgba(39, 84, 56, 0.12);
  background: white;
}

.dialog-preview {
  margin-top: 18px;
  border-radius: 22px;
  border: 1px solid rgba(39, 84, 56, 0.12);
  overflow: visible;
  max-height: none;
  background: #ffffff;
}

#sendPreviewCanvas {
  width: 100%;
  height: auto;
  display: block;
  background: white;
}

.signature-card {
  margin-top: 18px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(247, 252, 249, 0.92);
}

.signature-card__head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

#signaturePad {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 18px;
  border: 1px dashed rgba(39, 84, 56, 0.24);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 250, 246, 0.95));
  touch-action: none;
}

.dialog-actions {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

.dialog-actions__primary {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-actions .primary,
.dialog-actions .secondary,
.dialog-actions .ghost {
  min-width: 156px;
  justify-content: center;
}

.share-only-button {
  min-width: 54px !important;
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 16px;
}

.share-only-button::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  margin: 0 auto;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f6f66' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='18' cy='5' r='3'/%3E%3Ccircle cx='6' cy='12' r='3'/%3E%3Ccircle cx='18' cy='19' r='3'/%3E%3Cpath d='M8.59 13.51 15.42 17.49'/%3E%3Cpath d='M15.41 6.51 8.59 10.49'/%3E%3C/svg%3E");
}

.action-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.action-with-icon::before {
  content: "";
  width: 18px;
  height: 18px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.action-with-icon--signature::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f6f66' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 1 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E");
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  padding: 14px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1px solid rgba(39, 84, 56, 0.08);
}

.history-item__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 4px;
}

.history-item__time {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.history-item p {
  margin: 0;
  color: var(--muted);
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
}

.history-item a {
  color: var(--accent-cool);
  font-weight: 700;
  text-decoration: none;
}

.history-item__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.history-item__actions .ghost,
.history-item__actions .secondary {
  min-width: 0;
}

.settings-section {
  grid-column: span 2;
  margin: 0;
  padding: 18px;
  border: 1px solid rgba(39, 84, 56, 0.12);
  border-radius: 22px;
  background: rgba(247, 252, 249, 0.9);
}

.settings-section legend {
  padding: 0 10px;
  color: var(--accent-strong);
  font-weight: 700;
}

.empty-state {
  color: var(--muted);
  padding: 16px;
}

.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 34, 28, 0.34);
  backdrop-filter: blur(4px);
  z-index: 20;
}

.side-panel {
  --panel-padding: 22px;
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: var(--panel-width);
  padding: 22px;
  border-radius: 28px;
  overflow: auto;
  z-index: 30;
  transform: translateX(calc(100% + 28px));
  transition: transform 220ms ease;
}

.side-panel.is-open {
  transform: translateX(0);
}

.side-panel__head {
  margin-bottom: 18px;
}

body.panel-open {
  overflow: hidden;
}

@media (max-width: 1180px) {
  .app-shell,
  .app-shell.nav-collapsed {
    grid-template-columns: 1fr;
  }

  .tool-rail,
  .app-shell.nav-collapsed .tool-rail {
    padding: 16px;
  }

  .tool-rail__actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .app-shell.nav-collapsed .tool-rail__brand-wrap,
  .app-shell.nav-collapsed .tool-rail__footer {
    display: grid;
  }

  .app-shell.nav-collapsed .rail-label {
    display: inline;
  }

  .main-card,
  .invoice-meta-grid,
  .form-grid,
  .preview-layout {
    grid-template-columns: 1fr;
  }

  .compact-grid,
  .settings-section,
  .span-2 {
    grid-column: auto;
  }

  .settings-section__grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  :root {
    --mobile-nav-height: 88px;
  }

  html,
  body {
    min-height: 100dvh;
  }

  body {
    padding: 0;
  }

  .app-shell {
    display: block;
    min-height: 100dvh;
  }

  .tool-rail,
  .main-card {
    border-radius: 0;
    min-height: auto;
  }

  .tool-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.995), rgba(245, 250, 247, 0.99)),
      linear-gradient(180deg, rgba(63, 138, 90, 0.1), transparent);
    box-shadow: 0 -14px 36px rgba(24, 49, 38, 0.16);
  }

  .tool-rail__top,
  .tool-rail__brand-wrap,
  .tool-rail__footer,
  .app-shell.nav-collapsed .tool-rail__brand-wrap,
  .app-shell.nav-collapsed .tool-rail__footer {
    display: none;
  }

  .tool-rail__actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .rail-button,
  .app-shell.nav-collapsed .rail-button {
    width: 100%;
    min-width: 0;
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-height: 68px;
    padding: 10px 6px;
    border-radius: 18px;
    text-align: center;
  }

  .rail-label,
  .app-shell.nav-collapsed .rail-label {
    display: block;
    font-size: 0.68rem;
    line-height: 1.05;
  }

  .dialog-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .dialog-card {
    width: 100%;
    min-height: min(86dvh, 860px);
    margin: 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    border-radius: 26px 26px 0 0;
    overflow-y: auto;
  }

  .dialog-card .side-panel__head {
    position: sticky;
    top: calc(-18px - env(safe-area-inset-top));
    z-index: 6;
    margin: calc(-18px - env(safe-area-inset-top)) -16px 16px;
    padding: calc(18px + env(safe-area-inset-top)) 16px 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(255, 255, 255, 0.94));
    backdrop-filter: blur(10px);
  }

  .invoice-toolbar,
  .preview-head,
  .section-head,
  .side-panel__head,
  .toolbar-group {
    flex-direction: column;
    align-items: stretch;
  }

  .content-shell {
    min-height: 100dvh;
    width: 100%;
  }

  .main-card {
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(var(--mobile-nav-height) + 18px + env(safe-area-inset-bottom));
    background: transparent;
    border: 0;
    box-shadow: none;
    width: 100%;
    max-width: 100%;
  }

  .section-head {
    margin-bottom: 14px;
  }

  .section-head h2 {
    font-size: 1.55rem;
  }

  .section-kicker {
    font-size: 0.72rem;
    letter-spacing: 0.14em;
  }

  .invoice-meta-grid,
  .form-grid,
  .compact-grid,
  .settings-section__grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-inline-two {
    grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  }

  .form-inline-two--equal {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-inline-three {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.85fr) minmax(0, 0.85fr);
  }

  .invoice-meta-grid .span-2,
  .form-grid .span-2,
  .settings-section__grid .span-2 {
    grid-column: auto;
  }

  label,
  .static-field {
    gap: 7px;
    font-size: 0.92rem;
  }

  input,
  select,
  textarea,
  .static-field__value {
    min-height: 54px;
    padding: 15px 16px;
    border-radius: 18px;
    font-size: 1rem;
  }

  textarea {
    min-height: 116px;
  }

  .password-field,
  .cc-row {
    grid-template-columns: minmax(0, 1fr) 54px;
    gap: 8px;
  }

  .password-toggle,
  .icon-button {
    min-width: 54px;
    min-height: 54px;
    width: 54px;
    height: 54px;
  }

  .settings-section {
    padding: 16px 14px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.92);
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    width: 100%;
    max-width: 100%;
  }

  .invoice-items-wrap {
    padding: 0;
  }

  .invoice-items-actions,
  .panel-table__actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 10px;
    padding: 10px 0 0;
  }

  .invoice-items-actions .secondary,
  .invoice-items-actions .totals-chip {
    margin-left: 0;
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .preview-layout {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 16px;
    width: 100%;
  }

  .preview-card,
  .side-card {
    padding: 14px;
    border-radius: 24px;
    width: 100%;
    max-width: 100%;
  }

  .preview-head .primary,
  .preview-actions .primary,
  .dialog-actions .primary,
  .dialog-actions .secondary,
  .dialog-actions .ghost,
  .actions .primary,
  .actions .secondary,
  .actions .ghost {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .dialog-actions__primary {
    width: 100%;
  }

  .share-only-button {
    width: 54px !important;
    flex: 0 0 54px;
  }

  .panel-form-actions {
    position: sticky;
    bottom: 0;
    margin: 8px calc(var(--panel-padding, 0px) * -1) 0;
    padding: 12px var(--panel-padding, 0px) calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.94) 26%, rgba(255, 255, 255, 0.99));
    backdrop-filter: blur(10px);
  }

  .logout-inline-button {
    background: rgba(176, 68, 68, 0.12);
    color: var(--danger);
  }

  .logout-inline-button:hover {
    background: rgba(176, 68, 68, 0.18);
  }

  .history-item {
    padding: 12px 14px;
  }

  .history-item__head,
  .history-item__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .table-wrap {
    margin-top: 0;
  }

  table {
    min-width: 0;
    max-width: 100%;
  }

  .invoice-table {
    min-width: 0;
    width: 100%;
  }

  table thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    margin-bottom: 14px;
    border: 1px solid rgba(39, 84, 56, 0.08);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.8);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: start;
    padding: 12px 14px;
  }

  td::before {
    display: none;
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
  }

  td[data-label]:not([data-label=""])::before {
    display: block;
    content: attr(data-label);
  }

  td input,
  td select,
  td button,
  .readonly-chip {
    width: 100%;
  }

  .invoice-table td[data-label="Artikel"],
  .invoice-table td[data-label="Beschreibung"],
  .invoice-table td[data-label="Menge & Einheit"],
  .invoice-table td[data-label="Preis, MwSt. & Rabatt"],
  .invoice-table td[data-label="Summe"],
  .invoice-table td[data-label="Aktion"] {
    width: 100%;
  }

  .invoice-table input,
  .invoice-table select,
  .quantity-stepper__button {
    min-height: 56px;
  }

  .invoice-field-row--two {
    grid-template-columns: minmax(0, 4.2fr) minmax(0, 0.9fr);
  }

  .invoice-description-fields--two {
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  }

  .invoice-field-row--three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readonly-chip {
    justify-content: flex-start;
    min-height: 52px;
  }

  .row-actions {
    flex-direction: row;
    width: 100%;
  }

  .admin-user-row td[data-label="Zuletzt online"] {
    display: none;
  }

  .admin-user-row:not(.is-expanded) td[data-label="Firma"],
  .admin-user-row:not(.is-expanded) td[data-label="Daten"],
  .admin-user-row:not(.is-expanded) td[data-label="Aktion"] {
    display: none;
  }

  .admin-user-row td[data-label="Benutzer"] {
    padding: 0;
    gap: 0;
  }

  .admin-user-row td[data-label="Benutzer"]::before {
    display: none;
    content: none;
  }

  .admin-user-summary {
    min-height: 60px;
    padding: 14px;
    border-radius: 18px;
  }

  .admin-user-row.is-expanded td[data-label="Firma"],
  .admin-user-row.is-expanded td[data-label="Daten"],
  .admin-user-row.is-expanded td[data-label="Aktion"] {
    display: grid;
  }

  .side-panel {
    --panel-padding: 14px;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-nav-height) + 10px + env(safe-area-inset-bottom));
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - var(--mobile-nav-height) - 10px - env(safe-area-inset-bottom));
    min-height: auto;
    padding: calc(14px + env(safe-area-inset-top)) 14px 24px;
    border-radius: 0;
    transform: translateY(100%);
    background: rgba(255, 255, 255, 0.98);
    z-index: 50;
  }

  .side-panel.is-open {
    transform: translateY(0);
  }

  .side-panel__head {
    position: sticky;
    top: calc(-14px - env(safe-area-inset-top));
    z-index: 4;
    margin: 0 -14px 16px;
    padding: calc(14px + env(safe-area-inset-top)) 14px 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.92));
    backdrop-filter: blur(10px);
  }

  body.dialog-open .tool-rail {
    transform: translateY(calc(100% + env(safe-area-inset-bottom) + 16px));
    pointer-events: none;
  }

  .auth-overlay {
    padding: 0;
    align-items: stretch;
  }

  .install-sheet {
    inset: auto 12px calc(var(--mobile-nav-height) + 16px + env(safe-area-inset-bottom));
  }

  .preview-actions {
    margin-top: 14px;
  }

  .loading-overlay {
    padding: 18px;
  }

  .loading-overlay__card {
    width: 100%;
    max-width: 320px;
    padding: 24px 20px;
    border-radius: 24px;
  }

  .install-sheet__card {
    width: 100%;
    padding: 18px;
    border-radius: 22px;
  }

  .install-sheet__actions .primary,
  .install-sheet__actions .ghost {
    width: 100%;
  }

  .auth-card {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    padding: calc(22px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .auth-card__logo {
    width: 88px;
    height: 88px;
    margin-bottom: 18px;
  }

  .signature-card__head,
  .dialog-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .dialog-card--compact {
    min-height: 72dvh;
  }

  .signature-card {
    min-height: 48dvh;
  }

  #signaturePad {
    min-height: 36dvh;
  }

  .dialog-preview {
    margin-top: 14px;
    border-radius: 18px;
    overflow: hidden;
  }

  .dialog-card,
  .dialog-card--compact,
  .dialog-card--preview,
  .preview-card,
  .side-card,
  .settings-section,
  .signature-card,
  .info-card,
  .history-list,
  .history-item {
    max-width: 100%;
  }

  .content-shell,
  .main-card,
  .preview-card,
  .side-card,
  .dialog-card,
  .dialog-preview {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  #invoiceCanvas,
  #sendPreviewCanvas {
    width: 100%;
    max-width: 100%;
    border-radius: 18px;
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-nav-height: 78px;
  }

  .tool-rail {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
  }

  .tool-rail__actions {
    display: flex;
    gap: 6px;
    width: 100%;
  }

  .rail-button,
  .app-shell.nav-collapsed .rail-button {
    min-height: 60px;
    padding: 8px 4px;
    border-radius: 16px;
    gap: 4px;
  }

  .rail-icon {
    width: 18px;
    height: 18px;
    flex-basis: 18px;
  }

  .rail-label,
  .app-shell.nav-collapsed .rail-label {
    font-size: 0.58rem;
    line-height: 1;
    letter-spacing: 0;
  }

  .main-card {
    padding-bottom: calc(var(--mobile-nav-height) + 16px + env(safe-area-inset-bottom));
  }

  .side-panel {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .quantity-stepper {
    grid-template-columns: 48px minmax(96px, 1fr) 48px;
  }
}
