/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --bg:           #f0f2f5;
  --surface:      #ffffff;
  --border:       #d0d5dd;
  --border-light: #e4e7ec;
  --text:         #101828;
  --text-muted:   #667085;
  --accent:       #1570ef;
  --accent-hover: #1048a8;
  --accent-light: #eff4ff;
  --label:        #344054;
  --section-hd:   #f8f9fb;
  --required:     #d92d20;
  --success:      #067647;
  --success-bg:   #ecfdf3;
  --row-alt:      #fafafa;
  --shadow:       0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
}

/* ── Base ───────────────────────────────────────────────── */
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 0;
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(16,24,40,.06);
}

.app-brand { display: flex; flex-direction: column; }
.app-title { font-size: 15px; font-weight: 700; letter-spacing: -.3px; color: var(--text); }
.app-subtitle { font-size: 11px; color: var(--text-muted); }

.topbar-actions { display: flex; gap: 8px; }

/* ── Tab navigation ─────────────────────────────────────── */
.tab-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 0 4px;
  background: var(--border-light);
  color: var(--text-muted);
}
.tab-btn.active .tab-badge { background: var(--accent-light); color: var(--accent); }

/* ── Tab panels ─────────────────────────────────────────── */
.tab-content {
  padding: 20px 24px;
  flex: 1;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Card ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--section-hd);
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--label);
}
.section-header .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.section-body { padding: 14px 16px; }

/* ── Grid ───────────────────────────────────────────────── */
.grid          { display: grid; gap: 12px; }
.grid-2        { grid-template-columns: 1fr 1fr; }
.grid-3        { grid-template-columns: 1fr 1fr 1fr; }
.grid-4        { grid-template-columns: 1fr 1fr 1fr 1fr; }
.col-span-2    { grid-column: span 2; }
.col-span-3    { grid-column: span 3; }
.col-span-4    { grid-column: span 4; }

/* ── Fields ─────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 3px; }

label {
  font-size: 11px;
  font-weight: 500;
  color: var(--label);
  letter-spacing: .1px;
}
label .req { color: var(--required); margin-left: 2px; }

input[type="text"], input[type="date"], input[type="number"], input[type="tel"],
select, textarea {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21,112,239,.12);
}
input::placeholder, textarea::placeholder { color: #aab4c4; }
input[readonly] { background: var(--section-hd); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667085' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
}
textarea { resize: vertical; min-height: 56px; }

.mapping-note {
  font-size: 10px;
  color: #9eb3d0;
  font-style: italic;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--section-hd); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--border-light); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: #fff0f0; border-color: #fca5a5; color: var(--required); }

/* ── Cargo table ────────────────────────────────────────── */
.cargo-table-wrap { overflow-x: auto; }

table.cargo {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.cargo thead tr { background: var(--section-hd); }
table.cargo th {
  padding: 7px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.cargo td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
table.cargo tbody tr:nth-child(even) td { background: var(--row-alt); }
table.cargo td input, table.cargo td select { padding: 4px 7px; font-size: 12px; }
table.cargo td.td-num { width: 30px; color: var(--text-muted); text-align: center; }
table.cargo td.td-btn { width: 34px; text-align: center; }

/* ── Totals row ─────────────────────────────────────────── */
.totals-row {
  display: flex;
  gap: 24px;
  padding: 10px 16px;
  background: var(--accent-light);
  border-top: 1px solid #c7d9fd;
  font-size: 12px;
  flex-wrap: wrap;
}
.totals-row .total-item { display: flex; flex-direction: column; gap: 1px; }
.totals-row .total-label { font-size: 10px; text-transform: uppercase; color: var(--text-muted); letter-spacing: .3px; }
.totals-row .total-value { font-weight: 700; font-size: 13px; color: var(--accent); }

/* ── Misc ───────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border-light); margin: 12px 0; }

.inline-group { display: flex; gap: 8px; align-items: flex-end; }
.inline-group .field { flex: 1; }

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--label);
  cursor: pointer;
  white-space: nowrap;
}
input[type="checkbox"], input[type="radio"] {
  width: 14px; height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.form-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  z-index: 90;
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 10px;
  max-width: 760px;
  width: 95%;
  max-height: 80vh;
  overflow: auto;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3, .col-span-4 { grid-column: span 1; }
  .tab-content { padding: 12px; }
  .app-topbar { padding: 8px 12px; }
}

/* ── Print ──────────────────────────────────────────────── */
@media print {
  body { background: white; }
  .app-topbar, .tab-nav, .form-footer, .btn, .btn-icon, .modal-overlay { display: none !important; }
  .tab-panel { display: block !important; }
}
