:root {
  --primary: #3b669e;
  --primary-hover: #2f5583;
  --primary-light: #eef4fb;
  --header-bg: #345a82;
  --bg: #f9f7f2;
  --surface: #ffffff;
  --surface-muted: #ede8e1;
  --text: #1f2933;
  --text-secondary: #5c6670;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --success: #067647;
  --success-bg: #ecfdf3;
  --warning-bg: #fff9e6;
  --warning-text: #9a6700;
  --border: #d9dde3;
  --shadow: 0 1px 3px rgba(31, 41, 51, 0.08);
  --radius: 10px;
  --radius-lg: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

/* —— Header —— */
.app-header {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--header-bg);
  position: sticky;
  top: 0;
  z-index: 200;
}

.app-header-side {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.app-header-side-right {
  justify-content: flex-end;
}

.app-header-spacer {
  width: 44px;
  height: 44px;
}

.app-header-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header-mark-link {
  display: flex;
  -webkit-tap-highlight-color: transparent;
}

.app-header-mark {
  display: block;
  height: 28px;
  width: auto;
}

.menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.menu-btn:hover,
.menu-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.12);
}

.menu-btn-bar {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

.menu-btn[aria-expanded="true"] .menu-btn-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-btn[aria-expanded="true"] .menu-btn-bar:nth-child(2) {
  opacity: 0;
}

.menu-btn[aria-expanded="true"] .menu-btn-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.app-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 41, 51, 0.45);
  z-index: 250;
}

.app-menu-backdrop:not([hidden]) {
  display: block;
}

.app-menu {
  position: fixed;
  top: 0;
  right: 0;
  width: min(300px, 88vw);
  height: 100%;
  height: 100dvh;
  z-index: 300;
  background: var(--surface);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  padding-top: max(16px, env(safe-area-inset-top));
}

.app-menu:not([hidden]) {
  display: block;
}

.app-menu.is-open {
  transform: translateX(0);
}

.app-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}

.app-menu-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.menu-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.menu-close-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.app-menu-panel {
  padding: 20px;
}

