*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  color: #181818;
  background: #f4f5f7;
}

body { display: flex; }

/* Layout */
.sidebar {
  width: 200px;
  min-width: 200px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  background: #202433;
  color: #d6d9e1;
  padding: 18px 12px;
}

.sidebar-brand {
  margin: 0 4px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

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

.sidebar-label {
  display: block;
  margin: 0 4px 5px;
  color: #9aa1b2;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.sidebar-select {
  width: 100%;
  padding: 7px 8px;
  color: #f6f7fb;
  background: #2b3144;
  border: 1px solid #444c64;
  border-radius: 4px;
  font: inherit;
}

.sidebar-fixed {
  padding: 7px 8px;
  color: #f6f7fb;
  background: #2b3144;
  border: 1px solid #444c64;
  border-radius: 4px;
}

.sidebar-nav {
  display: grid;
  gap: 3px;
}

.sidebar-nav a {
  padding: 8px 10px;
  color: #c3c7d2;
  text-decoration: none;
  border-radius: 4px;
}

.sidebar-nav a:hover {
  color: #fff;
  background: #30374d;
}

.sidebar-nav a.active {
  color: #fff;
  background: #3a425c;
  font-weight: 600;
}

.sidebar-account {
  display: grid;
  gap: 6px;
  margin-top: 22px;
  padding: 12px 4px 0;
  border-top: 1px solid #353c51;
}

.sidebar-user {
  color: #f6f7fb;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.sidebar-account a,
.sidebar-account button {
  padding: 0;
  color: #c3c7d2;
  background: transparent;
  border: 0;
  font: inherit;
  font-size: 12px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.sidebar-account a:hover,
.sidebar-account button:hover {
  color: #fff;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f4f5f7;
}

.auth-card {
  width: min(380px, 100%);
  padding: 24px;
  background: #fff;
  border: 1px solid #dfe3ea;
  border-radius: 6px;
}

.auth-card h1 {
  margin: 0 0 18px;
  font-size: 20px;
}

.auth-card form {
  display: grid;
  gap: 12px;
}

.auth-card .btn {
  width: 100%;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-header h2,
.page-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Messages */
.flash-list { margin-bottom: 16px; }

.flash {
  padding: 10px 12px;
  border-radius: 5px;
  margin-bottom: 8px;
  font-size: 13px;
  border: 1px solid transparent;
}

.flash-success {
  background: #e8f5ed;
  color: #174b2a;
  border-color: #bfdcc9;
}

.flash-error {
  background: #fbebeb;
  color: #7b2020;
  border-color: #efc7c7;
}

/* Forms */
.form-group,
.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.form-row,
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.field-grid.three { grid-template-columns: 1.15fr .85fr .85fr; }

.form-group label,
.field label,
label {
  color: #4c5567;
  font-size: 12px;
  font-weight: 650;
}

.form-label-row,
.section-head,
.items-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

input[type=text],
input[type=password],
input[type=date],
input[type=file],
textarea,
select {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid #cbd1dc;
  border-radius: 4px;
  background: #fff;
  color: #171a21;
  font: inherit;
}

textarea {
  min-height: 72px;
  line-height: 1.35;
  resize: vertical;
}

input[type=text]:focus,
input[type=password]:focus,
input[type=date]:focus,
input[type=file]:focus,
textarea:focus,
select:focus {
  outline: 2px solid #4d74d9;
  outline-offset: -1px;
  border-color: #4d74d9;
}

input:disabled,
textarea:disabled {
  background: #f0f2f5;
  color: #687386;
  cursor: default;
}

input[type=file] {
  padding: 6px 9px;
}

.narrow-form,
.inline-form { max-width: 680px; }

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { filter: brightness(.96); }

.btn-primary {
  color: #fff;
  background: #315dbe;
  border-color: #315dbe;
}

.btn-secondary,
.btn-small {
  color: #273043;
  background: #fff;
  border-color: #c9cfda;
}

.btn-danger {
  color: #fff;
  background: #b94141;
  border-color: #b94141;
}

.btn-small {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

.btn-tiny {
  min-height: 28px;
  padding: 4px 8px;
  color: #273043;
  background: #fff;
  border-color: #c9cfda;
  font-size: 12px;
}

.btn-icon {
  width: 32px;
  min-height: 32px;
  padding: 0;
  color: #6e7687;
  background: transparent;
  border: 1px solid #d4dae4;
  border-radius: 4px;
  cursor: pointer;
}

.btn-icon:hover {
  color: #9d2929;
  background: #fff;
  border-color: #d1a3a3;
}

/* Invoice workspace */
.invoice-workspace {
  display: grid;
  grid-template-columns: minmax(680px, 760px) minmax(420px, 1fr);
  gap: 24px;
  align-items: start;
}

.invoice-layout {
  display: grid;
  grid-template-columns: minmax(680px, 760px) minmax(420px, 1fr);
  gap: 24px;
  align-items: start;
}

/* Reisekosten form is wider, so give it more room; the preview still fills the
   rest as 1fr (flush, no gap), just a bit narrower than on the invoice page. */
.travel-workspace {
  grid-template-columns: minmax(680px, 1080px) minmax(340px, 1fr);
}

.hospitality-workspace {
  grid-template-columns: minmax(560px, 780px) minmax(340px, 1fr);
}

.editor,
.editor-col {
  min-width: 0;
  background: #fff;
  border: 1px solid #dfe3ea;
  border-radius: 6px;
}

.section {
  padding: 18px 20px;
  border-bottom: 1px solid #e6e9ef;
}

.section:last-child { border-bottom: 0; }

.section-title {
  margin: 0;
  color: #2b2f3a;
  font-size: 13px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.customer-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-top: 12px;
  padding: 11px 12px;
  background: #f7f8fb;
  border: 1px solid #e0e5ef;
  border-radius: 4px;
  color: #2d3340;
  line-height: 1.35;
}

.customer-name { font-weight: 700; }

.customer-address { white-space: pre-line; }

.customer-meta {
  color: #626c7f;
  font-size: 12px;
  white-space: nowrap;
}

.preview-col,
.preview {
  min-width: 0;
  position: sticky;
  top: 24px;
}

.preview-title,
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
  color: #4c5567;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.preview-placeholder {
  padding: 24px;
  background: #fff;
  border: 1px solid #dfe3ea;
  border-radius: 5px;
  color: #687386;
  font-size: 13px;
  text-align: center;
}

#preview-frame {
  width: 100%;
  border: 1px solid #d4d9e3;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 8px 26px rgba(31, 36, 50, .14);
}

/* Items */
.items-scroll { overflow-x: auto; }

.items-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  border: 1px solid #dfe3ea;
  background: #fbfcfe;
}

.items-table th {
  padding: 7px 6px;
  color: #596376;
  background: #f1f4f8;
  border-bottom: 1px solid #dfe3ea;
  font-size: 11px;
  font-weight: 750;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.items-table td {
  padding: 5px;
  border-bottom: 1px solid #e7ebf1;
  vertical-align: top;
}

.items-table tr:last-child td { border-bottom: 0; }

.items-table input {
  min-height: 31px;
  padding: 5px 7px;
  font-size: 13px;
}

.items-table .title-col { width: 25%; }
.items-table .desc-col { width: auto; }
.items-table .qty-col,
.items-table .col-narrow { width: 92px; }
.items-table .price-col { width: 112px; }
.items-table .vat-col,
.items-table .col-tiny { width: 66px; }
.items-table .action-col,
.items-table .col-action { width: 36px; }

.items-footer {
  display: flex;
  justify-content: flex-start;
  margin-top: 8px;
}

.totals-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  background: #fbfcfe;
}

.totals-display,
.totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  max-width: 520px;
}

.total,
.totals-display span {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid #dfe3ea;
  border-radius: 4px;
  background: #fff;
}

.total span,
.totals-display span {
  color: #687386;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.total strong,
.totals-display strong {
  color: #181818;
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
  text-transform: none;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  white-space: nowrap;
}

/* Data tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #dfe3ea;
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
}

.data-table th {
  padding: 8px 10px;
  color: #596376;
  background: #f1f4f8;
  border-bottom: 1px solid #dfe3ea;
  font-size: 11px;
  font-weight: 750;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e7ebf1;
  vertical-align: top;
}

.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: #fbfcfe; }
.data-table .num { text-align: right; white-space: nowrap; }
.data-table .action-col { white-space: nowrap; display: flex; gap: 6px; }

.edit-row td,
.delete-confirm-row td {
  background: #fbfcfe;
  padding: 16px;
  border-bottom: 1px solid #dfe3ea;
}

.delete-confirm-row .warn-text {
  color: #8e2d2d;
  margin-right: 12px;
}

/* Reisekosten */
.travel-editor {
  max-width: 1120px;
}

.hospitality-editor {
  max-width: 780px;
}

.travel-table {
  min-width: 980px;
  table-layout: fixed;
}

.travel-table select,
.travel-table input {
  width: 100%;
  min-width: 0;
  min-height: 30px;
  padding: 5px 6px;
  font-size: 12px;
}

.travel-table col.travel-kind-col,
.travel-table .travel-kind-col { width: 160px; }
.travel-table col.travel-expense-kind-col,
.travel-table .travel-expense-kind-col { width: 190px; }
.travel-table col.travel-description-col { width: 230px; }
.travel-table col.travel-count-col,
.travel-table .travel-count-col { width: 74px; }
.travel-table col.travel-country-col,
.travel-table .travel-country-col { width: 145px; }
.travel-table col.travel-rate-col,
.travel-table .travel-rate-col { width: 96px; }
.travel-table col.travel-amount-col,
.travel-table .travel-amount-col { width: 106px; }
.travel-table col.travel-total-col,
.travel-table .travel-total-col { width: 106px; }

.travel-form-table {
  min-width: 960px;
  table-layout: fixed;
}

.travel-form-table col.travel-label-col { width: 35%; }
.travel-form-table col.travel-input-col { width: 35%; }
.travel-form-table col.travel-money-col { width: 10%; }

.travel-form-table input {
  width: 100%;
  min-width: 0;
  min-height: 30px;
  padding: 5px 6px;
  font-size: 12px;
}

.travel-form-table th {
  white-space: nowrap;
}

/* Eintaegige vs. mehrtaegige Reise: the inactive side is disabled and greyed. */
.travel-editor .mode-inactive,
.travel-editor .mode-inactive .muted,
.travel-editor .mode-inactive .section-title {
  color: #abb2bc;
}

.travel-editor .mode-inactive input,
.travel-editor .mode-inactive textarea,
.travel-editor .mode-inactive .travel-money-output {
  background: #f1f3f6;
  color: #abb2bc;
}

.inline-calc {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-calc input {
  max-width: 82px;
}

.travel-money-output {
  display: block;
  min-height: 30px;
  padding: 6px 7px;
  border: 1px solid #d6dce6;
  border-radius: 4px;
  background: #f7f9fc;
  white-space: nowrap;
}

.travel-rate-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.travel-rate-current {
  color: #596376;
  font-size: 12px;
}

.travel-rate-label,
.travel-line-total {
  display: block;
  min-height: 30px;
  padding: 6px 7px;
  border: 1px solid #d6dce6;
  border-radius: 4px;
  background: #f7f9fc;
  text-align: right;
  white-space: nowrap;
}

.travel-country-picker {
  display: grid;
  gap: 4px;
}

.travel-country-current {
  color: #596376;
  font-size: 11px;
  line-height: 1.2;
}

.receipt-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.receipt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid #dfe3ea;
  border-radius: 4px;
  background: #fbfcfe;
}

.receipt-preview-stack {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.receipt-preview-item {
  margin: 0;
  padding: 10px;
  background: #fff;
  border: 1px solid #d4d9e3;
  border-radius: 5px;
  box-shadow: 0 8px 26px rgba(31, 36, 50, .10);
}

.receipt-preview-item img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
}

.receipt-preview-item figcaption {
  margin-top: 6px;
  color: #687386;
  font-size: 12px;
  word-break: break-word;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 24, 34, 0.48);
}

.modal-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #dfe3ea;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 15px;
}

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

