:root {
  --red: #e60012;
  --red-dark: #c40010;
  --header-bg: #2d2d2d;
  --text: #333;
  --text-muted: #888;
  --bg: #d8dce2;
  --bg-side: #c5cad2;
  --bg-center: #e2e6ec;
  --card: #fff;
  --border: #e0e0e0;
  --alert-bg: #fff5f5;
  --alert-text: #c40010;
  --paid: #1a7f37;
  --pending: #b45309;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --radius: 4px;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: Roboto, Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: var(--text);
  background-color: var(--bg-side);
  background-image: linear-gradient(
    90deg,
    #b8bec8 0%,
    var(--bg-side) 12%,
    var(--bg-center) 22%,
    var(--bg-center) 78%,
    var(--bg-side) 88%,
    #b8bec8 100%
  );
  line-height: 1.5;
}

/* SF опознавательный знак */
.sf-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fff 0%, #f3f4f6 100%);
  border: 1px solid #e5e7eb;
  border-radius: 50%;
  flex-shrink: 0;
}

.sf-mark img {
  object-fit: contain;
}

.sf-mark--header {
  width: 34px;
  height: 34px;
  padding: 5px;
  background: #fff;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.sf-mark--header img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sf-mark--input {
  position: absolute;
  left: 0.65rem;
  z-index: 1;
  width: 32px;
  height: 32px;
  pointer-events: none;
}

.sf-mark--tag {
  width: 30px;
  height: 30px;
}

.sf-mark--sm {
  width: 26px;
  height: 26px;
}

.sf-mark--sm img {
  width: 18px;
  height: auto;
}

.sf-mark--modal {
  width: 32px;
  height: 32px;
}

/* Header */
.site-header {
  background: var(--header-bg);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem;
  gap: 1rem;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
}

.site-brand-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.site-nav {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  flex: 1;
}

.nav-link {
  color: #fff;
  text-decoration: none;
  padding: 1rem 0;
  font-size: 15px;
  border-bottom: 3px solid transparent;
}

.nav-link:hover {
  opacity: 0.9;
}

.nav-link.active {
  border-bottom-color: #fff;
  font-weight: 500;
}

/* Page */
.page {
  max-width: 900px;
  margin: 2rem auto 4rem;
  padding: 0 1rem;
}

.card {
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 1.5rem 2rem 2rem;
}

.alert {
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
  font-size: 13px;
}

.alert-info {
  background: var(--alert-bg);
  color: var(--alert-text);
  border: 1px solid #ffd6d6;
}

/* Search */
.search-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.input-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}

.tracking-input {
  width: 100%;
  padding: 0.65rem 2rem 0.65rem 3.25rem;
  border: 1px solid var(--border);
  font-size: 15px;
  border-radius: var(--radius);
}

.tracking-input:focus {
  outline: none;
  border-color: var(--red);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-input {
  position: absolute;
  right: 0.25rem;
  font-size: 1.25rem;
  line-height: 1;
}

.trash-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  padding: 0.65rem 1.25rem;
  font-family: inherit;
}

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

.btn-primary:hover {
  background: var(--red-dark);
}

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

