:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e5e8f0;
  --text: #1f2430;
  --muted: #8a92a6;
  --primary: #4f6bed;
  --primary-hover: #3f57d6;
  --primary-soft: #eef1fe;
  --success: #16a34a;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 8px 24px rgba(20, 30, 60, 0.06);
  font-family:
    "Inter",
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  gap: 20px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 28px 24px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.history-panel {
  position: sticky;
  top: 28px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.panel-head h1 {
  font-size: 20px;
  margin: 0;
}
.panel-head h2 {
  font-size: 16px;
  margin: 0;
}
.panel-head p {
  margin: 4px 0 0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}
.req {
  color: var(--danger);
}

/* ---- Form fields ---- */
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  margin-bottom: 24px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-full {
  grid-column: 1 / -1;
}
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: #4b5266;
}

input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input::placeholder {
  color: #b7bdcc;
}

#customerName,
#phone {
  width: 300px;
}
#email,
#address {
  width: 550px;
}

/* ---- Items table ---- */
.items-section {
  margin-bottom: 22px;
}
.items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.items-head h2 {
  font-size: 15px;
  margin: 0;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 10px;
  background: #fafbfe;
  border-bottom: 1px solid var(--border);
}
th.num,
td.num {
  text-align: right;
}
th.center,
td.center {
  text-align: center;
}
tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid #f1f3f9;
  vertical-align: middle;
}
tbody input {
  padding: 7px 9px;
  border-radius: 8px;
}
tbody input.num {
  text-align: right;
}
.cell-subtotal {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: #4b5266;
}

td:has(.cell-sku) {
  width: 25%;
}
td:has(.cell-price) {
  width: 90px;
}
td:has(.cell-qty) {
  width: 70px;
}
td:has(.cell-condition) {
  width: 100px;
}

.btn-del {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  transition:
    background 0.15s,
    color 0.15s;
}
.btn-del:hover {
  background: #fdeaea;
  color: var(--danger);
}

tfoot td {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  font-weight: 600;
}
.total-label {
  text-align: right;
  color: var(--muted);
}
.total-value {
  font-size: 15px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---- Buttons ---- */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 10px 16px;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.05s;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--primary);
}
.btn-ghost:hover {
  background: var(--primary-soft);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 15px;
}
.actions {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

/* ---- Currency selector ---- */
.currency-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.currency-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: #4b5266;
}
.currency-field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
  min-width: 100px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.currency-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- Result ---- */
.result {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 13.5px;
}
.result.success {
  background: #ecfdf3;
  border: 1px solid #b6f0cc;
  color: #0f7a3d;
}
.result.error {
  background: #fef2f2;
  border: 1px solid #fbcaca;
  color: #b42323;
}
.result a {
  color: var(--primary);
  font-weight: 600;
  word-break: break-all;
}
.result .link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

/* ---- History ---- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 72vh;
  overflow-y: auto;
}
.history-list .empty {
  text-align: center;
  padding: 24px 0;
}
.hist-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.hist-item:hover {
  border-color: #cdd5f5;
  box-shadow: 0 2px 8px rgba(20, 30, 60, 0.05);
}
.hist-item.clickable {
  cursor: pointer;
}
.hist-item.clickable:hover {
  border-color: var(--primary);
}
.hist-item.clickable:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.hist-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.hist-name {
  font-weight: 600;
}
.hist-total {
  color: var(--primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hist-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.hist-actions {
  margin-top: 8px;
}
.hist-link {
  font-size: 12.5px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.hist-link:hover {
  text-decoration: underline;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .history-panel {
    position: static;
  }
  .field-grid {
    grid-template-columns: 1fr;
  }
}
