/* ============================================================
   CSS VARIABLES — Design Tokens
   ============================================================ */
:root {
  /* Brand */
  --color-brand: #0052cc;
  --color-brand-hover: #0041a8;
  --color-brand-light: #dbeafe;
  --color-brand-subtle: #eff6ff;

  /* Neutrals */
  --color-bg: #f0f5fa;
  --color-surface: #ffffff;
  --color-surface-alt: #f6f9fc;
  --color-ink: #0f2231;
  --color-ink-muted: #4d6475;
  --color-ink-faint: #8fa5b3;
  --color-border: #d1e2ef;
  --color-border-strong: #aec8df;

  /* Semantic */
  --color-success: #137a42;
  --color-success-bg: #e6f6ee;
  --color-success-border: #9dd8b6;
  --color-error: #b91c1c;
  --color-error-bg: #fef2f2;
  --color-error-border: #fca5a5;

  /* Typography */
  --font: "Segoe UI", "Inter", Tahoma, Geneva, sans-serif;
  --text-xs: 0.6875rem; /* 11px */
  --text-sm: 0.8125rem; /* 13px */
  --text-base: 0.9375rem; /* 15px */
  --text-lg: 1.125rem; /* 18px */
  --text-xl: 1.375rem; /* 22px */
  --text-2xl: 1.75rem; /* 28px */
  --text-3xl: 2.125rem; /* 34px */

  /* Spacing (4-pt scale) */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.25rem;
  --s6: 1.5rem;
  --s8: 2rem;
  --s10: 2.5rem;

  /* Radii */
  --r-sm: 0.375rem;
  --r-md: 0.625rem;
  --r-lg: 1rem;
  --r-xl: 1.375rem;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md:
    0 4px 16px rgba(15, 34, 49, 0.08), 0 2px 6px rgba(15, 34, 49, 0.04);
  --shadow-lg:
    0 12px 40px rgba(15, 34, 49, 0.1), 0 4px 14px rgba(15, 34, 49, 0.05);

  /* Transitions — only transform/opacity for GPU compositing */
  --t-fast: 140ms ease;
  --t-base: 220ms ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-ink);
  background-color: var(--color-bg);
  /* Subtle radial accent — GPU-composited via background-attachment */
  background-image:
    radial-gradient(
      ellipse 70% 55% at 100% 0%,
      rgba(219, 234, 254, 0.75) 0%,
      transparent 55%
    ),
    radial-gradient(
      ellipse 50% 40% at 0% 100%,
      rgba(186, 230, 255, 0.35) 0%,
      transparent 50%
    );
  background-attachment: fixed;
  min-height: 100dvh;
}

/* ============================================================
   APP SHELL (BEM: app)
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── app__header ── */
.app__header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.app__header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--s3) var(--s4);
  display: flex;
  align-items: center;
  gap: var(--s4);
}

/* ── brand (BEM: brand) ── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  text-decoration: none;
  color: var(--color-brand);
  transition: opacity var(--t-fast);
}

.brand:hover {
  opacity: 0.8;
}

.brand__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--color-brand-light);
  border-radius: var(--r-md);
  padding: 5px;
  flex-shrink: 0;
}

.brand__icon svg {
  width: 100%;
  height: 100%;
}

.brand__name {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* ── app__main ── */
.app__main {
  flex: 1;
  /* Mobile-first: tight padding */
  padding: var(--s5) var(--s4);
}

/* ── app__footer ── */
.app__footer {
  padding: var(--s4);
  text-align: center;
  color: var(--color-ink-faint);
  font-size: var(--text-sm);
  border-top: 1px solid var(--color-border);
}

/* ============================================================
   CARD
   ============================================================ */
.card {
  max-width: 860px;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-xl);
  padding: var(--s5) var(--s5);
  box-shadow: var(--shadow-lg);
  /* GPU-friendly entrance animation */
  animation: cardEnter 0.4s cubic-bezier(0.22, 0.68, 0, 1.2) both;
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
   SEARCH PAGE ICON (BEM: search)
   ============================================================ */
.search__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: var(--r-lg);
  background: var(--color-brand-light);
  color: var(--color-brand);
  margin-bottom: var(--s5);
}

.search__icon svg {
  width: 28px;
  height: 28px;
}

/* ============================================================
   TYPOGRAPHY HELPERS
   ============================================================ */
.headline {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--color-ink);
}

.subhead {
  margin-top: var(--s2);
  color: var(--color-ink-muted);
  font-size: var(--text-base);
  line-height: 1.55;
}

/* Uppercase micro-label */
.label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-ink-muted);
}

/* Section divider-label */
.section-label {
  display: flex;
  align-items: center;
  gap: var(--s3);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-ink-muted);
  margin-bottom: var(--s4);
}

.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* ============================================================
   FORM COMPONENTS
   ============================================================ */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  margin-top: var(--s6);
}

