:root {
  --brand-red: #b62d38;
  --brand-red-dark: #8f2029;
  --ink: #20242a;
  --muted: #66707c;
  --line: #d9dde3;
  --soft: #f5f6f8;
  --panel: #ffffff;
  --success: #197057;
  --warning: #9d6a10;
  --danger: #a82b34;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #eef0f3;
  color: var(--ink);
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover { border-color: #b8bec7; }

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.primary {
  border-color: var(--brand-red);
  background: var(--brand-red);
  color: #fff;
}

.primary:hover {
  border-color: var(--brand-red-dark);
  background: var(--brand-red-dark);
}

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 30px;
  box-shadow: 0 16px 45px rgba(25, 28, 34, 0.12);
}

.login-logo {
  width: 260px;
  max-width: 100%;
  display: block;
  margin: 0 auto 24px;
}

.login-panel h1 {
  margin: 0 0 22px;
  text-align: center;
  font-size: 24px;
}

.login-form { display: grid; gap: 14px; }

.form-link {
  justify-self: center;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 10px;
}

input[disabled], textarea[disabled] {
  background: #f2f3f5;
  color: #505761;
}

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

.form-grid label.excel-textarea {
  justify-self: start;
  width: min(100%, 86ch);
}

.form-grid label.excel-textarea textarea {
  line-height: 1.35;
}

.choice-field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
}

.choice-field legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.choice-kind {
  width: max-content;
  border-radius: 999px;
  background: #eef0f3;
  color: #4f5965;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.choice-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
}

.choice-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-chip span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-left: 4px solid transparent;
  font-size: 12px;
  line-height: 1.15;
  white-space: nowrap;
}

.choice-chip input:checked + span {
  color: #111;
  font-weight: 700;
  box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.46);
}

.choice-chip input:focus-visible + span {
  outline: 2px solid rgba(52, 93, 140, 0.35);
  outline-offset: -2px;
}

