:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --text: #2a2825;
  --text-muted: #8a8377;
  --border: #e7e2d8;
  --accent: #a08a5f;
  --accent-dark: #8a7550;
  --pending: #b8912c;
  --pending-bg: #faf3e2;
  --confirmed: #55795f;
  --confirmed-bg: #eaf1ec;
  --radius: 6px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- Top bar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.brand {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--text);
}
.brand-sub {
  color: var(--text-muted);
  font-weight: normal;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); }

/* ---------- Home tiles ---------- */
.page-head { padding: 56px 0 32px; }
.page-head h1 { font-family: var(--serif); font-size: 32px; margin: 0 0 6px; font-weight: 500; }
.page-head p { color: var(--text-muted); margin: 0; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  padding-bottom: 64px;
}
.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s ease, transform .15s ease;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile-icon { font-size: 24px; margin-bottom: 14px; display: block; }
.tile h2 { font-size: 17px; margin: 0 0 6px; font-weight: 600; }
.tile p { margin: 0; font-size: 13px; color: var(--text-muted); }
.tile.disabled { opacity: .5; cursor: default; pointer-events: none; }
.tile-badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 10px;
  margin-top: 10px;
}

/* ---------- Dashboard ---------- */
.dash-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 40px 0 24px;
  flex-wrap: wrap;
}
.dash-head h1 { font-family: var(--serif); font-size: 28px; margin: 0 0 4px; font-weight: 500; }
.dash-head p { margin: 0; color: var(--text-muted); font-size: 14px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  border: none;
  background: none;
  padding: 10px 4px;
  margin-right: 24px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.filters select,
.filters input[type="search"] {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
}
.filters input[type="search"] { flex: 1; min-width: 180px; }
.filters .spacer { flex: 1; }

.shipment-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 40px; }
.shipment-row {
  display: grid;
  grid-template-columns: 52px 90px 1fr 1fr 70px 110px 32px;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
  border: none;
  width: 100%;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
}
.shipment-row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.shipment-row:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.shipment-row:hover { background: #fbfaf7; }
.thumb {
  width: 44px; height: 44px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--border);
  display: block;
}
.thumb-empty { width: 44px; height: 44px; border-radius: 4px; background: var(--border); }
.row-code { font-family: monospace; font-weight: 600; }
.row-date { color: var(--text-muted); font-size: 12px; }
.row-party { font-weight: 500; }
.row-reason { color: var(--text-muted); }
.row-pieces { color: var(--text-muted); text-align: right; }
.badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 3px 10px;
  border-radius: 100px;
  justify-self: start;
}
.badge-pending { background: var(--pending-bg); color: var(--pending); }
.badge-confirmed { background: var(--confirmed-bg); color: var(--confirmed); }
.badge-outgoing { background: #f1eee7; color: var(--text-muted); }
.badge-incoming { background: #eef2f4; color: #4a6b78; }

.row-menu { position: relative; display: flex; justify-content: flex-end; }
.row-menu-btn {
  background: none; border: none; font-size: 18px; line-height: 1;
  color: var(--text-muted); cursor: pointer; padding: 6px 8px; border-radius: 4px;
}
.row-menu-btn:hover { background: var(--bg); }
.row-dropdown {
  display: none;
  position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(20, 18, 15, .1);
  min-width: 130px; z-index: 20; overflow: hidden;
}
.row-dropdown.open { display: block; }
.row-dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 10px 14px; background: none; border: none;
  font-size: 13px; font-family: var(--sans); color: var(--text); cursor: pointer;
}
.row-dropdown button:hover { background: var(--bg); }
.row-dropdown button.danger { color: #a6452f; }

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

/* ---------- Detail modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(30, 27, 22, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  padding: 32px;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.modal-code { font-family: monospace; font-size: 22px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 4px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; margin-bottom: 24px; }
.detail-field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 3px; }
.detail-field div.value { font-size: 14px; }
.detail-field.full { grid-column: 1 / -1; }
.detail-field select,
.detail-field input[type="text"],
.detail-field input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--sans);
  background: var(--surface);
  color: var(--text);
}
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-bottom: 24px; }
.photo-grid img { width: 100%; height: 110px; object-fit: cover; border-radius: 4px; cursor: zoom-in; }

/* ---------- Wizard ---------- */
.wizard-body { min-height: 100vh; display: flex; flex-direction: column; }
.wizard-top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.wizard-back { background: none; border: none; font-size: 15px; color: var(--text-muted); cursor: pointer; padding: 6px; visibility: hidden; justify-self: start; }
.wizard-back.visible { visibility: visible; }
.wizard-top > a.wizard-back { justify-self: end; }
.dots { display: flex; gap: 6px; justify-self: center; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.dot.active { background: var(--accent); }
.dot.done { background: var(--accent); opacity: .5; }

.wizard-main { flex: 1; display: flex; flex-direction: column; padding: 28px 20px 100px; max-width: 480px; margin: 0 auto; width: 100%; }
.wizard-step h2 { font-family: var(--serif); font-size: 22px; margin: 0 0 24px; font-weight: 500; }

.direction-choices { display: flex; flex-direction: column; gap: 14px; }
.direction-btn {
  display: flex; align-items: center; gap: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.direction-btn:active { border-color: var(--accent); background: #fbfaf7; }
.direction-icon { font-size: 26px; }

.field { margin-bottom: 20px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.field select,
.field input[type="text"],
.field input[type="number"],
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 16px;
  font-family: var(--sans);
  background: var(--surface);
  color: var(--text);
}
.field textarea { min-height: 100px; resize: vertical; }

.stepper { display: flex; align-items: center; gap: 20px; margin-bottom: 4px; }
.stepper button {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 22px;
  cursor: pointer;
}
.stepper-value { font-size: 28px; font-weight: 600; min-width: 40px; text-align: center; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.choice-btn.selected { border-color: var(--accent); background: #faf6ee; color: var(--accent-dark); }

.photo-upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.photo-tile { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--border); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile.uploading img { opacity: 0; }
.photo-tile.uploading { position: relative; }
.photo-tile.uploading::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 20px; height: 20px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.photo-tile .remove { position: absolute; top: 4px; right: 4px; background: rgba(20,18,15,.65); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 13px; cursor: pointer; }
.photo-add {
  aspect-ratio: 1;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--surface);
}
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.wizard-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}
.wizard-footer .inner { max-width: 480px; margin: 0 auto; }

.confirm-screen { text-align: center; padding-top: 40px; }
.confirm-code {
  font-family: monospace;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: .03em;
  background: #faf6ee;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  margin: 24px 0;
}
.confirm-screen p { color: var(--text-muted); }

@media (max-width: 640px) {
  .shipment-row { grid-template-columns: 40px 1fr 70px 28px; }
  .row-date, .row-reason, .row-pieces { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
}