/* Generic label */
label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-ink);
  user-select: none;
}

/* Optional text inside a label */
.form-field__opt {
  font-weight: 400;
  color: var(--color-ink-faint);
  font-size: var(--text-xs);
  margin-left: var(--s1);
}

/* Text inputs + selects */
input[type="text"],
input[type="search"],
input[type="password"],
select {
  display: block;
  width: 100%;
  border: 1.5px solid var(--color-border);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  font-size: var(--text-base);
  font-family: var(--font);
  color: var(--color-ink);
  background: var(--color-surface);
  outline: none;
  /* Only animate box-shadow — no layout thrash */
  transition:
    box-shadow var(--t-fast),
    border-color var(--t-fast);
  appearance: none;
  -webkit-appearance: none;
}

input[type="text"]:hover,
input[type="password"]:hover,
select:hover {
  border-color: var(--color-border-strong);
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.15);
}

input::placeholder {
  color: var(--color-ink-faint);
}

/* Custom select arrow wrapper */
.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  content: "";
  position: absolute;
  right: var(--s4);
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 6px;
  background: var(--color-ink-muted);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  pointer-events: none;
}

.select-wrapper select {
  padding-right: var(--s10);
  cursor: pointer;
}

/* Stacked field wrapper */
.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.field-help {
  font-size: var(--text-sm);
  color: var(--color-ink-muted);
}

.field-help--error {
  color: var(--color-error);
}

/* Folder row */
.row {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.row--full {
  grid-column: 1 / -1;
}

.secret-inline {
  display: grid;
  grid-template-columns: max-content minmax(220px, 1fr) max-content;
  align-items: center;
  gap: var(--s3);
  width: 100%;
}

.secret-inline__label {
  margin: 0;
  white-space: nowrap;
}

.secret-inline input[type="password"] {
  width: 100%;
  min-width: 0;
}

.secret-inline .inline-checkbox {
  justify-self: end;
  white-space: nowrap;
  margin: 0;
}

.inline-checkbox--compact {
  min-height: 42px;
  padding-inline: var(--s4);
}

/* Two-column layout for form sections */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s4);
}

@media (max-width: 640px) {
  .secret-inline {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .secret-inline .inline-checkbox {
    justify-self: start;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   TOGGLE CHECKBOX
   ============================================================ */
.inline-checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border: 1.5px solid var(--color-border);
  border-radius: var(--r-md);
  background: var(--color-surface);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--color-ink);
  cursor: pointer;
  user-select: none;
  width: fit-content;
  transition:
    border-color var(--t-fast),
    background var(--t-fast);
}

.inline-checkbox:hover {
  border-color: var(--color-brand);
  background: var(--color-brand-subtle);
}

.inline-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--color-brand);
  flex-shrink: 0;
}

/* ============================================================
   BUTTONS (BEM: btn)
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border: none;
  border-radius: var(--r-md);
  padding: var(--s3) var(--s5);
  font-size: var(--text-base);
  font-weight: 600;
  font-family: var(--font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  /* GPU-composited transitions only */
  transition:
    opacity var(--t-fast),
    transform var(--t-fast),
    box-shadow var(--t-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 82, 204, 0.28);
}
.btn-primary:hover {
  background: var(--color-brand-hover);
  box-shadow: 0 4px 14px rgba(0, 82, 204, 0.36);
}

.btn-ghost {
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1.5px solid var(--color-border);
}
.btn-ghost:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-border-strong);
}

.btn-danger {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1.5px solid var(--color-error-border);
  padding: var(--s1) var(--s3);
  font-size: var(--text-sm);
  border-radius: var(--r-sm);
}
.btn-danger:hover {
  background: #fee2e2;
}

/* ============================================================
   ALERTS (BEM: alert)
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  font-size: var(--text-sm);
  line-height: 1.5;
  animation: alertSlide 0.25s ease both;
}

@keyframes alertSlide {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-success {
  background: var(--color-success-bg);
  border: 1.5px solid var(--color-success-border);
  color: var(--color-success);
}

.alert-error {
  background: var(--color-error-bg);
  border: 1.5px solid var(--color-error-border);
  color: var(--color-error);
}

/* Alert icon */
.alert__icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

/* ============================================================
   SHIPMENT PAGE
   ============================================================ */

/* ── Shipment header ── */
.shipment-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding-bottom: var(--s5);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--s5);
}

.shipment-header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-top: var(--s1);
  color: var(--color-ink);
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: var(--s1) var(--s3);
  border-radius: 9999px;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.status-badge--active {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* Pulsing dot indicator */
.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}

/* ── Shipment meta grid ── */
.shipment-meta {
  display: grid;
  /* Mobile-first: single column */
  grid-template-columns: 1fr;
  gap: var(--s4);
  margin-bottom: var(--s6);
  padding: var(--s5);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
}

