:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #182033;
  --muted: #697386;
  --line: #dfe5ee;
  --primary: #0A71B9;
  --primary-dark: #0c5f9b;
  --danger: #6a2d2d;
  --warning: #b45309;
  --success: #2d6a2d;
  --sidebar: #1a1a1a;
  --sidebar-text: #e7edf6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; display: flex; }

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; margin-bottom: 28px; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--primary); }
.nav { display: grid; gap: 6px; }
.nav a, .logout-link {
  min-height: 42px;
  padding: 11px 12px;
  border-radius: 8px;
  color: #d7deea;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav a:hover, .logout-link:hover { background: rgba(255,255,255,.08); }
.logout-link { margin-top: auto; }
.nav-icon {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: .9;
}

.main-panel { flex: 1; margin-left: 260px; min-width: 0; }
.topbar {
  height: 68px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
}
.topbar span { color: var(--muted); display: block; font-size: 14px; }
.content { padding: 28px; }

.grid { display: grid; gap: 18px; }
.grid p { margin: 0;}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .04);
}
.card h2, .card h3 { margin-top: 0; }
.muted { color: var(--muted); }
.success-panel .actions {
  margin: 28px 0 0;
}

.button, button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  justify-content: center;
  gap: 8px;
}
.button:hover, button:hover { background: var(--primary-dark); }
.button.secondary { background: #e8eef6; color: var(--text); }
.button.danger { background: var(--danger); }
.button.warning { background: var(--warning); }
.button.small { min-height: 34px; padding: 7px 10px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 18px; }

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
}
.pagination-link,
.pagination-ellipsis {
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 9px;
}
.pagination-link:hover {
  background: #e8eef6;
}
.pagination-number.disabled {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  opacity: 1;
}
.pagination-ellipsis {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.disabled { opacity: .45; pointer-events: none; }

.icon-button {
  width: 42px;
  padding: 0;
  background: #e8eef6;
  color: var(--text);
  display: none;
}
.icon-button span { width: 18px; height: 2px; background: currentColor; display: block; margin: 2px 0; }

.form-grid { display: grid; gap: 14px; }
label { font-weight: 700; font-size: 14px; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  margin-top: 5px;
}
textarea { min-height: 90px; resize: vertical; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.dashboard-transfers-table .transfer-status-cell {
  text-align: right;
}

.badge { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: 12px; }
.badge.active { background: #dff0d8; border-color: #b2dba1; color: var(--success); }
.badge.inactive { background: #fee2e2; color: var(--danger); }
.badge.placeholder { background: #fef3c7; color: var(--warning); }
.badge.sent, .badge.completed { background: #dff0d8; color: var(--success); width: max-content;}
.badge.failed, .badge.cancelled { background: #fee2e2; color: var(--danger); }
.badge.pending { background: #e0f2fe; color: #0369a1; }
.badge.in_progress { background: #fef3c7; color: #92400e; }

.alert { border-radius: 8px; padding: 12px 14px; margin-bottom: 18px; border: 1px solid var(--line); background: #fff; }
.alert-success { background: #dff0d8; border-color: #b2dba1; color: var(--success); }
.alert-error { background: #f0d8d8; border-color: #dba1a1; color: var(--danger); }

.empty-state { padding: 30px; text-align: center; color: var(--muted); }
.loading { opacity: .65; pointer-events: none; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); }
.auth-card h1 { margin: 0 0 8px; }

dialog {
  width: min(620px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
}
dialog::backdrop { background: rgba(15, 23, 42, .46); }
.modal-body { padding: 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.step-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}
.step-strip span {
  min-height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8eef6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  padding: 6px;
}
.inner-tool, .summary-panel {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fbfdff;
}
.summary-panel ul {
  padding: 0;
  list-style-type: none;
}
.summary-panel ul li {
  border-bottom: 1px solid var(--line);
  padding: 5px 0;
}
.combo-results {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.combo-option {
  width: 100%;
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  text-align: left;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
}
.combo-option:hover { background: #f5f9ff; color: var(--text); border-color: #c8d8ea; }
.combo-option small { color: var(--muted); font-weight: 400; }
.product-search-result {
  gap: 6px;
}
.product-search-result strong {
  max-width: 100%;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.product-search-result small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.3;
}
.selected-product {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 160px auto;
  gap: 12px;
  align-items: end;
}
.mobile-product-list {
  display: grid;
  gap: 10px;
}
.mobile-table { display: none; }
.product-row-card {
  display: grid;
  grid-template-columns: 1fr 150px auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.product-mobile-line {
  display: grid;
  gap: 4px;
}
.product-mobile-line strong {
  line-height: 1.25;
}
.product-mobile-line span,
.product-mobile-line small {
  color: var(--muted);
  color: var(--text);
  font-size: 14px;
}
.qty-input { max-width: 110px; }
.finish-button {
  width: 100%;
  min-height: 56px;
  font-size: 16px;
}
.finish-button:disabled, button:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 16px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  box-shadow: 0 18px 38px rgba(15, 23, 42, .22);
  font-weight: 700;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.transfer-document-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  max-width: 450px;
}
.transfer-document-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.transfer-document-main span:last-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.transfer-document-main strong {
  font-size: 14px;
  line-height: 1.2;
}
.transfer-document-main small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.transfer-document-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .02em;
}
.pdf-view-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: 0;
  padding: 10px 18px;
  font-size: 14px;
  white-space: nowrap;
}
.transfer-manage-actions {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 14px;
  width: 100%;
}
.pdf-upload-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px;
  flex: 1 1 450px;
  align-items: stretch;
  gap: 0;
  max-width: 450px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.finalize-transfer-form {
  display: flex;
  justify-content: flex-end;
  margin-left: auto;
}
.finalize-transfer-form button {
  min-height: 42px;
  max-height: 42px;
  white-space: nowrap;
}
.pdf-dropzone {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  min-height: 66px;
  margin: 0;
  padding: 12px 16px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background .16s ease;
}
.pdf-dropzone:hover,
.pdf-dropzone.is-dragover {
  background: #f5f9ff;
}
.pdf-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.pdf-dropzone-title {
  font-size: 14px;
  line-height: 1.25;
  text-align: center;
}
.pdf-dropzone-hint {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}
.pdf-upload-form button {
  min-width: 0;
  min-height: 66px;
  border-radius: 0;
}
.transfer-history h3 {
  margin-bottom: 14px;
}
.history-list {
  display: grid;
  gap: 12px;
}
.history-entry {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}
.history-dot {
  width: 9px;
  height: 9px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--primary);
}
.history-entry div {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.history-entry strong {
  font-size: 14px;
  line-height: 1.25;
}
.history-entry span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.backdrop { display: none; }

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 10; }
  .main-panel { margin-left: 0; }
  .icon-button { display: grid; place-items: center; }
  .content {
    padding: 12px;
  }
  input,
  select,
  textarea {
    font-size: 16px;
  }
  .grid {
    gap: 12px;
  }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-mobile { padding: 0; }
  .grid-mobile .card { border-radius: 8px; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 9;
    height: 64px;
    padding: 0 12px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
  }
  .topbar strong {
    display: block;
    line-height: 1.2;
  }
  .step-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .combo-option { grid-template-columns: 1fr; }
  .selected-product { grid-template-columns: 1fr; align-items: stretch; }
  .product-row-card { grid-template-columns: 1fr; align-items: stretch; }
  .qty-input { max-width: 100%; }
  .card {
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .04);
  }
  .card h2 {
    font-size: 20px;
    line-height: 1.25;
  }
  .card h3 {
    font-size: 16px;
    line-height: 1.3;
  }
  .table-wrap {
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }
  .desktop-table { display: none; }
  .mobile-table {
    display: block;
    border: 1px solid var(--line);
    background: var(--panel);
    overflow: hidden;
    border-radius: 8px;
  }
  .mobile-table table {
    display: table;
    min-width: 0;
    width: 100%;
  }
  .mobile-table thead {
    display: table-header-group;
  }
  .mobile-table tbody {
    display: table-row-group;
  }
  .mobile-table tr {
    display: table-row;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
  }
  .mobile-table th,
  .mobile-table td {
    display: table-cell;
    width: auto;
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
  }
  table, thead, tbody, tr, th, td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  thead { display: none; }
  tr {
    position: relative;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 10px;
  }
  td {
    border-bottom: 0;
    padding: 5px;
  }
  td[data-label]::before,
  .mobile-table .product-mobile-line > [data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
  }
  .menu-toggle {
    padding: 10px;
    gap: 0;
  }
  .actions {
    align-items: stretch;
    flex-direction: column;
    margin: 0 0 14px;
  }
  .mobile-table .product-mobile-line:has(.badge) {
    position: relative;
    min-height: 24px;
    padding-right: 96px;
  }
  .mobile-table .product-mobile-line:has(.badge) .badge {
    position: absolute;
    top: 0;
    right: 0;
  }
  .table-wrap:not(.mobile-table) tr:has(.badge) td:has(> .badge) {
    position: absolute;
    top: 12px;
    right: 12px;
    width: auto;
    padding: 0;
  }
  .dashboard-transfers-mobile .product-mobile-line {
    position: relative;
  }
  .mobile-table .mobile-transfer-number {
    color: var(--text);
    font-weight: 700;
    line-height: 1.25;
  }
  .actions form,
  .actions .button,
  .actions button {
    width: 100%;
  }
  .actions .button,
  .actions button {
    display: inline-flex;
    align-items: center;
  }
  .pagination {
    margin: 0 0 14px;
  }
  .transfer-document-panel {
    align-items: stretch;
    flex-direction: column;
    margin-top: 14px;
    max-width: none;
  }
  .pdf-view-button {
    width: 100%;
  }
  .desktop-upload,
  .finalize-transfer-form {
    display: none;
  }
  .pagination {
    justify-content: center;
  }
  .pagination-link,
  .pagination-ellipsis {
    min-width: 34px;
    min-height: 34px;
    padding: 5px 8px;
  }
}
