/*
 * GFL Shipping Calculator — Isolated CSS
 * Uses existing portal CSS variables only.
 * No overrides to global portal styles.
 */

/* ── Fix 4: Page containers fill .main correctly ─────────────────────────── */
#page-shipping-rates,
#page-admin-rate-searches {
  width: 100%;
  min-width: 0;
}

/* ── Fix 2/4: Page header layout ─────────────────────────────────────────── */
.sc-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.sc-page-title {
  min-width: 0;
}

.sc-page-title h1 {
  margin: 0 0 5px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sc-page-title p {
  margin: 0;
  font-size: 0.83rem;
  color: var(--muted, #6B7280);
}

.sc-page-badge {
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 6px 10px;
  border-radius: 999px;
  background: #FEF3C7;
  border: 1px solid #FCD34D;
  color: #92400E;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── Fix 4: Destination grid ──────────────────────────────────────────────── */
.sc-destination-grid {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(150px, 1fr) minmax(180px, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

/* ── Form fields ──────────────────────────────────────────────────────────── */
.sc-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.sc-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #374151;
  letter-spacing: 0.3px;
}

.sc-field input,
.sc-field select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1.5px solid var(--border, #E5E7EB);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #F9FAFB;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.sc-field input:focus,
.sc-field select:focus {
  border-color: var(--blue, #2563EB);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: #fff;
}

/* ── Field-level error text ───────────────────────────────────────────────── */
.sc-field-error {
  font-size: 0.73rem;
  color: #DC2626;
  margin-top: 2px;
  min-height: 0;
  line-height: 1.3;
}

/* ── Carrier toggles ──────────────────────────────────────────────────────── */
.sc-carriers {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
}

/* Fix 5: normalized carrier button */
.sc-carrier-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  min-width: 128px;
  justify-content: flex-start;
  padding: 8px 14px;
  border: 2px solid var(--border, #E5E7EB);
  border-radius: 10px;
  background: #F9FAFB;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6B7280;
  transition: all .15s;
  font-family: inherit;
  user-select: none;
}

.sc-carrier-btn.active {
  border-color: var(--blue, #2563EB);
  background: #eff6ff;
  color: var(--blue, #2563EB);
}

.sc-carrier-btn:hover {
  border-color: #9CA3AF;
  background: #fff;
}

/* Fix 5: logo frame inside toggle button */
.sc-carrier-logo-frame {
  width: 64px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--border, #E5E7EB);
  border-radius: 8px;
  padding: 4px 6px;
  box-sizing: border-box;
}

/* Inside result cards (no border) */
.sc-rate-card .sc-carrier-logo-frame {
  background: transparent;
  border: none;
}

.sc-carrier-logo {
  max-width: 52px;
  max-height: 32px;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Inside toggle buttons — smaller, no border */
.sc-carrier-toggle-logo {
  width: 58px;
  height: 28px;
  padding: 2px 4px;
  border: 0;
  background: transparent;
}

/* ── Package rows ─────────────────────────────────────────────────────────── */
.sc-box-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 0;
}

.sc-box-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #F9FAFB;
  border: 1px solid var(--border, #E5E7EB);
  border-radius: 10px;
  padding: 12px 14px;
  flex-wrap: wrap;
}

.sc-box-num {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted, #6B7280);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.sc-box-fields {
  display: grid;
  grid-template-columns: 70px 1fr 1fr 1fr 1fr;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.sc-remove-btn {
  background: none;
  border: 1.5px solid #E5E7EB;
  border-radius: 7px;
  color: #9CA3AF;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 0.85rem;
  transition: all .15s;
  align-self: flex-end;
  flex-shrink: 0;
}

.sc-remove-btn:hover {
  background: #FEF2F2;
  border-color: #FCA5A5;
  color: #DC2626;
}

/* ── Action buttons ───────────────────────────────────────────────────────── */
.sc-btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

.sc-btn-primary {
  background: var(--black, #111827);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 11px 24px;
  font-size: 0.93rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}

.sc-btn-primary:hover  { background: #1F2937; transform: translateY(-1px); }
.sc-btn-primary:disabled { background: #9CA3AF; cursor: not-allowed; transform: none; }

.sc-btn-secondary {
  background: none;
  border: 1.5px solid var(--border, #E5E7EB);
  border-radius: 9px;
  padding: 10px 18px;
  font-size: 0.88rem;
  color: #374151;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}

.sc-btn-secondary:hover { background: #F3F4F6; }

/* ── Results ──────────────────────────────────────────────────────────────── */
#sc-results {
  margin-top: 20px;
}

.sc-results-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sc-rate-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--card, #FFFFFF);
  border: 1.5px solid var(--border, #E5E7EB);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  flex-wrap: wrap;
  transition: box-shadow .15s;
}

.sc-rate-card.cheapest {
  border-color: #10B981;
  background: #F0FDF4;
}

.sc-rate-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }

.sc-rate-info {
  flex: 1;
  min-width: 0;
}

.sc-carrier-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--black, #111827);
}

.sc-service-name {
  font-size: 0.80rem;
  color: var(--muted, #6B7280);
  margin-top: 2px;
}

.sc-rate-prices {
  text-align: right;
  flex-shrink: 0;
}

.sc-total-price {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--black, #111827);
  letter-spacing: -0.5px;
  line-height: 1;
}

.sc-per-box {
  font-size: 0.75rem;
  color: var(--muted, #6B7280);
  margin-top: 3px;
}

.sc-badges {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.sc-badge-estimate {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FCD34D;
  border-radius: 4px;
  padding: 2px 7px;
}

.sc-badge-cheapest {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #6EE7B7;
  border-radius: 4px;
  padding: 2px 7px;
}

.sc-unavailable {
  font-size: 0.82rem;
  color: var(--muted, #6B7280);
  font-style: italic;
}

/* ── States ───────────────────────────────────────────────────────────────── */
.sc-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--muted, #6B7280);
  font-size: 0.88rem;
}

.sc-spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border, #E5E7EB);
  border-top-color: var(--blue, #2563EB);
  border-radius: 50%;
  animation: sc-spin .7s linear infinite;
  margin-bottom: 12px;
}

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

.sc-error-state {
  background: #FEF2F2;
  border: 1px solid #FCA5A5;
  border-radius: 10px;
  padding: 16px 20px;
  color: #991B1B;
  font-size: 0.88rem;
  margin-top: 16px;
}

/* ── Disclaimer ───────────────────────────────────────────────────────────── */
.sc-disclaimer {
  font-size: 0.75rem;
  color: #9CA3AF;
  line-height: 1.6;
  padding: 14px 0 0;
  border-top: 1px solid var(--border, #E5E7EB);
  margin-top: 12px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sc-destination-grid {
    grid-template-columns: 1fr 1fr;
  }

  .sc-destination-city {
    grid-column: 1 / -1;
  }

  .sc-box-fields {
    grid-template-columns: 60px 1fr 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .sc-page-header {
    flex-direction: column;
    gap: 10px;
  }

  .sc-destination-grid {
    grid-template-columns: 1fr;
  }

  .sc-destination-city {
    grid-column: auto;
  }

  .sc-box-fields {
    grid-template-columns: 60px 1fr 1fr;
  }

  .sc-rate-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .sc-rate-prices {
    text-align: left;
    width: 100%;
  }

  .sc-carrier-logo-frame {
    width: 56px;
    height: 36px;
  }
}

@media (max-width: 400px) {
  .sc-box-fields {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── Google Places Autocomplete — v2 additions ───────────────────────────── */

/* Isolated overflow fix for the shipping card — does not touch global .card */
#page-shipping-rates .sc-shipping-card {
  overflow: visible;
}

/* Destination search wrapper */
.sc-destination-search {
  margin-bottom: 16px;
  position: relative;
  z-index: 5;
}

/* Autocomplete host container */
#sc-place-autocomplete-host {
  width: 100%;
  min-width: 0;
}

/* Google Places element styling */
#sc-place-autocomplete-host gmp-place-autocomplete {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 8px;
  color-scheme: light;
}

/* ── Custom country search dropdown — v3 ───────────────────────────────────── */

/* Wrapper: establishes stacking context so dropdown overlays card content */
.sc-country-search-wrap {
  position: relative;
}

/* Visible search input — full width, matches other inputs */
#sc-country-search {
  width: 100%;
  box-sizing: border-box;
}

/* Dropdown list container */
.sc-country-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: #ffffff;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: -1px;
}

/* Individual option row */
.sc-country-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.875rem;
  color: #111827;
  border-bottom: 1px solid #f3f4f6;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s;
}

.sc-country-option:last-child {
  border-bottom: none;
}

.sc-country-option:hover,
.sc-country-option--active {
  background: #f0f7ff;
}

/* Country name portion */
.sc-country-option-name {
  flex: 1;
  font-weight: 500;
}

/* ISO code badge */
.sc-country-option-code {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  background: #f3f4f6;
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
  font-family: monospace, monospace;
}

/* Ensure card overflow visible so dropdown is not clipped */
#page-shipping-rates .sc-shipping-card {
  overflow: visible;
}

/* ── Section titles (Standard / Express) ──────────────────────────────── */
.sc-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6b7280;
  padding: 14px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}
.sc-section-title:first-of-type {
  border-top: none;
  padding-top: 0;
}

/* ── Transit time line ─────────────────────────────────────────────────── */
.sc-transit-time {
  font-size: 0.78rem;
  color: #6b7280;
  margin: 2px 0 5px;
}

/* ── Source/status badges ──────────────────────────────────────────────── */
.sc-badge-live {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #d1fae5;
  color: #065f46;
  letter-spacing: 0.3px;
}
.sc-badge-live::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #10b981;
  flex-shrink: 0;
}

.sc-badge-estimate {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #fef3c7;
  color: #92400e;
}

/* ── Best Price badge ──────────────────────────────────────────────────── */
.sc-badge-cheapest {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #ede9fe;
  color: #5b21b6;
}

/* ── Fastest badge ─────────────────────────────────────────────────────── */
.sc-badge-fastest {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #fff7ed;
  color: #c2410c;
}
