/* ============================================
   Portal — Customer Portal Layout & Components
   ============================================ */

/* ── Portal Layout ── */
.portal {
  display: flex;
  min-height: 100vh;
  padding-top: var(--header-height);
  background: var(--color-base);
}

/* ── Sidebar ── */
.portal__sidebar {
  width: 260px;
  background: var(--color-surface-dark);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  flex-shrink: 0;
  z-index: 10;
}

.portal__sidebar-header {
  padding: var(--space-6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.portal__company-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: var(--space-1);
  color: var(--color-white);
}

.portal__rep-info {
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.45);
  line-height: 1.4;
}

.portal__nav {
  flex: 1;
  padding: var(--space-4) 0;
}

.portal__nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  text-decoration: none;
  background: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  text-align: left;
}

.portal__nav-item:hover {
  color: var(--color-white);
  background: rgba(255, 255, 255, 0.05);
}

.portal__nav-item.is-active {
  color: var(--color-accent);
  background: rgba(232, 64, 0, 0.12);
  border-left-color: var(--color-accent);
  font-weight: var(--weight-semibold);
}

.portal__nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}

.portal__nav-item.is-active svg {
  opacity: 1;
}

.portal__nav-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: var(--space-3) var(--space-6);
}

.portal__nav-item--danger {
  color: rgba(255, 100, 80, 0.8);
}
.portal__nav-item--danger:hover {
  background: rgba(232, 64, 0, 0.1);
  color: var(--color-accent-light);
}

/* ── Main Content ── */
.portal__content {
  flex: 1;
  padding: var(--space-8);
  max-width: 1060px;
  min-width: 0;
}

/* ── Welcome Banner ── */
.portal__welcome {
  margin-bottom: var(--space-8);
}

.portal__welcome h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  margin-bottom: var(--space-1);
}

.portal__welcome p {
  font-size: var(--text-sm);
  color: var(--color-neutral);
}

.portal__rebate-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-tint);
  border-radius: 0;
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-accent);
  border-left: 3px solid var(--color-accent);
}

/* ── Metric Cards ── */
.portal__metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.metric-card {
  background: var(--color-white);
  border-radius: 0;
  border: 1.5px solid var(--color-border-light);
  padding: var(--space-6);
  transition: all var(--transition-base);
}

.metric-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.metric-card__value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: var(--weight-bold);
  color: var(--color-accent);
  margin-bottom: var(--space-1);
}

.metric-card__label {
  font-size: var(--text-sm);
  color: var(--color-neutral);
}

/* ── Section Card ── */
.portal__section {
  background: var(--color-white);
  border-radius: 0;
  border: 1.5px solid var(--color-border-light);
  overflow: hidden;
  margin-bottom: var(--space-6);
}

.portal__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.portal__section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
}

.portal__section-body {
  padding: var(--space-6);
}

/* ── Filter Bar ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  align-items: center;
}

.filter-pills {
  display: flex;
  gap: var(--space-1);
  background: var(--color-surface-alt);
  border-radius: 0;
  padding: 2px;
}

.filter-pill {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: 0;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: none;
  color: var(--color-neutral);
  white-space: nowrap;
}

.filter-pill:hover {
  color: var(--color-primary);
}

.filter-pill.is-active {
  background: var(--color-accent);
  color: var(--color-white);
  box-shadow: none;
}

.filter-search {
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--color-border-light);
  border-radius: 0;
  font-size: var(--text-sm);
  width: 200px;
  transition: border-color var(--transition-fast);
}

.filter-search:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* ── Status Badges (extended) ── */
.status-badge--submitted {
  background: #F0F0ED;
  color: var(--color-neutral);
}

.status-badge--in_review {
  background: #FFF3CD;
  color: #856404;
}

.status-badge--approved {
  background: #E6F5EC;
  color: var(--color-success);
}

.status-badge--in_production {
  background: #dbeafe;
  color: #1e40af;
}

.status-badge--shipped {
  background: #d1fae5;
  color: #065f46;
}

.status-badge--complete {
  background: var(--color-accent);
  color: var(--color-white);
}