.app-menu-label {
  margin: 0 0 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.app-menu-label:not(:first-child) {
  margin-top: 20px;
}

.app-menu-tenant {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.02em;
}

.app-menu-user {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.btn-menu-logout {
  margin-top: 28px;
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--border);
}

.btn-menu-logout:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

body.menu-open {
  overflow: hidden;
}

/* —— Layout —— */
.wizard,
.login-main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

body.has-bottom-bar .wizard {
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.login-page .login-main {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* —— Cards —— */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.step-card {
  padding: 20px;
}

.step-card-centered {
  text-align: center;
  padding: 32px 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
}

/* —— Typography —— */
.page-title {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.25;
}

.page-lead,
.hint {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.subsection-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

/* —— Forms —— */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
}

.field-input {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 102, 158, 0.15);
}

.field-readonly {
  background: var(--bg);
  color: var(--text);
  cursor: default;
}

.field-readonly:focus {
  border-color: var(--border);
  box-shadow: none;
}

.field-picker-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.field-picker-label.is-placeholder {
  color: var(--text-secondary);
}

.field-picker-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.bottom-sheet-search-wrap {
  padding: 0 12px 8px;
}

.bottom-sheet-search {
  width: 100%;
}

.bottom-sheet-empty {
  margin: 0;
  padding: 16px 14px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
  padding: 8px 12px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.btn-ghost:hover {
  background: var(--bg);
  color: var(--primary);
}

.btn-lg {
  padding: 14px 20px;
  font-size: 1.05rem;
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.btn-xl {
  width: 100%;
  min-height: 64px;
  font-size: 1.15rem;
  margin-top: 8px;
}

.btn-with-icon {
  display: flex;
}

.btn-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* —— Wizard steps —— */
.step {
  display: none;
}

.step.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* —— Choice buttons —— */
.choice-list {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}

.choice-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 60px;
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.choice-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.choice-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.choice-btn strong {
  font-size: 1.05rem;
}

.choice-btn span {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* —— Movement screen —— */
.form-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 8px;
}

.form-section-title {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
}

.form-section-hint {
  margin: -4px 0 12px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.pieces-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.pieces-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.stat-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
}

.stat-pill-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

/* —— Pieces list —— */
.pieces-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

.piece-item {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.piece-item.missing,
.piece-item.uncertain {
  border-color: #f5c518;
  background: var(--warning-bg);
}

.piece-warning {
  color: var(--warning-text) !important;
  font-weight: 600;
}

.btn.is-placeholder {
  color: var(--text-secondary);
}

.piece-item img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-muted);
  flex-shrink: 0;
}

.piece-meta {
  flex: 1;
  min-width: 0;
}

.piece-meta strong {
  display: block;
  font-size: 0.95rem;
  color: var(--primary);
}

.piece-meta span {
  display: block;
  font-size: 0.88rem;
  color: var(--text);
  margin-top: 2px;
}

.piece-meta small {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.piece-item .btn {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.add-piece {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.add-piece .field-input {
  flex: 1;
}

/* —— Workflow —— */
.workflow-choice {
  min-height: 72px;
}

.workflow-choice-primary {
  border-color: var(--primary);
  background: var(--primary-light);
}

.workflow-choice-primary span {
  color: #3d5f87;
}

/* —— Alerts & status —— */
.alert {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.95rem;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(6, 118, 71, 0.2);
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.2);
}

.status-text {
  margin: 12px 0;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
}

.step-loading {
  margin: 24px 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.done-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 56px;
  text-align: center;
}

/* —— Spinner —— */
.spinner {
  position: fixed;
  inset: 0;
  background: rgba(249, 247, 242, 0.85);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 1000;
  display: none;
}

.spinner:not([hidden]) {
  display: flex;
}

.spinner-inner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* —— Tablet —— */
@media (min-width: 600px) {
  .wizard,
  .login-main {
    padding: 24px;
    max-width: 720px;
  }

  .home-grid {
    grid-template-columns: repeat(1, 1fr);
  }

  .step-card {
    padding: 28px;
  }

  .page-title {
    font-size: 1.5rem;
  }

  .user-badge-name {
    max-width: 220px;
  }

  .choice-list {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 900px) {
  .wizard {
    max-width: 800px;
  }
}

/* —— Secció per tipus de tasca (Embalatges/Transports/Instal·lacions) —— */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-header .page-title {
  margin: 0;
}

.section-new-btn {
  flex-shrink: 0;
  padding: 10px 16px;
}

/* Capçalera de formulari: títol + acció (p.e. foto), alineats en una fila. */
.form-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.form-title-row .page-title {
  margin: 0;
}

/* Botó de foto rodó, només icona (embalatge i transport). */
.photo-round-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.photo-round-btn:active {
  background: var(--primary);
  color: #fff;
}

.photo-round-icon {
  width: 24px;
  height: 24px;
}

/* —— Home —— */
.home-card-wrap .page-lead {
  margin-bottom: 24px;
}

.home-grid {
  display: grid;
  gap: 12px;
}

.home-tile {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 18px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.home-tile:active {
  transform: scale(0.98);
}

.home-tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--header-bg);
  color: #fff;
}

.home-tile-icon svg {
  width: 26px;
  height: 26px;
}

.home-tile-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.home-tile-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.home-tile-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* —— Search —— */
.search-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 24px;
}

.search-card .page-title {
  margin-bottom: 16px;
}

.search-card > .btn-secondary.btn-block {
  margin-top: 16px;
}

.search-view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.search-view-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.search-view-tab svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.search-view-tab.active {
  background: var(--header-bg);
  border-color: var(--header-bg);
  color: #fff;
}

.search-mode-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 14px;
  padding: 4px 6px 4px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 102, 158, 0.15);
}

.search-input {
  flex: 1;
  min-width: 0;
  padding: 11px 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
}

.search-input:focus {
  outline: none;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.search-box-tools {
  display: flex;
  flex-shrink: 0;
  gap: 2px;
}

.search-box-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.search-box-btn svg {
  width: 22px;
  height: 22px;
}

.search-box-btn:active {
  background: var(--bg);
  color: var(--primary);
}

.search-box-btn.is-recording {
  background: var(--danger-bg);
  color: var(--danger);
}

.search-status {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  min-height: 1.25em;
}

.search-history-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 4px;
}

.search-history-panel[hidden],
#search-form-panel[hidden] {
  display: none !important;
}

.search-results[hidden] {
  display: none !important;
}

.search-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-history-item {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.search-history-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-history-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--primary);
}

