:root {
  --bg: #e7e5e4;
  --bg-mid: #d6d3d1;
  --panel: rgba(255, 252, 255, 0.94);
  --panelSolid: #fafaf9;
  --border: rgba(120, 113, 108, 0.18);
  --border-strong: rgba(154, 52, 18, 0.3);
  --text: #1c1917;
  --muted: #57534e;
  --muted2: #78716c;
  --primary: #c2410c;
  --primary-dim: rgba(234, 88, 12, 0.18);
  --danger: #b91c1c;
  --shadow-soft: 0 4px 24px rgba(28, 25, 23, 0.06);
  --radius-lg: 16px;
  --radius-md: 12px;
  --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --input-bg: #ffffff;
  --input-bg-focus: #fff7ed;
  --surface-raised: #ffedd5;
  --brand-title-gradient: linear-gradient(135deg, #9a3412 0%, #c2410c 42%, #ea580c 100%);
  --body-gradient: linear-gradient(180deg, #fafaf9 0%, #f5f5f4 22%, #e7e5e4 50%, #d6d3d1 76%, #c4c0bb 100%);
  --topbar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.99) 0%, rgba(250, 250, 249, 0.97) 100%);
  --panel-inset: 0 0 0 1px rgba(255, 255, 255, 0.85) inset;
  --stat-inset: 0 1px 0 rgba(255, 255, 255, 0.75) inset;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-feature-settings: "ss01" on, "cv11" on;
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  background-image: var(--body-gradient);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  color: var(--text);
  overflow-x: hidden;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: clamp(12px, 3vw, 18px) clamp(14px, 4vw, 22px);
  padding-top: max(clamp(12px, 3vw, 18px), env(safe-area-inset-top));
  padding-left: max(clamp(14px, 4vw, 22px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 4vw, 22px), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar--tool {
  align-items: center;
}

.toolbar-title {
  min-width: 0;
  flex: 1 1 auto;
}

.toolbar-title .brand-title {
  margin: 0;
}

.toolbar-title .brand-subtitle {
  margin: 4px 0 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

a.brand.brand--home {
  text-decoration: none;
  color: inherit;
}

.brand-logo-img {
  flex-shrink: 0;
  display: block;
  max-height: clamp(36px, 10vw, 48px);
  width: auto;
  height: auto;
  object-fit: contain;
}

.brand-title {
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: clamp(1.05rem, 4.2vw, 1.375rem);
  line-height: 1.15;
  background: var(--brand-title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 200px;
  min-width: 0;
}

.topbar-actions > .tool-account-cta.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  box-sizing: border-box;
}

.demo-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  margin-right: 4px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr) minmax(0, 360px);
  grid-template-areas: "left center right";
  gap: clamp(12px, 2.5vw, 18px);
  padding: clamp(6px, 2vw, 8px) clamp(12px, 3vw, 22px) max(12px, env(safe-area-inset-bottom));
  align-items: stretch;
  width: 100%;
  max-width: 100%;
}

.panel-left {
  grid-area: left;
}
.panel-center {
  grid-area: center;
}
.panel-right {
  grid-area: right;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft), var(--panel-inset);
}

.panel-title {
  padding: 15px 16px 11px;
  border-bottom: 1px solid rgba(120, 113, 108, 0.12);
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-left,
.panel-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-center {
  display: flex;
  flex-direction: column;
  min-height: clamp(300px, 48vh, 620px);
  min-height: clamp(300px, 48dvh, 620px);
}

.form-grid,
.stats-grid {
  padding: 14px 16px;
  display: grid;
  gap: 14px;
}

.form-grid {
  grid-template-columns: 1fr;
}

.stats-grid {
  grid-template-columns: 1fr 1fr;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface-raised);
  box-shadow: var(--stat-inset);
}

.stat-label {
  color: var(--muted2);
  font-size: 12px;
}

.stat-value {
  margin-top: 4px;
  font-weight: 800;
  font-size: 16px;
}

.section-subtitle {
  margin: 4px 0 0;
  color: var(--muted2);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.form-grid .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
}

.field-hint {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted2);
}

.field-hint strong {
  color: var(--text);
  font-weight: 700;
}