.btn-block {
  width: 100%;
  padding: 0.85rem;
  margin-top: 0.5rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  padding: 0.3rem 0.55rem 0.3rem 0.3rem;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.tag-text {
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.02em;
}

.tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.back-link {
  display: inline-block;
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.back-link:hover {
  color: var(--text);
  text-decoration: underline;
}

/* Tracking result — логотип SF на весь фон карточки */
.tracking-result {
  position: relative;
  border: none;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  overflow: hidden;
  min-height: 280px;
  background-color: #fff;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)),
    url('assets/sf-express-bg.png');
  background-repeat: no-repeat, no-repeat;
  background-position: center, center;
  background-size: auto, 100% 100%;
}

.tracking-result > * {
  position: relative;
  z-index: 1;
}

.tracking-result.hidden {
  display: none;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.waybill-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 13px;
  color: var(--text-muted);
}

.payment-title {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  font-size: 16px;
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.modal-title-row h2 {
  margin: 0;
}

.waybill-label strong {
  color: var(--text);
}

.eta-block {
  text-align: right;
}

.eta-title {
  display: block;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.eta-date {
  font-weight: 700;
  font-size: 18px;
  color: var(--red);
}

/* Route bar */
.route-bar {
  margin-bottom: 1.75rem;
}

.route-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
}

.route-point {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1;
  background: #fff;
  padding: 0 2px;
}

.route-point.origin {
  left: 0;
}

.route-point.dest {
  right: 0;
}

.route-progress {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--red);
  border-radius: 2px;
  width: 25%;
  transition: width 0.4s ease;
}

.route-marker {
  position: absolute;
  top: 50%;
  left: 25%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid var(--red);
  transition: left 0.4s ease;
}

/* Status log */
.status-log {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.status-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  padding-bottom: 1rem;
}

.status-item:not(:last-child) {
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 1rem;
}

.status-icon {
  width: 28px;
  height: 28px;
  background: var(--text);
  transform: rotate(45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-icon span {
  transform: rotate(-45deg);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.status-title {
  font-weight: 700;
  margin: 0;
  font-size: 15px;
}


.status-time {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0;
}

.status-desc {
  grid-column: 2;
  margin: 0;
  color: #1a1a1a;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}

/* Payment */
.payment-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 1rem;
  padding: 1.25rem 1.5rem;
  background: rgba(255, 255, 255, 0.55);
}

.payment-section.hidden {
  display: none;
}

.payment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.payment-header h3 {
  margin: 0;
  font-size: 16px;
}

.payment-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.payment-badge.pending,
#paymentBadge {
  background: #fef3c7;
  color: var(--pending);
  padding: 0.5rem 1rem;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.payment-badge.paid {
  background: #d1fae5;
  color: var(--paid);
}

.payment-desc {
  margin: 0 0 0.75rem;
  font-size: 14px;
  color: #1a1a1a;
  font-weight: 500;
  line-height: 1.6;
}

.payment-instruction {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  font-size: 13px;
  line-height: 1.55;
  color: #333;
  background: #f0f7ff;
  border: 1px solid #c5d9f0;
  border-left: 3px solid #1677ff;
  border-radius: var(--radius);
}

.payment-instruction--modal {
  margin: 0.25rem 0 1rem;
}

.payment-breakdown {
  margin: 0 0 1rem;
}

.payment-breakdown .row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 14px;
}

.payment-breakdown .row.total {
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  font-weight: 700;
}

.payment-breakdown .row.total dd {
  color: var(--red);
  font-size: 18px;
}

.payment-breakdown dt {
  margin: 0;
  color: var(--text-muted);
}

.payment-breakdown dd {
  margin: 0;
  font-weight: 500;
}

.btn-pay {
  padding: 0.75rem 2rem;
  font-size: 15px;
  cursor: pointer;
  border-radius: var(--radius);
  font-family: inherit;
  font-weight: 500;
}

.payment-note {
  margin: 0.75rem 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* CTA */
.cta-block {
  text-align: center;
  margin: 2rem 0 1.5rem;
}

.btn-login {
  padding: 0.85rem 3.5rem;
  font-size: 16px;
  border-radius: 24px;
}

.cta-hint {
  margin: 0.75rem 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--card);
  border-radius: 8px;
  padding: 1.75rem;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal h2 {
  margin: 0 0 0.5rem;
  font-size: 20px;
}

.modal-waybill,
.modal-amount {
  margin: 0 0 1rem;
  font-size: 14px;
}

.modal-amount strong {
  color: var(--red);
  font-size: 18px;
}

.payment-form label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 13px;
  color: var(--text-muted);
}

.payment-form input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
}

.payment-form input:focus {
  outline: none;
  border-color: var(--red);
}

.payment-qr-block {
  text-align: center;
  margin: 1rem 0 1.25rem;
  padding: 1.25rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
}

.payment-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.payment-brand-name {
  font-size: 20px;
  font-weight: 700;
  color: #1677FF;
  letter-spacing: 0.02em;
}

.alipay-logo {
  display: inline-flex;
  line-height: 0;
}

.payment-qr-frame {
  width: 200px;
  height: 200px;
  margin: 0 auto;
  padding: 10px;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.payment-qr {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  object-fit: contain;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.payment-qr-hint {
  margin: 0.85rem 0 0;
  font-size: 13px;
  color: #1a1a1a;
  font-weight: 500;
}

.modal-hint {
  margin: 1rem 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

/* Чат техподдержки SF — виджет в правом нижнем углу */
.support-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 360px;
  height: 520px;
  max-height: calc(100vh - 40px);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
  animation: support-chat-in 0.25s ease;
}

.support-chat.hidden {
  display: none;
}

@keyframes support-chat-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.nav-link--chat-open {
  border-bottom-color: #fff;
  font-weight: 500;
}

.support-chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 1rem 1.25rem;
  background: var(--header-bg);
  color: #fff;
  flex-shrink: 0;
}

.support-chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
}

.support-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
}

.support-chat-header h2,
.support-chat-subtitle {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

.support-chat-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
}

.support-chat-subtitle {
  margin: 0.15rem 0 0;
  font-size: 12px;
  opacity: 0.85;
}

.support-chat-status {
  font-size: 11px;
  background: #1a7f37;
  color: #fff;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.support-chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
  opacity: 0.9;
}

.support-chat-close:hover {
  opacity: 1;
}

.support-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.support-msg {
  max-width: 88%;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
}

.support-msg p {
  margin: 0;
}

.support-msg time {
  display: block;
  margin-top: 0.35rem;
  font-size: 11px;
  opacity: 0.65;
}

.support-msg--agent {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.support-msg--user {
  align-self: flex-end;
  background: var(--red);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.support-msg--user time {
  color: rgba(255, 255, 255, 0.85);
}

.support-chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}

.support-chat-form input {
  flex: 1;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}

.support-chat-form input:focus {
  outline: none;
  border-color: var(--red);
}

.support-chat-send {
  flex-shrink: 0;
  padding: 0.65rem 1rem;
}

@media (max-width: 600px) {
  .card {
    padding: 1rem;
  }

  .result-header {
    flex-direction: column;
  }

  .eta-block {
    text-align: left;
  }

  .support-chat {
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 12px 12px 0 0;
  }
}
