:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1c1f26;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --pending-bg: #fef3c7;
  --pending-ink: #92400e;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--ink);
  color: white;
  padding: 14px 16px 0 16px;
}
.topbar h1 {
  margin: 0 0 10px 0;
  font-size: 20px;
}
.tabs {
  display: flex;
  gap: 4px;
}
.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.65);
  padding: 10px 8px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
.tab-btn.active {
  color: white;
  border-bottom-color: var(--accent);
}

main { padding: 12px; max-width: 720px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.icon-btn {
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
}

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

.order-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.order-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.order-name {
  font-weight: 700;
  font-size: 15px;
}
.order-number {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.order-address {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}
.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-pending { background: var(--pending-bg); color: var(--pending-ink); }
.status-delivered { background: var(--ok-bg); color: var(--ok); }
.status-failed { background: var(--bad-bg); color: var(--bad); }

.import-box {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.import-box p { color: var(--muted); font-size: 14px; }
#importStatus { margin-top: 10px; font-size: 13px; color: var(--muted); }

#reviewArea { margin-top: 16px; }
.review-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.review-table th, .review-table td {
  border-bottom: 1px solid var(--border);
  padding: 6px;
  text-align: left;
}
.review-table input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  padding: 4px;
  border-radius: 6px;
}
.review-table input:focus {
  border-color: var(--accent);
  background: white;
  outline: none;
}
.review-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  justify-content: flex-end;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
button.danger {
  background: var(--bad-bg);
  color: var(--bad);
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
.row-remove {
  color: var(--bad);
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.log-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.log-entry-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
}
.log-entry-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.log-entry-note {
  font-size: 13px;
  margin-top: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  border: none;
  background: var(--bg);
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.modal h2 { margin: 0 0 4px 0; font-size: 18px; padding-right: 30px; }
.modal .field { margin: 10px 0; font-size: 14px; }
.modal .field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 2px;
}
.modal textarea {
  width: 100%;
  min-height: 70px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.modal-actions button { flex: 1; }
.modal-history {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.modal-history h3 { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
}
.toast.hidden { display: none; }