/* Company signatures */
.signature-header {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 32px;
  margin-bottom: 10px;
}

.signature-list { max-width: 680px; }

.signature-row-label {
  display: flex;
  align-items: center;
  gap: 12px;
}

.signature-thumb {
  height: 30px;
  max-width: 160px;
  padding: 2px 6px;
  background: #fff;
  border: 1px solid #dfe3ea;
  border-radius: 4px;
}

.signature-modal-panel { width: min(560px, 100%); }

#signature-form {
  display: grid;
  gap: 14px;
}

.signature-canvas {
  width: 100%;
  height: 180px;
  background: #fff;
  border: 1px dashed #b9c0cd;
  border-radius: 4px;
  touch-action: none;
  cursor: crosshair;
}

/* Misc */
.info-box {
  padding: 14px 16px;
  background: #eef4ff;
  border: 1px solid #cddbf5;
  border-radius: 5px;
  font-size: 13px;
}

.muted { color: #687386; }
.small { font-size: 12px; }

.section-divider {
  border: 0;
  border-top: 1px solid #dfe3ea;
  margin: 24px 0;
}

h4 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 650;
}

/* The travel editor is much wider (~960px of fixed table), so it needs to drop
   to a single column much earlier than the invoice form. */
@media (max-width: 1650px) {
  .travel-workspace {
    grid-template-columns: 1fr;
  }

  .travel-workspace .preview-col {
    position: static;
  }
}

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

  .preview-col,
  .preview {
    position: static;
  }
}

@media (max-width: 780px) {
  body { display: block; }

  .sidebar {
    width: auto;
    min-width: 0;
    height: auto;
    position: static;
  }

  .main-content { padding: 18px; }

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

  .form-row,
  .field-grid,
  .field-grid.three,
  .customer-summary,
  .totals-actions,
  .totals-display,
  .totals {
    grid-template-columns: 1fr;
  }

  .items-table { min-width: 640px; }

  .actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .actions .btn,
  .form-actions .btn {
    width: 100%;
  }

  .preview-col { display: none; }
}

/* Inline customer save feedback */
.form-msg { font-size: 0.85rem; margin-left: 0.5rem; }
.msg-success { color: #2a7a2a; }
.msg-error   { color: #c0392b; }