/* ── Order Detail Expansion ── */
.order-detail {
  background: var(--color-base);
  border-top: 1px solid var(--color-border);
  padding: var(--space-6);
  animation: fadeSlideDown 0.3s ease;
}

@keyframes fadeSlideDown {
  from { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
  to { opacity: 1; max-height: 2000px; }
}

.order-detail__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

.order-detail__section h4 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-neutral);
  margin-bottom: var(--space-3);
}

.order-detail__row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-border);
}

.order-detail__row:last-child {
  border-bottom: none;
}

/* ── Status Timeline ── */
.status-timeline {
  display: flex;
  gap: 0;
  margin: var(--space-4) 0;
}

.status-timeline__step {
  flex: 1;
  text-align: center;
  position: relative;
  padding-top: var(--space-8);
}

.status-timeline__step::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-border);
}

.status-timeline__step:first-child::before {
  left: 50%;
}

.status-timeline__step:last-child::before {
  right: 50%;
}

.status-timeline__dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-border);
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--color-white);
}

.status-timeline__step.is-reached .status-timeline__dot {
  background: var(--color-accent);
}

.status-timeline__step.is-current .status-timeline__dot {
  background: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-tint);
}

.status-timeline__label {
  font-size: var(--text-xs);
  color: var(--color-neutral);
  margin-top: var(--space-1);
}

.status-timeline__date {
  font-size: 10px;
  color: var(--color-neutral);
}

/* ── Product Library Cards ── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.product-card {
  background: var(--color-white);
  border-radius: 0;
  border: 1.5px solid var(--color-border-light);
  overflow: hidden;
  transition: all var(--transition-base);
}

.product-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.product-card.is-unavailable {
  opacity: 0.6;
  pointer-events: auto;
}

.product-card.is-unavailable:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--color-border);
}

.product-card__header {
  padding: var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.product-card__type {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}

.product-card__type--label {
  background: #dbeafe;
  color: #1e40af;
}

.product-card__type--pouch {
  background: #fef3c7;
  color: #92400e;
}

.product-card__type--rollstock {
  background: var(--color-tint);
  color: var(--color-accent);
}

.product-card__unavailable {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-error);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: #fde8e8;
}

.product-card__body {
  padding: 0 var(--space-4) var(--space-4);
}

.product-card__name {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.product-card__name-edit {
  cursor: pointer;
  color: var(--color-neutral);
  transition: color var(--transition-fast);
}

.product-card__name-edit:hover {
  color: var(--color-accent);
}

.product-card__spec {
  font-size: var(--text-sm);
  color: var(--color-neutral);
  line-height: 1.5;
  margin-bottom: var(--space-3);
}

.product-card__prices {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  background: var(--color-base);
  border-radius: var(--radius-md);
}

.product-card__price-label {
  font-size: var(--text-xs);
  color: var(--color-neutral);
}

.product-card__price-value {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
}

.price-change--up {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: #d97706;
  background: #fef3c7;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
}

.price-change--down {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
  background: var(--color-tint);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
}

.product-card__footer {
  padding: 0 var(--space-4) var(--space-4);
  display: flex;
  gap: var(--space-2);
}

/* ── Settings Sections ── */
.settings-section {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--color-border);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-section__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  margin-bottom: var(--space-6);
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.settings-readonly {
  font-size: var(--text-sm);
  padding: var(--space-3) var(--space-4);
  background: var(--color-base);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  color: var(--color-neutral);
}

/* Toggle Switch */
.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  padding: var(--space-3) 0;
}

.toggle__switch {
  width: 44px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  position: relative;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.toggle__switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-white);
  transition: transform var(--transition-fast);
  box-shadow: var(--shadow-xs);
}

.toggle input:checked + .toggle__switch {
  background: var(--color-accent);
}

.toggle input:checked + .toggle__switch::after {
  transform: translateX(20px);
}

.toggle input {
  display: none;
}

.toggle__label {
  font-size: var(--text-sm);
}

/* ── Address Cards ── */
.address-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  transition: border-color var(--transition-fast);
}

.address-card:hover {
  border-color: var(--color-neutral);
}

.address-card__body {
  font-size: var(--text-sm);
  line-height: 1.6;
}

.address-card__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
  margin-bottom: var(--space-1);
}