/* Ensure [hidden] wins over .field-row { display: grid } */
[hidden] {
  display: none !important;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.field-row--two-cols {
  grid-template-columns: 1fr 1fr;
}

.cargo-dims-block {
  margin-top: 2px;
}

.cargo-dims-block .section-subtitle {
  margin: 0 0 10px;
}

.field-row--dims .field {
  min-width: 0;
}

.toggle-row {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1fr;
  }
  .toggle-row {
    grid-template-columns: 1fr;
  }
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  user-select: none;
  font-size: 13px;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

input[type="text"],
input[type="number"] {
  background: var(--input-bg);
  border: 1px solid rgba(120, 113, 108, 0.22);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: rgba(154, 52, 18, 0.45);
  box-shadow: 0 0 0 3px var(--primary-dim);
  background: var(--input-bg-focus);
}

select {
  width: 100%;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(120, 113, 108, 0.22);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  background-color: var(--input-bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus {
  border-color: rgba(154, 52, 18, 0.45);
  box-shadow: 0 0 0 3px var(--primary-dim);
  background: var(--input-bg-focus);
}

.btn {
  border: 1px solid rgba(120, 113, 108, 0.22);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  border-color: rgba(120, 113, 108, 0.38);
  background: #fffcf7;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-dim);
  border-color: var(--border-strong);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(165deg, #ea580c 0%, #c2410c 45%, #7c2d12 100%);
  border-color: rgba(154, 52, 18, 0.45);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.22) inset, 0 8px 20px rgba(194, 65, 12, 0.28);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-danger {
  border-color: rgba(185, 28, 28, 0.45);
}

.btn-danger.btn-soft {
  background: rgba(254, 226, 226, 0.85);
  color: #991b1b;
}

.btn-ghost {
  background: rgba(255, 252, 247, 0.65);
}

.row-actions {
  padding: 0 16px 12px;
}

/* Add/Clear on row 1, Import CSV/PDF on row 2 — two columns so labels never squash */
.row-actions--toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: stretch;
}

.row-actions--toolbar .btn {
  min-width: 0;
  font-size: 0.9375rem;
  padding: 11px 12px;
  line-height: 1.3;
  text-align: center;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.import-format-hint {
  margin: 0 16px 10px;
  font-size: clamp(10px, 2.8vw, 11px);
  line-height: 1.45;
  color: var(--muted2);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.import-format-hint code {
  font-size: 10px;
  background: rgba(15, 23, 42, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

.import-hint.import-hint--warn {
  color: #b91c1c;
  font-weight: 600;
}

.items-list {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  max-height: min(42vh, 520px);
  max-height: min(42dvh, 520px);
  -webkit-overflow-scrolling: touch;
}

.line-card {
  border-radius: var(--radius-md);
  border: 1px solid rgba(120, 113, 108, 0.12);
  background: var(--surface-raised);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
}

.line-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.line-card-title {
  font-weight: 800;
  color: var(--text);
}

.line-card-meta {
  color: var(--muted);
  font-size: 12px;
}

.line-remove {
  border: none;
  background: transparent;
  color: var(--danger);
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
}

.view-controls--pallet {
  padding: 0 16px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.view-controls--pallet .check {
  font-size: 13px;
  font-weight: 650;
}

.three-host {
  padding: 10px 16px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.three-container-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: clamp(260px, 38vh, 480px);
  min-height: clamp(260px, 38dvh, 480px);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(120, 113, 108, 0.15);
  background: #e7e5e4;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55) inset;
}

.three-container {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: clamp(260px, 38vh, 480px);
  min-height: clamp(260px, 38dvh, 480px);
  touch-action: none;
}

.three-hint {
  font-size: 11px;
  margin: 0;
  padding: 0 4px;
  color: var(--muted2);
  line-height: 1.35;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.three-hover-tip {
  position: absolute;
  z-index: 5;
  max-width: min(420px, calc(100% - 24px));
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: rgba(255, 255, 255, 0.96);
  color: #0f172a;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.12);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.35;
}

.overflow-breakdown {
  margin: 0 16px 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(154, 52, 18, 0.35);
  background: linear-gradient(145deg, rgba(255, 247, 237, 0.95), rgba(255, 237, 213, 0.5));
  box-shadow: var(--stat-inset);
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
}

.overflow-breakdown__title {
  font-weight: 800;
  font-size: 13px;
  color: #9a3412;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.overflow-breakdown__scroll {
  max-height: min(42vh, 360px);
  max-height: min(42dvh, 360px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  border: 1px solid rgba(120, 113, 108, 0.15);
  background: rgba(255, 255, 255, 0.72);
}

.overflow-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.overflow-table th,
.overflow-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(120, 113, 108, 0.12);
}

.overflow-table th {
  position: sticky;
  top: 0;
  background: rgba(255, 237, 213, 0.95);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.04em;
}

.overflow-table tr:last-child td {
  border-bottom: 0;
}

.instructions {
  padding: 0 16px 18px;
  font-size: clamp(12px, 3.2vw, 13px);
  line-height: 1.55;
  color: var(--text);
  max-height: min(38vh, 480px);
  max-height: min(38dvh, 480px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.instructions ol {
  margin: 8px 0 0;
  padding-left: 1.25rem;
}

.instructions li {
  margin-bottom: 8px;
}

.muted {
  color: var(--muted);
}

.instructions .ok {
  color: #15803d;
  font-weight: 700;
}

.instructions .warn {
  color: #b45309;
  font-weight: 700;
}

.app-footer {
  margin-top: auto;
  padding: 16px clamp(14px, 4vw, 22px) max(20px, env(safe-area-inset-bottom));
  padding-right: max(clamp(14px, 4vw, 22px), env(safe-area-inset-right));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.footer-site-link {
  margin: 0;
  font-size: 0.875rem;
}

.footer-site-link a {
  color: var(--muted);
  font-weight: 650;
  text-decoration: none;
}

.footer-site-link a:hover {
  color: var(--primary);
  text-decoration: underline;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "center center"
      "left right";
  }

  .panel-center {
    grid-column: 1 / -1;
    min-height: clamp(320px, 44vh, 520px);
    min-height: clamp(320px, 44dvh, 520px);
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "center"
      "left"
      "right";
  }

  .panel-center {
    min-height: clamp(300px, 42vh, 480px);
    min-height: clamp(300px, 42dvh, 480px);
  }
}

@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .btn {
    flex: 1;
    min-width: 0;
  }

  .panel-title {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .panel-title {
    font-size: 0.75rem;
  }

  .three-hint {
    font-size: 10px;
  }
}
