@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --primary:      #16A34A;
  --primary-bg:   #E6F4EA;
  --primary-sh:   rgba(22,163,74,0.30);
  --bg:           #F8FAFC;
  --surface:      #FFFFFF;
  --text1:        #1E293B;
  --text2:        #64748B;
  --text3:        #94A3B8;
  --border:       #E2E8F0;
  --error:        #EF4444;
  --error-bg:     #FEE2E2;
  --tag-bg:       #F8FAFC;
  --tag-text:     #475569;
  --edit-bg:      #F1F5F9;
  --snack-bg:     #334155;
  --radius-card:  16px;
  --radius-input: 12px;
  --radius-tag:   6px;
  --shadow-card:  0 2px 8px rgba(0,0,0,0.04);
  --shadow-sheet: 0 4px 20px rgba(0,0,0,0.10);
  --shadow-fab:   0 4px 12px var(--primary-sh);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text1);
  min-height: 100vh;
  padding-bottom: 88px;
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.app-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text1);
  letter-spacing: -0.2px;
}
.header-actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text2);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background 0.15s;
}
.icon-btn:active { background: var(--bg); }

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; }
.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text3);
  padding: 10px 4px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.badge {
  background: var(--primary-bg);
  color: var(--primary);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}
.tab-btn:not(.active) .badge {
  background: var(--border);
  color: var(--text2);
}

/* ── Content ───────────────────────────────────────────────────────────────── */
.content { padding: 16px; max-width: 600px; margin: 0 auto; }

/* ── Order Card ────────────────────────────────────────────────────────────── */
.order-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s;
}
.order-card:active { box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px 12px;
}
.card-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.card-av-text {
  font-size: 15px;
  font-weight: 700;
  color: #475569;
  line-height: 1;
}
.card-top-info { flex: 1; min-width: 0; }
.card-name-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}
.card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text1);
  line-height: 1.3;
  flex: 1;
}
.card-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.card-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-meta-phone { font-size: 13px; color: var(--text2); }
.card-meta-date  { font-size: 12px; color: var(--text3); }

.card-divider { height: 1px; background: var(--border); }

/* Card sections */
.card-section { padding: 10px 16px; }
.card-section-hd {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 7px;
}
.card-section-body {
  font-size: 14px;
  color: var(--text1);
  line-height: 1.5;
  white-space: pre-line;
}

/* Chips */
.card-chips { display: flex; flex-direction: column; gap: 6px; }
.card-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text1);
  line-height: 1.4;
}
.card-chip svg { flex-shrink: 0; color: var(--text2); }

/* TTN in card */
.card-ttn-main  { font-size: 17px; font-weight: 700; color: var(--text1); margin-bottom: 2px; }
.card-ttn-empty { font-size: 15px; font-weight: 700; color: var(--text2); margin-bottom: 2px; }
.card-ttn-sub   { font-size: 12px; color: var(--text3); margin-top: 2px; }
.card-ttn-return{ font-size: 12px; color: #e65100; margin-top: 3px; }

/* Draft badge in title */
.draft-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFF8E1;
  color: #F59E0B;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  margin-left: 8px;
  vertical-align: middle;
}

/* Card action buttons */
.card-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.card-actions::-webkit-scrollbar { display: none; }
.card-act-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 52px;
  padding: 9px 8px;
  border-radius: 12px;
  border: none;
  font-size: 10px;
  font-weight: 500;
  flex-shrink: 0;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}
.card-act-btn:active { opacity: 0.7; }
.card-act-primary {
  flex-direction: row;
  gap: 6px;
  min-width: auto;
  padding: 0 16px;
  height: 46px;
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: white;
}
.card-act-icon   { background: var(--edit-bg); color: var(--text2); }
.card-act-delete { background: var(--error-bg); color: var(--error); }
.card-act-return { background: #FFF3E0; color: #E65100; }
.card-act-lbl { font-size: 10px; line-height: 1; }

/* View modal action buttons */
.view-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px env(safe-area-inset-bottom, 20px);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  background: var(--surface);
  z-index: 1;
}
.view-act-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 56px;
  padding: 12px 6px;
  border-radius: 14px;
  border: none;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}