/* ── Loading Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, #e8e8e5 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton--text { height: 14px; margin-bottom: var(--space-2); width: 70%; }
.skeleton--title { height: 24px; margin-bottom: var(--space-3); width: 40%; }
.skeleton--card { height: 200px; }
.skeleton--metric { height: 100px; }

/* ── Form Alerts ── */
.form-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.form-alert--error {
  background: #fde8e8;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.form-alert--success {
  background: #E6F5EC;
  color: var(--color-success);
  border: 1px solid rgba(26, 140, 91, 0.2);
}

.form-alert--info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

/* ── Password Checklist ── */
.password-checklist {
  margin-top: var(--space-2);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-1);
}

.pw-check {
  font-size: var(--text-xs);
  color: var(--color-neutral);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.pw-check.is-met {
  color: var(--color-success);
}

.pw-check span {
  width: 14px;
  text-align: center;
}

/* Password strength bar colors */
.password-strength__bar.is-weak { background: var(--color-error); }
.password-strength__bar.is-good { background: var(--color-warning); }
.password-strength__bar.is-strong { background: var(--color-success); }

/* ── Form Input Wrap (for toggles) ── */
.form-input-wrap {
  position: relative;
}

.form-input-wrap .form-input {
  padding-right: 44px;
}

.form-input-toggle {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-neutral);
  padding: var(--space-2);
  transition: color var(--transition-fast);
}

.form-input-toggle:hover {
  color: var(--color-primary);
}

/* Form row between (remember me + forgot) */
.form-row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
  margin-top: calc(-1 * var(--space-2));
}

.form-checkbox--sm .form-checkbox__label {
  font-size: var(--text-xs);
}

/* ── Reorder Banner ── */
.reorder-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
}

/* ── Orders Table ── */
.orders-table {
  width: 100%;
  border-collapse: collapse;
}

.orders-table thead {
  background: var(--color-base);
}

.orders-table th {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-neutral);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  white-space: nowrap;
}

.orders-table td {
  font-size: var(--text-sm);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.orders-table tbody tr {
  transition: background var(--transition-fast);
  cursor: pointer;
}

.orders-table tbody tr:hover {
  background: var(--color-tint);
}

.orders-table tbody tr.order-detail-row {
  cursor: default;
}

.orders-table tbody tr.order-detail-row:hover {
  background: transparent;
}

.orders-table__link {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
  text-decoration: none;
  white-space: nowrap;
}

.orders-table__link:hover {
  text-decoration: underline;
}

/* ── Status Badge Base ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  white-space: nowrap;
  line-height: 1.4;
}

.status-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

/* ── Toast Notification ── */
.toast {
  position: fixed;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: var(--color-white);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-lg);
  transition: bottom 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 9999;
  white-space: nowrap;
}

.toast.is-visible {
  bottom: var(--space-8);
}
.toast--success { background: hsl(145, 65%, 38%); }
.toast--error   { background: hsl(0, 65%, 50%); }

/* ── Avatar ── */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
}

/* ── Form Divider ── */
.form-divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-6) 0;
  font-size: var(--text-sm);
  color: var(--color-neutral);
}

.form-divider::before,
.form-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* ── Password Strength Base ── */
.password-strength {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.password-strength__bar {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--color-border);
  transition: background 0.3s ease;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .portal__sidebar {
    width: 220px;
  }
  .portal__metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .order-detail__grid {
    grid-template-columns: 1fr;
  }
}

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

@media (max-width: 768px) {
  .portal {
    flex-direction: column;
  }
  .portal__sidebar {
    width: 100%;
    height: auto;
    position: relative;
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .portal__nav {
    display: flex;
    gap: 0;
    padding: 0;
    overflow-x: auto;
  }
  .portal__nav-item {
    padding: var(--space-3) var(--space-4);
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }
  .portal__nav-item.is-active {
    border-left-color: transparent;
    border-bottom-color: var(--color-accent);
  }
  .portal__nav-divider { display: none; }
  .portal__content {
    padding: var(--space-4);
  }
  .portal__metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .product-grid {
    grid-template-columns: 1fr;
  }
  .settings-row {
    grid-template-columns: 1fr;
  }
}