/* Each meta cell: label on top, value below */
.shipment-meta > div {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.shipment-meta > div > strong {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-ink-muted);
  /* Treat <strong> as a label only — no bold feel */
  font-style: normal;
}

.shipment-meta > div > span {
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--color-ink);
  word-break: break-word;
}

/* ============================================================
   UPLOAD SECTION
   ============================================================ */
.upload-grid {
  display: grid;
  /* Mobile: stacked */
  grid-template-columns: 1fr;
  gap: var(--s4);
}

.upload-box {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  border: 1.5px dashed var(--color-border);
  border-radius: var(--r-lg);
  padding: var(--s5);
  background: var(--color-surface-alt);
  transition:
    border-color var(--t-fast),
    background var(--t-fast);
}

.upload-box:has(input:focus) {
  border-color: var(--color-brand);
  background: var(--color-brand-subtle);
}

.upload-box label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-ink-muted);
}

/* File input */
input[type="file"] {
  display: block;
  width: 100%;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-family: var(--font);
  color: var(--color-ink-muted);
  background: var(--color-surface);
  cursor: pointer;
  outline: none;
}

/* Chrome/Edge file button */
input[type="file"]::-webkit-file-upload-button {
  background: var(--color-brand-light);
  border: 1px solid var(--color-brand);
  border-radius: var(--r-sm);
  color: var(--color-brand);
  font-family: var(--font);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 10px;
  cursor: pointer;
  margin-right: var(--s3);
}

/* Firefox / standard file button */
input[type="file"]::file-selector-button {
  background: var(--color-brand-light);
  border: 1px solid var(--color-brand);
  border-radius: var(--r-sm);
  color: var(--color-brand);
  font-family: var(--font);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 10px;
  cursor: pointer;
  margin-right: var(--s3);
}

/* Image preview — fade in via opacity/transform only */
.image-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--r-md);
  border: 1px solid var(--color-border);
  background: #fff;
  animation: fadeIn 0.3s ease both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================
   DOCS LIST
   ============================================================ */
.docs-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  margin-top: var(--s2);
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--color-ink);
  /* Animate in new items */
  animation: docIn 0.2s ease both;
}

@keyframes docIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Filename truncation */
.doc-item span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   ACTIONS ROW
   ============================================================ */
.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s6);
  padding-top: var(--s5);
  border-top: 1px solid var(--color-border);
}

/* ============================================================
   UTILITY
   ============================================================ */
.hidden {
  display: none !important;
}

/* ============================================================
   QR SCANNER MODAL
   ============================================================ */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
}

.qr-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 34, 49, 0.56);
  backdrop-filter: blur(2px);
}

.qr-modal__panel {
  position: relative;
  width: min(560px, 100%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.qr-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.qr-modal__header h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.qr-modal__close {
  padding: var(--s2) var(--s4);
}

.qr-camera-wrap {
  border-radius: var(--r-md);
  border: 1px solid var(--color-border);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
}

.qr-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================================
   RESPONSIVE — Tablet  ≥ 768px
   ============================================================ */
@media (min-width: 768px) {
  .app__main {
    padding: var(--s8) var(--s6);
  }

  .card {
    padding: var(--s8) var(--s10);
  }

  .shipment-meta {
    grid-template-columns: 1fr 1fr;
  }

  .upload-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================
   RESPONSIVE — Desktop  ≥ 1024px
   ============================================================ */
@media (min-width: 1024px) {
  .app__main {
    padding: var(--s10) var(--s8);
  }

  .headline {
    font-size: var(--text-3xl);
  }

  .shipment-header h1 {
    font-size: var(--text-3xl);
  }

  .shipment-meta {
    grid-template-columns: repeat(4, 1fr);
  }
}
/* ============================================================
   IMAGE PREVIEW LIST
   ============================================================ */
.image-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: var(--s3);
  margin-top: var(--s3);
}

.image-preview-item {
  position: relative;
  aspect-ratio: 1; /* Hiển thị hình vuông thu nhỏ */
  border-radius: var(--r-md);
  border: 1px solid var(--color-border);
  overflow: hidden;
  background: var(--color-surface);
  animation: fadeIn 0.3s ease both;
}

.image-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.btn-remove-img {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--color-border);
  color: var(--color-error);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform var(--t-fast);
  padding: 0;
  box-shadow: var(--shadow-sm);
}

.btn-remove-img:hover {
  transform: scale(1.1);
  background: var(--color-error-bg);
  border-color: var(--color-error-border);
}

/* ============================================================
   DOCS LIST ENHANCEMENTS
   ============================================================ */
/* Kích thước file */
.doc-size {
  color: var(--color-ink-faint);
  font-size: var(--text-xs);
  font-style: normal;
  margin-left: var(--s2);
}

/* Nút xóa file (icon) */
.btn-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-error);
  padding: var(--s1);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}

.btn-remove:hover {
  background: var(--color-error-bg);
}