.choice-empty span { border-left-color: #9aa3ad; }
.choice-color-1 span { border-left-color: #b62d38; background: #fff1f2; }
.choice-color-2 span { border-left-color: #345d8c; background: #eef5ff; }
.choice-color-3 span { border-left-color: #197057; background: #edf8f3; }
.choice-color-4 span { border-left-color: #9d6a10; background: #fff7e8; }
.choice-color-5 span { border-left-color: #7a4ea3; background: #f6f0fb; }
.choice-color-6 span { border-left-color: #c4581b; background: #fff2ea; }
.choice-color-7 span { border-left-color: #4c7780; background: #edf7f8; }
.choice-color-8 span { border-left-color: #5c6670; background: #f2f4f6; }

.material-block {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
}

.material-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.material-block-head span {
  font-weight: 700;
  color: var(--ink);
}

.material-block-head small {
  color: var(--muted);
}

.material-row {
  display: grid;
  grid-template-columns: minmax(88px, 112px) minmax(240px, 1fr) minmax(150px, 180px);
  gap: 10px;
  align-items: end;
}

.material-row.hidden {
  display: none;
}

.material-row .material-check {
  min-height: 36px;
  align-content: center;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid rgba(52, 93, 140, 0.35);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 18px 14px;
}

.brand {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 52px;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.brand span {
  font-weight: 700;
  line-height: 1.1;
}

.nav { display: grid; gap: 6px; }

.nav-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 40px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.nav-item.active {
  border-color: rgba(182, 45, 56, 0.22);
  background: rgba(182, 45, 56, 0.08);
  color: var(--brand-red-dark);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--brand-red-dark);
  font-size: 12px;
  font-weight: 700;
}

.user-panel {
  margin-top: auto;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.user-panel strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #33383f;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.link-button {
  border: 0;
  min-height: auto;
  padding: 0;
  color: var(--brand-red-dark);
  background: transparent;
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-red-dark);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar h1, .record-form h2 {
  margin: 0;
  font-size: 24px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
}

.search { min-width: min(280px, 100%); }
.select { width: 112px; }
.sort-direction { width: 132px; }

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-row article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.summary-row span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.summary-row strong { font-size: 22px; }

.notice, .form-error, .form-info {
  border: 1px solid rgba(168, 43, 52, 0.25);
  border-radius: 6px;
  background: rgba(168, 43, 52, 0.08);
  color: var(--danger);
  padding: 10px 12px;
}

.form-info {
  border-color: rgba(25, 112, 87, 0.25);
  background: rgba(25, 112, 87, 0.09);
  color: var(--success);
  overflow-wrap: anywhere;
}

.form-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.form-help.wide {
  grid-column: 1 / -1;
}

.notice {
  margin-bottom: 12px;
  color: var(--ink);
  border-color: rgba(157, 106, 16, 0.25);
  background: rgba(157, 106, 16, 0.1);
}

.home-view {
  display: grid;
  gap: 18px;
}

.home-hero {
  position: relative;
  min-height: clamp(360px, 55vh, 620px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151a20;
}

.home-hero-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.home-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.72) 39%, rgba(255, 255, 255, 0.14) 72%);
}

.home-hero-overlay {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  max-width: 680px;
  min-height: inherit;
  padding: clamp(26px, 6vw, 72px);
}

.home-logo {
  width: min(360px, 70vw);
  margin-bottom: 28px;
}

.home-hero h2 {
  max-width: 620px;
  margin: 0;
  color: var(--brand-red-dark);
  font-size: clamp(34px, 5.5vw, 72px);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 0.95;
}

.home-hero p {
  max-width: 520px;
  margin: 18px 0 0;
  color: #333941;
  font-size: clamp(15px, 1.6vw, 22px);
  line-height: 1.45;
}

.home-fly-in {
  position: absolute;
  z-index: 2;
  right: clamp(18px, 5vw, 74px);
  bottom: clamp(18px, 5vw, 54px);
  width: min(42vw, 560px);
  min-width: 220px;
  border: 8px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(18, 24, 30, 0.36);
  object-fit: cover;
  transform-origin: 80% 80%;
  animation: homeFlyIn 900ms cubic-bezier(0.16, 1, 0.3, 1) 160ms both;
}

.home-gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 180px;
  gap: 14px;
}

.home-tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  margin: 0;
}

.home-tile.tall {
  grid-row: span 2;
}

.home-tile.wide {
  grid-column: span 2;
}

.home-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 220ms ease;
}

.home-tile:hover img {
  transform: scale(1.035);
}

.home-tile figcaption {
  position: absolute;
  left: 12px;
  bottom: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 9px;
}

@keyframes homeFlyIn {
  from {
    opacity: 0;
    transform: translate3d(34vw, -18vh, 0) rotate(2.5deg) scale(0.86);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  }
}

.table-wrap {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 220px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.table-top-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  height: 16px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--panel);
}

.table-top-scroll + .table-wrap {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

#tableTopScrollContent {
  height: 1px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
}

body[data-view="orders"] table { min-width: 2360px; }
body[data-view="sheets"] table { min-width: 3680px; }
body[data-view="customers"] table { min-width: 1220px; }
body[data-view="contacts"] table { min-width: 980px; }

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8f9fb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafbfc; }

body[data-view="orders"] .sticky-col,
body[data-view="sheets"] .sticky-col {
  position: sticky;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
}

body[data-view="orders"] th.sticky-col,
body[data-view="sheets"] th.sticky-col {
  background: #f8f9fb;
  z-index: 7;
}

body[data-view="orders"] td.sticky-col,
body[data-view="sheets"] td.sticky-col {
  z-index: 4;
}

body[data-view="orders"] .sticky-col-1,
body[data-view="sheets"] .sticky-col-1 {
  left: 0;
  width: 120px;
  min-width: 120px;
  max-width: 120px;
}

body[data-view="orders"] .sticky-col-2,
body[data-view="sheets"] .sticky-col-2 {
  left: 120px;
  width: 220px;
  min-width: 220px;
  max-width: 220px;
}

body[data-view="orders"] tbody tr:hover td.sticky-col,
body[data-view="sheets"] tbody tr:hover td.sticky-col {
  background: #fafbfc;
}

.inline-edit {
  width: 100%;
  min-width: 88px;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.inline-edit.money {
  text-align: right;
}

.inline-edit:hover {
  border-color: #d4d9e1;
}

.inline-edit:focus {
  outline: 2px solid rgba(176, 37, 48, 0.18);
  border-color: var(--brand-red);
}

.inline-edit.is-saving {
  color: var(--muted);
  background: #f3f5f7;
}

.inline-edit.is-error {
  border-color: var(--danger);
  background: rgba(168, 43, 52, 0.08);
}

.inline-check-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 30px;
}

.inline-check {
  width: 18px;
  min-height: 18px;
  padding: 0;
  cursor: pointer;
}

.group-row td {
  background: #f0f2f5;
  color: var(--brand-red-dark);
  font-weight: 700;
  cursor: default;
}

.status, .file-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.status.open, .file-pill {
  background: rgba(52, 93, 140, 0.11);
  color: #244b75;
}

.status.done {
  background: rgba(25, 112, 87, 0.11);
  color: var(--success);
}

.status.warn {
  background: rgba(157, 106, 16, 0.13);
  color: var(--warning);
}

.status.error {
  background: rgba(168, 43, 52, 0.11);
  color: var(--danger);
}

.inline-action {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  white-space: nowrap;
}

.danger-action {
  border-color: rgba(168, 43, 52, 0.35);
  color: var(--danger);
  background: rgba(168, 43, 52, 0.08);
}

.danger-action:hover {
  border-color: var(--danger);
  background: rgba(168, 43, 52, 0.13);
}

.completion-button {
  border-color: rgba(25, 112, 87, 0.28);
  color: var(--success);
  background: rgba(25, 112, 87, 0.08);
}

.completion-button:disabled {
  border-color: #d3d7dd;
  color: #68707a;
  background: #eef0f3;
  opacity: 1;
}

.empty-state {
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

.statistics-view {
  display: grid;
  gap: 16px;
}

.stats-loading,
.stats-intro,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stats-loading {
  padding: 26px;
  color: var(--muted);
}

.stats-intro {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
}

.stats-intro strong {
  color: var(--ink);
}

.stats-grid {
  display: grid;
  gap: 16px;
}

.stat-card {
  overflow: hidden;
}

.stat-card-wide {
  grid-column: 1 / -1;
}

.stat-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.stat-card-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.stat-card-header span {
  color: var(--muted);
  font-size: 13px;
}

.stat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
}

.stat-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stat-legend i {
  display: inline-block;
  width: 24px;
  height: 3px;
  border-radius: 999px;
}

.legend-orders { background: var(--brand-red); }
.legend-circulation { background: #245f8f; }
.bar-legend {
  height: 10px !important;
}
.bar-year-0 { fill: var(--brand-red); background: var(--brand-red); }
.bar-year-1 { fill: #245f8f; background: #245f8f; }
.bar-year-2 { fill: #6f7680; background: #6f7680; }

.profit-bars {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.profit-row {
  display: grid;
  grid-template-columns: 28px minmax(150px, 260px) minmax(120px, 1fr) minmax(96px, max-content);
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.profit-rank {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.profit-label {
  overflow: hidden;
  color: var(--ink);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profit-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9edf1;
}

.profit-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-red);
}

.revenue-card .profit-fill {
  background: #245f8f;
}

.profit-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

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

.stat-chart {
  display: block;
  width: 100%;
  height: auto;
  padding: 10px 12px 0;
}

.chart-grid {
  stroke: #e3e6eb;
  stroke-width: 1;
}

.chart-axis {
  stroke: #9aa2ad;
  stroke-width: 1;
}

.line-orders,
.line-circulation {
  fill: none;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.line-orders { stroke: var(--brand-red); }
.line-circulation { stroke: #245f8f; }

.dot-orders { fill: var(--brand-red); }
.dot-circulation { fill: #245f8f; }

.chart-month,
.chart-scale {
  fill: var(--muted);
  font-size: 12px;
}

.chart-month {
  text-anchor: middle;
}

.chart-scale-right {
  text-anchor: end;
}

.stat-month-table {
  min-width: 740px;
  border-top: 1px solid var(--line);
}

.stat-month-table th,
.stat-month-table td {
  max-width: none;
  padding: 8px 12px;
  font-size: 12px;
}

.management-dashboard {
  display: grid;
  gap: 14px;
}

.management-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.management-check {
  display: flex;
  min-height: 36px;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.management-check input {
  width: 18px;
  min-height: 18px;
}

.management-active-filters,
.management-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

.management-active-filters strong,
.management-rules strong {
  color: var(--ink);
}

.management-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.management-tabs button.active {
  border-color: rgba(182, 45, 56, 0.22);
  background: rgba(182, 45, 56, 0.08);
  color: var(--brand-red-dark);
  font-weight: 700;
}

.management-content {
  display: grid;
  gap: 14px;
}

.management-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.management-kpi {
  display: grid;
  gap: 6px;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 13px;
}

.management-kpi span,
.management-kpi small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.management-kpi strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1.15;
}

.management-grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.management-table-card {
  min-width: 0;
}

.management-table-wrap {
  overflow: auto;
  max-height: min(620px, calc(100vh - 260px));
}

.management-table {
  min-width: 1180px;
}

.management-table th,
.management-table td {
  max-width: 220px;
  padding: 8px 10px;
  font-size: 12px;
}

.management-chart-legend {
  padding: 12px 16px 0;
  justify-content: flex-start;
}

.profit-fill.negative {
  background: var(--danger);
}

.management-notes {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.management-notes span {
  border-left: 4px solid var(--brand-red);
  background: #fafbfc;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 13px;
}

.record-dialog {
  width: min(860px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(25, 28, 34, 0.22);
}

.small-dialog {
  width: min(540px, calc(100% - 32px));
}

.record-dialog::backdrop { background: rgba(22, 25, 30, 0.42); }

.record-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 34px);
}

.record-form header, .record-form footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  background: var(--panel);
}

.record-form header { border-bottom: 1px solid var(--line); }
.record-form footer { border-top: 1px solid var(--line); }

.icon-button {
  width: 36px;
  padding: 0;
}

.form-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-color: #9aa3ad #eef0f3;
  scrollbar-width: auto;
}

.form-grid::-webkit-scrollbar {
  width: 16px;
}

.form-grid::-webkit-scrollbar-track {
  background: #eef0f3;
}

.form-grid::-webkit-scrollbar-thumb {
  border: 3px solid #eef0f3;
  border-radius: 999px;
  background: #9aa3ad;
}

.form-grid::-webkit-scrollbar-thumb:hover {
  background: #77818d;
}

.form-grid label.wide,
.form-grid .wide { grid-column: 1 / -1; }

.link-field {
  display: grid;
  gap: 8px;
}

.quick-create {
  display: grid;
  gap: 8px;
}

.quick-create-toggle {
  justify-self: start;
}

.quick-create-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}

.quick-create-panel.hidden {
  display: none;
}

.quick-create-warning {
  grid-column: 1 / -1;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #f0d6a8;
  border-radius: 6px;
  background: #fff8e8;
  color: #73530d;
  font-size: 12px;
  font-weight: 700;
}

.quick-create-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.checkbox-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--ink);
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.record-actions, .footer-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.form-error {
  margin: 0 18px 12px;
}

.record-form > .form-info {
  margin: 0 18px 12px;
}

.user-list {
  padding: 0 18px 18px;
}

.user-list-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.user-list-header strong {
  color: var(--ink);
}

.mini-table {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.mini-table th,
.mini-table td {
  max-width: none;
  padding: 8px 10px;
  font-size: 12px;
}

.search-results {
  display: grid;
  gap: 10px;
}

.search-result {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 13px 14px;
}

.search-result-title {
  justify-self: start;
  color: var(--brand-red-dark);
  font-size: 15px;
  font-weight: 700;
}

.search-result span,
.search-result p,
.muted-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.portal-extra {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  padding: 14px;
}

.portal-extra-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.portal-extra-head strong,
.extra-block h3 {
  color: var(--ink);
}

.portal-extra-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.order-extra-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.extra-block,
.qr-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.extra-block h3 {
  margin: 0;
  font-size: 16px;
}

.qr-panel {
  grid-template-columns: 116px minmax(0, 1fr);
  align-items: center;
}

.qr-panel img {
  width: 108px;
  height: 108px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 6px;
}

.qr-panel div {
  display: grid;
  gap: 8px;
}

.customer-note {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-left: 5px solid #9aa3ad;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.customer-note.priority-wichtig { border-left-color: var(--warning); }
.customer-note.priority-kritisch { border-left-color: var(--danger); }
.customer-note.needs-ack { background: #fff8e8; }
.customer-note.is-archived { opacity: 0.68; }

.customer-note div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.customer-note p {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
  white-space: pre-wrap;
}

.photo-upload,
.feedback-form,
.note-create {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.photo-upload .wide,
.feedback-form .wide,
.note-create .wide {
  grid-column: 1 / -1;
}

.photo-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.photo-item {
  display: grid;
  gap: 8px;
  margin: 0;
  min-width: 0;
}

.photo-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #eef0f3;
}

.photo-item figcaption {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

.photo-item figcaption strong {
  color: var(--ink);
}

.feedback-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.feedback-list li {
  color: var(--ink);
  font-size: 13px;
}

.feedback-list span {
  color: var(--muted);
  font-size: 12px;
}

.mandatory-notes {
  display: grid;
  gap: 10px;
  max-height: min(60vh, 520px);
  overflow: auto;
  padding: 18px;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
  .nav-item {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
  .topbar-actions { justify-content: stretch; }
  .topbar-actions > * { flex: 1 1 180px; }
  .summary-row, .form-grid { grid-template-columns: 1fr; }
  .management-filters,
  .management-kpi-grid,
  .management-grid-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .material-row {
    grid-template-columns: 1fr;
  }
  .material-block-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .order-extra-grid,
  .photo-upload,
  .feedback-form,
  .note-create,
  .photo-list {
    grid-template-columns: 1fr;
  }
  .qr-panel {
    grid-template-columns: 96px minmax(0, 1fr);
  }
  .qr-panel img {
    width: 88px;
    height: 88px;
  }
  .home-hero {
    min-height: 640px;
  }
  .home-hero::after {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.78) 48%, rgba(255, 255, 255, 0.08));
  }
  .home-hero-overlay {
    align-content: start;
    min-height: 0;
  }
  .home-fly-in {
    right: 18px;
    bottom: 18px;
    width: min(72vw, 460px);
  }
  .home-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .workspace { padding: 14px; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-hero {
    min-height: 600px;
  }
  .home-logo {
    width: min(260px, 82vw);
  }
  .home-fly-in {
    width: calc(100% - 36px);
    min-width: 0;
  }
  .home-gallery {
    grid-template-columns: 1fr;
    grid-auto-rows: 190px;
  }
  .home-tile.tall,
  .home-tile.wide {
    grid-column: auto;
    grid-row: auto;
  }
  .profit-row {
    grid-template-columns: 24px minmax(0, 1fr) minmax(82px, max-content);
  }
  .profit-track {
    grid-column: 2 / -1;
  }
  .management-filters,
  .management-kpi-grid,
  .management-grid-two {
    grid-template-columns: 1fr;
  }
  .management-tabs button {
    flex: 1 1 150px;
  }
}

@media print {
  .sidebar,
  .topbar-actions,
  .management-tabs,
  .management-filters button {
    display: none !important;
  }
  .app-shell {
    display: block;
  }
  .workspace {
    padding: 0;
  }
  .management-table-wrap,
  .table-wrap {
    max-height: none;
    overflow: visible;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-fly-in {
    animation: none;
  }
  .home-tile img {
    transition: none;
  }
}