.view-act-btn:active { opacity: 0.7; }
.view-act-create { background: var(--primary); color: white; flex: 2; flex-direction: row; gap: 8px; font-size: 14px; font-weight: 600; padding: 14px 16px; }
.view-act-default { background: var(--edit-bg); color: var(--text2); }
.view-act-delete  { background: var(--error-bg); color: var(--error); }
.view-act-return  { background: #FFF3E0; color: #E65100; }
.view-act-ttn-mgmt { background: var(--primary-bg); color: var(--primary); font-weight: 600; font-size: 11px; }

/* ── FAB ───────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: var(--shadow-fab);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.93); }

/* ── Modal / Bottom Sheet ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.40);
  z-index: 300;
  align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px 16px 40px;
  box-shadow: var(--shadow-sheet);
}
.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text1);
}
.close-btn {
  background: var(--bg);
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 16px;
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
}

/* ── Form ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 16px;
  background: var(--bg);
  color: var(--text1);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.form-input::placeholder { color: var(--text3); }
.form-input:focus { border-color: var(--primary); border-width: 1.5px; background: var(--surface); }

.form-textarea {
  height: auto;
  min-height: 80px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.5;
}

/* ── Autocomplete ──────────────────────────────────────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  max-height: 200px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: var(--shadow-sheet);
}
.autocomplete-item {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text1);
  transition: background 0.1s;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:active { background: var(--bg); }
.autocomplete-item .sub { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── Weight selector ───────────────────────────────────────────────────────── */
.weight-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.weight-btn {
  padding: 10px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text2);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.weight-btn.active {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

/* ── Carrier selector ──────────────────────────────────────────────────────── */
.carrier-grid { display: flex; gap: 8px; }

/* ── Payment selector ──────────────────────────────────────────────────────── */
.payment-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.payment-btn {
  flex: 1;
  min-width: 88px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text2);
  cursor: pointer;
  text-align: center;
  line-height: 1.4;
  transition: all 0.15s;
}
.payment-btn.active {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}
.payment-btn .sub {
  font-size: 10px;
  display: block;
  margin-top: 2px;
  font-weight: 400;
  color: var(--text3);
}
.payment-btn.active .sub { color: var(--primary); opacity: 0.8; }

/* ── Primary button ────────────────────────────────────────────────────────── */
.btn-primary-full {
  width: 100%;
  height: 52px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-input);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s;
  margin-top: 8px;
}
.btn-primary-full:active { opacity: 0.85; }
.btn-primary-full:disabled { opacity: 0.6; }

/* ── Settings section ──────────────────────────────────────────────────────── */
.settings-group { margin-bottom: 20px; }

/* ── Smart paste panel ─────────────────────────────────────────────────────── */
.smart-panel {
  background: #F0FDF4;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-card);
  padding: 14px;
  margin-bottom: 16px;
}
.smart-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
}
.smart-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-smart {
  flex: 1;
  height: 40px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-input);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.btn-cancel {
  width: 40px; height: 40px;
  background: var(--bg);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.btn-smart-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-input);
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-smart-trigger:active { background: var(--primary-bg); }

/* ── Refresh row ───────────────────────────────────────────────────────────── */
.refresh-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 13px;
  color: var(--text2);
  font-family: inherit;
  cursor: pointer;
}

/* ── Toast / Snackbar ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 16px; right: 16px;
  background: var(--snack-bg);
  color: #fff;
  padding: 13px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  z-index: 1000;
  pointer-events: none;
  max-width: 560px;
  margin: 0 auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error   { background: #B91C1C; }
.toast.success { background: #15803D; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty-state .icon { font-size: 44px; margin-bottom: 12px; }
.empty-state .text { font-size: 15px; color: var(--text2); }

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Report ────────────────────────────────────────────────────────────────── */
.report-period-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tag);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
}
.report-period-btn.active {
  background: var(--primary-bg);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.report-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.stat-val {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-lbl {
  font-size: 12px;
  color: var(--text2);
}
.report-section { margin-bottom: 20px; }
.report-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.report-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text1);
}
.report-row strong { color: var(--primary); font-weight: 600; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  .weight-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 560px) {
  .toast { left: 50%; right: auto; transform: translateX(-50%) translateY(12px); width: 400px; }
  .toast.show { transform: translateX(-50%) translateY(0); }
}