.search-history-icon svg {
  width: 18px;
  height: 18px;
}

.search-history-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.search-history-item:active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.search-history-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

.search-history-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-empty {
  margin: 0;
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.search-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.search-result-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--primary-light);
}

.search-result-header strong {
  color: var(--primary);
  font-size: 0.95rem;
}

.search-result-body {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0;
}

.search-result-image {
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-result-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

.search-result-meta {
  padding: 12px 14px;
  min-width: 0;
}

.search-result-meta p {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-title {
  font-size: 0.92rem !important;
}

.search-result-location {
  color: var(--primary) !important;
  font-weight: 500;
}

.search-result-condition {
  color: var(--text-secondary) !important;
  font-size: 0.8rem !important;
}

.app-menu-hint {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* —— Bottom bar (filters / search modes) —— */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 302;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(31, 41, 51, 0.08);
}

.bottom-bar[hidden] {
  display: none !important;
}

.bottom-bar-inner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
}

.bottom-bar-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  min-height: 52px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.bottom-bar-back[hidden] {
  display: none !important;
}

.bottom-bar-back svg {
  width: 22px;
  height: 22px;
}

.bottom-bar-back:active {
  background: var(--surface-muted);
  color: var(--text);
}

.bottom-bar-buttons {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  min-width: 0;
}

.bottom-bar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bottom-bar-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-bar-btn-icon svg {
  width: 20px;
  height: 20px;
}

.bottom-bar-btn-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-bar-btn.is-active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.bottom-bar-btn.is-active .bottom-bar-btn-icon {
  color: var(--primary);
}

.bottom-bar-btn:not(:has(.bottom-bar-btn-icon)) {
  font-size: 0.78rem;
  padding: 10px 6px;
}

.bottom-bar-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 41, 51, 0.35);
  z-index: 300;
}

