:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1c241f;
  --muted: #647067;
  --line: #dfe5df;
  --brand: #0f7b63;
  --brand-dark: #095f4c;
  --accent: #d84f2a;
  --soft: #edf7f3;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(22, 33, 27, 0.09);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(10px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 3vw, 2.1rem);
}

h2 {
  font-size: 1.2rem;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  padding: 22px clamp(16px, 4vw, 42px) 42px;
}

.order-panel,
.summary-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.order-panel {
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.search {
  flex: 1 1 320px;
}

.store-field {
  flex: 0 1 280px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 123, 99, 0.22);
  border-color: var(--brand);
}

input:disabled,
select:disabled {
  color: #8b948d;
  background: #f0f2ef;
  cursor: not-allowed;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

.supplier-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--muted);
  background: #f3f5f1;
  font-weight: 700;
}

.tab.active {
  color: #fff;
  background: var(--brand);
}

.product-list {
  display: grid;
  gap: 1px;
  background: var(--line);
}

.supplier-title {
  padding: 14px 18px;
  background: var(--soft);
  color: var(--brand-dark);
  font-weight: 800;
}

.product-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px 118px 116px;
  gap: 12px;
  align-items: center;
  min-height: 70px;
  padding: 12px 18px;
  background: #fff;
}

.order-lock {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  color: var(--brand-dark);
  background: var(--soft);
}

.product-name {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.product-name strong {
  overflow-wrap: anywhere;
}

.product-name span,
.money-muted {
  color: var(--muted);
  font-size: 0.86rem;
}

.last-order {
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.last-order.empty {
  color: var(--danger);
}

.qty-control {
  display: grid;
  grid-template-columns: 34px minmax(52px, 1fr) 34px;
  gap: 6px;
  align-items: center;
}

.stepper,
.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--ink);
  background: #eef1ed;
  font-weight: 800;
}

.qty-input {
  min-height: 34px;
  padding: 4px 6px;
  text-align: center;
}

.line-total {
  text-align: right;
  font-weight: 800;
}

.summary-panel {
  position: sticky;
  top: 96px;
  align-self: start;
  padding: 18px;
}

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

.summary-header strong {
  font-size: 1.35rem;
  color: var(--brand-dark);
}

.summary-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

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

.primary,
.ghost,
.danger,
.admin-actions button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.primary {
  width: 100%;
  color: #fff;
  background: var(--brand);
}

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

.ghost {
  color: var(--brand-dark);
  background: #e6f2ee;
}

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

.note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

dialog {
  width: min(1080px, calc(100vw - 24px));
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.28);
}

#reviewDialog {
  height: min(92vh, 840px);
}

dialog::backdrop {
  background: rgba(10, 15, 12, 0.44);
}

.admin-modal {
  padding: 18px;
}

.review-modal {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  height: 100%;
  min-height: 0;
  padding: 18px;
  overflow: hidden;
}

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

.pin-gate {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px;
  gap: 12px;
  align-items: end;
  padding-top: 18px;
}

.admin-content {
  display: grid;
  gap: 16px;
  padding-top: 18px;
}

.admin-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
}

.admin-step {
  min-height: 42px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.admin-step.active {
  color: #fff;
  background: var(--brand);
}

.admin-section {
  display: grid;
  gap: 14px;
}

.section-copy {
  display: grid;
  gap: 4px;
}

.section-copy h3 {
  margin: 0;
  font-size: 1.05rem;
}

.section-copy p {
  color: var(--muted);
  line-height: 1.4;
}

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

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

.admin-table-wrap {
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.admin-table th {
  position: sticky;
  top: 0;
  background: #f7faf7;
  color: var(--muted);
  text-align: left;
}

.admin-table input,
.admin-table select {
  min-height: 36px;
}

.remove-row {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--danger);
  background: #fff0ee;
  font-weight: 900;
}

.review-content {
  display: grid;
  gap: 10px;
}

.review-supplier {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.review-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--brand-dark);
  font-weight: 800;
}

.review-total strong {
  font-size: 1.2rem;
}

.review-supplier-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-dark);
  background: var(--soft);
  font-weight: 800;
}

.review-supplier-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--soft);
  color: var(--brand-dark);
  font-weight: 800;
}

.review-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 120px 120px;
  gap: 12px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  align-items: center;
}

.review-line span {
  color: var(--muted);
  font-size: 0.86rem;
}

.review-line-head {
  background: #fafcf9;
  font-weight: 800;
}

.review-line-head span {
  color: var(--brand-dark);
}

.review-line strong:last-child {
  text-align: right;
}

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

.history-filter {
  max-width: 360px;
}

.history-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.history-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}

.history-card summary::-webkit-details-marker {
  display: none;
}

.history-card summary span {
  display: grid;
  gap: 3px;
}

.history-summary-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.history-pdf,
.history-delete {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 10px;
  color: #fff;
  font-weight: 800;
}

.history-pdf {
  background: var(--brand);
}

.history-delete {
  background: var(--danger);
}

.history-card small {
  color: var(--muted);
}

.history-body {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.history-supplier {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.history-supplier header,
.history-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px 110px;
  gap: 10px;
  padding: 9px 10px;
  align-items: center;
}

.history-supplier header {
  color: var(--brand-dark);
  background: var(--soft);
  font-weight: 800;
}

.history-line {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.history-line span:first-child {
  color: var(--ink);
  font-weight: 700;
}

.history-line span:last-child,
.history-supplier header span:last-child {
  text-align: right;
}

.message-preview {
  color: var(--muted);
  min-height: 0;
}

.message-preview textarea {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  resize: none;
}

.review-actions {
  display: grid;
  grid-template-columns: 120px minmax(180px, 1fr);
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.review-actions .primary,
.admin-actions .primary {
  width: auto;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .product-row {
    grid-template-columns: 1fr;
  }

  .line-total {
    text-align: left;
  }

  .admin-grid,
  .lists-grid,
  .pin-gate,
  .admin-steps,
  .review-actions {
    grid-template-columns: 1fr;
  }

  .review-line,
  .history-supplier header,
  .history-line {
    grid-template-columns: 1fr;
  }

  .review-line strong:last-child,
  .history-line span:last-child,
  .history-supplier header span:last-child {
    text-align: left;
  }
}
