:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #d9e0e8;
  --text: #121826;
  --muted: #667085;
  --header: #101827;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f97316;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

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

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--primary);
}

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

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

th {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  background: var(--surface-2);
}

.app-header {
  background: var(--header);
  color: #fff;
}

.app-header__inner {
  width: min(1240px, calc(100% - 28px));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 12px 0;
}

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

.brand:hover {
  text-decoration: none;
}

.brand__mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background: #2563eb;
  color: #fff;
  font-weight: 800;
}

.brand small {
  display: block;
  color: #cbd5e1;
  font-size: 12px;
}

.main-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.main-nav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  color: #d7deea;
  border-radius: 6px;
}

.main-nav a.active,
.main-nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  text-decoration: none;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: #e5e7eb;
}

.user-menu em {
  color: #a7b0c0;
  font-style: normal;
  font-size: 12px;
}

.container {
  width: min(1600px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 42px;
}

.container--wide,
.container:has(.orders-sheet) {
  width: calc(100% - 20px);
  max-width: none;
}

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

.page-head h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: 0;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel,
.auth-card,
.confirmation-sheet,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel {
  padding: 16px;
  margin-bottom: 16px;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel__head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  background: #e7ecf2;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e7ecf2;
  color: #1f2937;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-sm {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.button-row,
.actions-bar,
.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

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

.alert {
  padding: 11px 13px;
  border-radius: 8px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: #fff;
}

.alert-success {
  color: #166534;
  background: #ecfdf3;
  border-color: #bbf7d0;
}

.alert-error {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

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

.form-grid,
.filters,
.settings-add {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.orders-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.orders-controls .filters {
  grid-template-columns: repeat(5, minmax(110px, 1fr)) auto;
}

.orders-controls .filters--admin {
  grid-template-columns: repeat(6, minmax(110px, 1fr)) auto;
}

.orders-controls select {
  min-width: 0;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: end;
  justify-content: flex-start;
}

.selection-actions {
  display: flex;
  gap: 8px;
  align-items: end;
  justify-content: flex-end;
  padding-bottom: 0;
}

.selection-actions form {
  margin: 0;
}

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

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

.field span {
  color: #374151;
  font-size: 12px;
  font-weight: 700;
}

.check {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #374151;
  font-size: 13px;
}

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

.auth-shell {
  min-height: calc(100vh - 130px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(420px, 100%);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.auth-card__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

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

.auth-card p,
.login-hint {
  margin: 0;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 16px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 5px;
  font-size: 25px;
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap.slim {
  max-height: 420px;
}

.summary-cell {
  min-width: 260px;
  font-size: 12px;
  color: #344054;
}

.excel-panel {
  padding: 0;
  overflow: hidden;
}

.orders-sheet {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: collapse;
  background: #fff;
  font-size: 12px;
}

.orders-sheet th,
.orders-sheet td {
  border-bottom: 1px solid #cbd5e1;
  border-right: 1px solid #d6dee8;
  padding: 7px 8px;
  vertical-align: middle;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
}

.orders-sheet th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  color: #344054;
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
  border-bottom-color: #b8c3d1;
}

.orders-sheet th::after {
  content: "";
}

.orders-sheet tbody tr:nth-child(even) {
  background: #fbfcfe;
}

.orders-sheet tbody tr:hover {
  background: #eef4ff;
}

.orders-sheet tbody tr.is-selected {
  background: #e8f0fe;
}

.orders-sheet th:nth-child(1),
.orders-sheet td:nth-child(1) {
  width: 4%;
}

.orders-sheet th:nth-child(2),
.orders-sheet td:nth-child(2) {
  width: 14%;
}

.orders-sheet th:nth-child(3),
.orders-sheet td:nth-child(3) {
  width: 12%;
}

.orders-sheet th:nth-child(4),
.orders-sheet td:nth-child(4) {
  width: 8%;
}

.orders-sheet th:nth-child(5),
.orders-sheet td:nth-child(5) {
  width: 8%;
}

.orders-sheet th:nth-child(6),
.orders-sheet td:nth-child(6) {
  width: 8%;
}

.orders-sheet th:nth-child(7),
.orders-sheet td:nth-child(7) {
  width: 13%;
}

.orders-sheet th:nth-child(8),
.orders-sheet td:nth-child(8) {
  width: 7%;
}

.orders-sheet th:nth-child(9),
.orders-sheet td:nth-child(9) {
  width: 18%;
}

.orders-sheet th:nth-child(10),
.orders-sheet td:nth-child(10) {
  width: 10%;
}

.sheet-green {
  background: transparent;
  color: var(--text);
  font-weight: 600;
}

.text-center {
  text-align: center;
}

.select-cell {
  text-align: center;
}

.select-cell input {
  width: 16px;
  min-height: 16px;
  cursor: pointer;
}

.money-cell {
  text-align: right;
  white-space: nowrap;
}

.order-link {
  color: #1f2937;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: #cbd5e1;
  text-underline-offset: 3px;
}

.position-highlight {
  background: transparent;
  color: var(--text);
  font-weight: 800;
}

.sheet-notes-cell {
  white-space: normal;
  text-align: left;
  color: #475467;
}

.sheet-actions {
  justify-content: center;
  gap: 4px;
  flex-wrap: nowrap;
}

.sheet-actions .btn {
  min-height: 30px;
  padding: 5px 7px;
  font-size: 11px;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e5e7eb;
  color: #374151;
}

.pill.paid {
  color: #166534;
  background: #dcfce7;
}

.pill.partial {
  color: #9a3412;
  background: #ffedd5;
}

.pill.unpaid {
  color: #991b1b;
  background: #fee2e2;
}

.customer-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  margin: 12px 0;
}

.order-items {
  display: grid;
  gap: 12px;
}

.order-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.order-item__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.order-item__top h3 {
  margin: 0;
  font-size: 15px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1.4fr);
  gap: 16px;
  align-items: start;
}

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

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

.settings-panel {
  min-width: 0;
}

.settings-panel--wide {
  grid-column: 1 / -1;
}

.settings-add {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 12px;
}

.settings-panel input,
.settings-panel select {
  min-width: 140px;
}

.settings-list {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.settings-list.slim {
  max-height: 420px;
  overflow-x: hidden;
}

.settings-list__head,
.settings-row {
  min-width: 680px;
  display: grid;
  gap: 8px;
  align-items: center;
}

.settings-list__head {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 0;
}

.settings-row {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
}

.settings-row--users {
  grid-template-columns: minmax(120px, 1fr) minmax(130px, 1fr) 100px 100px minmax(120px, 1fr) auto;
}

.settings-row--generic {
  min-width: 0;
  grid-template-columns: minmax(180px, 1fr) 90px 138px;
}

.settings-list__head.settings-row--generic {
  min-width: 0;
}

.settings-row--generic .table-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.settings-row--rules {
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.8fr) 110px 100px auto;
}

.confirmation-sheet {
  padding: 22px;
  max-width: 980px;
  margin: 0 auto;
}

.confirmation-head,
.confirmation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.confirmation-head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.confirmation-head span,
.kv,
.confirmation-grid p {
  color: #344054;
}

.confirmation-grid h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.confirmation-grid p {
  margin: 3px 0;
}

.sheet-line {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.confirmation-table th,
.confirmation-table td {
  font-size: 12px;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.sheet-notes {
  margin-top: 16px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sheet-notes p {
  margin: 6px 0 0;
}

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

@media (max-width: 980px) {
  .stats-grid,
  .settings-grid,
  .two-column,
  .orders-controls {
    grid-template-columns: 1fr;
  }

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

  .orders-controls .filters,
  .orders-controls .filters--admin {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .selection-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  body {
    font-size: 13px;
  }

  .app-header__inner,
  .container {
    width: calc(100% - 16px);
  }

  .app-header__inner {
    align-items: stretch;
    gap: 10px;
  }

  .brand,
  .user-menu {
    width: 100%;
  }

  .main-nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-nav a {
    justify-content: center;
    padding: 8px 6px;
  }

  .page-head {
    flex-direction: column;
  }

  .page-head > .btn,
  .page-head .button-row {
    width: 100%;
  }

  .page-head .btn,
  .button-row .btn {
    flex: 1 1 auto;
  }

  .confirmation-head,
  .confirmation-grid {
    grid-template-columns: 1fr;
  }

  .main-nav,
  .user-menu,
  .button-row,
  .actions-bar,
  .table-actions {
    justify-content: flex-start;
  }

  .form-grid,
  .filters,
  .settings-add,
  .form-grid.compact,
  .orders-controls .filters,
  .orders-controls .filters--admin {
    grid-template-columns: 1fr;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1 1 0;
  }

  .page-head h1 {
    font-size: 22px;
  }

  .panel {
    padding: 12px;
  }

  .orders-controls {
    gap: 14px;
  }

  .selection-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

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

  .selection-actions form {
    display: block;
  }

  .excel-panel {
    padding: 0;
    border: 0;
    background: transparent;
  }

  .table-wrap {
    overflow: visible;
  }

  .orders-sheet,
  .orders-sheet tbody,
  .orders-sheet tr,
  .orders-sheet td {
    display: block;
    width: 100% !important;
  }

  .orders-sheet {
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
    table-layout: auto;
  }

  .orders-sheet thead {
    display: none;
  }

  .orders-sheet tbody {
    display: grid;
    gap: 10px;
  }

  .orders-sheet tr {
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    overflow: hidden;
  }

  .orders-sheet tbody tr:nth-child(even) {
    background: #fff;
  }

  .orders-sheet tbody tr:hover,
  .orders-sheet tbody tr.is-selected {
    background: #eef4ff;
  }

  .orders-sheet td {
    min-height: 40px;
    display: grid !important;
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 9px 11px;
    border-right: 0;
    border-bottom: 1px solid #e2e8f0;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    text-align: left;
  }

  .orders-sheet td:last-child {
    border-bottom: 0;
  }

  .orders-sheet td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .orders-sheet .text-center,
  .orders-sheet .money-cell,
  .orders-sheet .sheet-notes-cell {
    text-align: left;
  }

  .orders-sheet .money-cell {
    white-space: normal;
  }

  .select-cell input {
    justify-self: start;
  }

  .order-link {
    overflow-wrap: anywhere;
  }

  .settings-list {
    overflow-x: visible;
  }

  .settings-list__head {
    display: none;
  }

  .settings-row,
  .settings-row--users,
  .settings-row--generic,
  .settings-row--rules {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .settings-row--generic .table-actions {
    justify-content: flex-start;
  }
}

@page {
  size: A4;
  margin: 12mm;
}

@media print {
  body {
    background: #fff;
    color: #000;
    font-size: 11px;
  }

  .app-header,
  .no-print,
  .alert,
  .btn,
  .actions-bar {
    display: none !important;
  }

  .container {
    width: 100%;
    padding: 0;
  }

  .confirmation-sheet {
    max-width: none;
    border: 0;
    padding: 0;
  }

  .confirmation-head h2 {
    font-size: 18px;
  }

  th,
  td {
    padding: 6px;
  }

  .sheet-notes {
    border: 1px solid #ddd;
  }
}