.bottom-sheet-backdrop[hidden] {
  display: none !important;
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 301;
  max-height: min(50vh, 360px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -4px 24px rgba(31, 41, 51, 0.15);
}

/* Quan la barra inferior és visible, el full es queda enganxat per sobre seu. */
body.has-bottom-bar .bottom-sheet-backdrop {
  bottom: calc(68px + env(safe-area-inset-bottom));
}

body.has-bottom-bar .bottom-sheet {
  bottom: calc(68px + env(safe-area-inset-bottom));
}

.bottom-sheet[hidden] {
  display: none !important;
}

.bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.bottom-sheet-header strong {
  font-size: 1rem;
  color: var(--text);
}

.bottom-sheet-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.bottom-sheet-options {
  overflow-y: auto;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.bottom-sheet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.bottom-sheet-option small {
  flex-shrink: 0;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.bottom-sheet-option.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.bottom-sheet-option:active {
  background: var(--bg);
}

/* —— Tasks —— */
.tasks-layout {
  padding-bottom: 24px;
}

.tasks-card > .btn-primary.btn-block {
  margin-top: 12px;
}

.tasks-card > .btn-secondary.btn-block {
  margin-top: 8px;
}

.tasks-status {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
}

.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tasks-empty {
  margin: 0;
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary);
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.task-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.task-card-clickable {
  display: block;
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.task-card-clickable:active {
  transform: scale(0.99);
}

.task-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.task-card-ref {
  display: block;
  flex: 1;
  min-width: 0;
  color: var(--primary);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.task-status-pill {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.task-status-pending {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.task-status-open {
  background: var(--primary-light);
  color: var(--primary);
}

.task-status-closed {
  background: var(--success-bg);
  color: var(--success);
}

.task-card-desc {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.task-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.task-detail-heading {
  flex: 1;
  min-width: 0;
}

.task-detail-type-badge {
  display: block;
  margin-bottom: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.task-detail-type-badge:empty {
  display: none;
}

.task-detail-ref {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.task-detail-desc {
  margin: 0 0 16px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.task-detail-meta {
  margin: 0 0 20px;
  padding: 0;
}

.task-detail-meta-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px 12px;
  margin-bottom: 8px;
}

.task-detail-meta-row[hidden] {
  display: none;
}

.task-detail-meta-row dt {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.task-detail-meta-row dd {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text);
  margin-left: 10px;
}

.task-detail-workflow {
  margin-bottom: 20px;
}

.task-workflow-actions {
  display: grid;
  gap: 10px;
}

.task-workflow-actions .choice-btn {
  width: 100%;
}

.task-objects-empty {
  list-style: none;
  margin: 0;
  padding: 20px 16px;
  text-align: center;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

  .search-result-image {
    max-height: 200px;
    overflow: hidden;
  }
}

@media (max-width: 380px) {
  .app-header-mark {
    height: 24px;
  }
}

/* —— Bottom sheet: multi-selecció i footer —— */
.bottom-sheet--tall {
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
}

.bottom-sheet-footer {
  flex-shrink: 0;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.bottom-sheet-footer[hidden] {
  display: none !important;
}

.bottom-sheet-footer .btn {
  margin-top: 0;
}

.multi-select-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.multi-select-check {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 2px solid var(--border);
  border-radius: 50%;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.multi-select-check svg {
  width: 14px;
  height: 14px;
}

.multi-select-option.is-checked {
  border-color: var(--primary);
  background: var(--primary-light);
}

.multi-select-option.is-checked .multi-select-check {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.multi-select-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.multi-select-body small {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* —— Detall de tasca: files editables —— */
.task-detail-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin: -4px 0 -4px -8px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.task-detail-edit-btn::after {
  content: '›';
  color: var(--text-secondary);
  font-weight: 700;
}

.task-detail-edit-btn:active {
  background: var(--primary-light);
}

.task-detail-edit-btn .is-placeholder,
.task-detail-edit-btn span:empty::before {
  content: 'Assignar…';
  color: var(--text-secondary);
}

.task-detail-date-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Files de text lliure (breu descripció, notes): el valor pot ser multilínia i
   l'editor apareix in situ, substituint el botó. */
.task-detail-edit-btn--text {
  align-items: flex-start;
  white-space: pre-wrap;
}

.task-detail-edit-btn--text span:empty::before {
  content: 'Afegir…';
  color: var(--text-secondary);
}

.task-detail-text-input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.task-detail-text-input[hidden] {
  display: none;
}

/* Targeta d'embalatge dins d'un transport o selector */
.packing-ref-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.packing-ref-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.packing-ref-box {
  font-weight: 700;
  color: var(--primary);
}

.packing-ref-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.packing-ref-card .btn {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 0.85rem;
}

/* —— Confirm dialog —— */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 41, 51, 0.45);
  z-index: 400;
}

.confirm-backdrop[hidden] {
  display: none !important;
}

.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 401;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-dialog[hidden] {
  display: none !important;
}

.confirm-dialog-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  padding: 20px;
}

.confirm-dialog-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.confirm-dialog-message {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.4;
}

.confirm-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
