/*
Theme Name: Emerson Israel RMA
Theme URI: https://emerson.co.il/
Author: Avraham Avniloff
Description: Emerson Israel service portal. Welcome landing (Diagnostic Assistant + RMA) and the RMA (Return Material Authorization) form.
Version: 1.3
Text Domain: emerson-israel-rma
*/

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap");

/* Design tokens — mirrored from the Diagnostic Assistant app (src/styles/tokens.css)
   so the RMA form and the diagnostic wizard share one visual language.
   The --rma-* names are kept because the existing form CSS/JS reference them. */
:root {
  --rma-bg-1: #f0f2f5;
  --rma-bg-2: #f0f2f5;
  --rma-surface: #ffffff;
  --rma-surface-2: #f7f8fa;
  --rma-text: #1a2840;
  --rma-text-2: #4e5a6a;
  --rma-muted: #6a7888;
  --rma-border: #d8dde6;
  --rma-border-light: #eaecf0;
  --rma-accent: #18468b;
  --rma-accent-dark: #123566;
  --rma-accent-soft: #eef1f6;
  --rma-red: #c0392b;
  --rma-red-dark: #a5301f;
  --rma-red-soft: #fdecea;
  --rma-success: #2e7d32;
  --rma-error: #c0392b;
  --rma-warning: #f57f17;
  --rma-shadow: 0 20px 60px rgba(26, 40, 64, 0.1);
  --rma-radius-lg: 12px;
  --rma-radius-md: 8px;
  --rma-radius-sm: 4px;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--rma-text);
  overflow-x: hidden;
  background: var(--rma-bg-1);
  -webkit-font-smoothing: antialiased;
}

.site-main {
  padding: 0 0 48px;
}

.rma-page {
  direction: ltr !important;
  text-align: left;
}

.rma-page * {
  direction: ltr !important;
  unicode-bidi: isolate;
}

.rma-form input,
.rma-form textarea,
.rma-form select {
  -webkit-user-select: text;
  user-select: text;
}

/* Blue app bar — same pattern as the Diagnostic Assistant header, mobile-first:
   phone gets a compact single-line title, hidden subtitle and a small logo;
   the full desktop treatment (bigger title, visible subtitle, fixed height)
   only kicks in from 768px, same breakpoint the diagnostic app uses. */
.rma-appbar {
  background: var(--rma-accent);
  color: #fff;
  padding: 12px 0;
}

.rma-appbar__inner {
  width: 1200px;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rma-appbar__titles {
  min-width: 0;
}

.rma-appbar__title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.rma-appbar__sub {
  display: none; /* subtitle is noise on a phone, same as the diagnostic header */
}

.rma-appbar__logo {
  height: 32px;
  width: auto;
  flex: none;
  display: block;
}

@media (min-width: 768px) {
  .rma-appbar {
    padding: 16px 0;
  }
  .rma-appbar__inner {
    max-width: calc(100% - 48px);
    height: 50px;
    gap: 16px;
    padding-right: 10px;
  }
  .rma-appbar__title {
    font-size: 18px;
  }
  .rma-appbar__sub {
    display: block;
    margin: 2px 0 0;
    font-size: 14px;
    opacity: 0.85;
  }
  .rma-appbar__logo {
    height: 48px;
  }
}

.rma-shell {
  width: 1200px;
  max-width: calc(100% - 48px);
  margin: 24px auto 0;
  display: grid;
  gap: 24px;
}

.rma-form {
  display: grid;
  gap: 24px;
}

.rma-card {
  background: var(--rma-surface);
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-lg);
  padding: 24px;
  box-shadow: var(--rma-shadow);
  position: relative;
  overflow: hidden;
  animation: rma-fade-up 0.45s ease both;
}

.rma-card:nth-of-type(2) {
  animation-delay: 0.05s;
}

.rma-card:nth-of-type(3) {
  animation-delay: 0.1s;
}

.rma-card:nth-of-type(4) {
  animation-delay: 0.15s;
}

.rma-card:nth-of-type(5) {
  animation-delay: 0.2s;
}

/* section head: red dot + uppercase title, mirroring the app's .frame-head */
.rma-card__head {
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rma-border-light);
}

.rma-card__head h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.25;
}

.rma-card__head h2::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--rma-red);
  flex: none;
}

.rma-card__head p {
  margin: 6px 0 0 25px;
  font-size: 14px;
  color: var(--rma-muted);
}

.rma-grid {
  display: grid;
  gap: 16px 24px;
}

.rma-grid > * {
  min-width: 0;
}

.rma-grid + .rma-grid {
  margin-top: 12px;
}

.rma-grid--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.rma-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rma-grid.rma-grid--3 {
  margin-top: 15px;
}

.rma-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.rma-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.rma-field span {
  font-size: 12px;
  font-weight: 700;
  color: var(--rma-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.rma-field--full {
  grid-column: 1 / -1;
}

.erma-control {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1.5px solid var(--rma-border);
  border-radius: var(--rma-radius-sm);
  background: var(--rma-surface-2);
  color: var(--rma-text);
  font: inherit;
  font-size: 14px;
  padding: 12px;
  box-sizing: border-box;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

textarea.erma-control {
  min-height: 88px;
  resize: vertical;
}

.erma-reason {
  min-height: 160px;
}

.erma-control::placeholder {
  color: var(--rma-muted);
}

.erma-control[readonly] {
  background: var(--rma-surface-2);
  color: var(--rma-muted);
  cursor: default;
}

.erma-control:disabled {
  opacity: 0.75;
  cursor: default;
}

.erma-control:focus,
.erma-control:focus-visible {
  outline: none;
  border-color: var(--rma-red);
  background: var(--rma-surface);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

.erma-control[aria-invalid="true"] {
  border-color: var(--rma-red);
  background: var(--rma-red-soft);
}

select.erma-control {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpolyline points='1%201%205%205%209%201' fill='none' stroke='%23435a76' stroke-width='1.35' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 10px 6px;
  background-position: calc(100% - 12px) 50%;
  padding-right: 32px;
  cursor: pointer;
}

select.erma-control::-ms-expand {
  display: none;
}

.rma-subcard {
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-md);
  padding: 16px;
  background: var(--rma-surface-2);
}

.rma-subcard h3 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--rma-muted);
}

.rma-address-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  border: 1.5px solid var(--rma-border);
  border-radius: var(--rma-radius-sm);
  overflow: hidden;
  background: var(--rma-surface);
}

.rma-address-grid > .erma-control {
  border: 0;
  border-radius: 0;
  min-height: 44px;
}

.rma-address-grid > .erma-control:not(:last-child) {
  border-right: 1px solid var(--rma-border-light);
}

.rma-address-grid select.erma-control {
  background-position: calc(100% - 10px) 50%;
}

.rma-serial-panel {
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-md);
  background: var(--rma-surface-2);
  padding: 16px;
  margin-bottom: 16px;
  display: grid;
  gap: 12px;
}

.rma-serial-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.rma-serial-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.rma-btn--small {
  min-height: 40px;
  padding: 8px 16px;
  font-size: 14px;
}

.rma-serial-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rma-serial-count {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--rma-muted);
}

.rma-serial-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.rma-serial-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-md);
  background: var(--rma-surface);
  padding: 8px 12px;
}

.rma-serial-item--empty {
  justify-content: flex-start;
  color: var(--rma-muted);
  font-style: italic;
}

.rma-serial-value {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 14px;
  color: var(--rma-text);
  word-break: break-word;
}

.rma-choice {
  margin: 0;
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-md);
  padding: 12px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--rma-surface-2);
}

.rma-choice legend {
  padding: 0 6px;
  font-weight: 700;
  font-size: 12px;
  color: var(--rma-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rma-choice label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--rma-text);
  font-size: 14px;
}

input.erma-control[type="radio"] {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
}

input.erma-control[type="date"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* iOS Safari/Chrome: native date control may overflow grid cells */
@supports (-webkit-touch-callout: none) {
  input.erma-control[type="date"] {
    width: -webkit-fill-available;
    max-width: 100%;
    min-width: 0;
  }

  input.erma-control[type="date"]::-webkit-date-and-time-value {
    min-width: 0;
    width: 100%;
    text-align: left;
  }
}

.rma-statement {
  margin: 0;
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-md);
  background: var(--rma-surface-2);
  padding: 16px;
  font-size: 14px;
  color: var(--rma-text-2);
}

.rma-note {
  margin-top: 16px;
  border-left: 4px solid var(--rma-warning);
  background: #fff8e1;
  border-radius: 0 var(--rma-radius-sm) var(--rma-radius-sm) 0;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--rma-text-2);
}

.rma-footer-warning {
  margin: 16px 0 0;
  font-size: 14px;
  color: var(--rma-red);
  font-weight: 600;
}

.rma-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--rma-border-light);
  border-radius: var(--rma-radius-lg);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--rma-shadow);
}

.rma-actions__credit {
  margin: 0;
  margin-right: auto;
  font-size: 12px;
  color: var(--rma-muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.rma-btn,
.erma-btn {
  appearance: none;
  border: 1.5px solid transparent;
  border-radius: var(--rma-radius-md);
  min-height: 44px;
  padding: 12px 24px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}

.rma-btn:active,
.erma-btn:active {
  transform: translateY(1px);
}

.rma-btn:focus-visible,
.erma-btn:focus-visible {
  outline: 2px solid var(--rma-red);
  outline-offset: 2px;
}

.rma-btn--ghost {
  color: var(--rma-muted);
  border-color: var(--rma-border);
  background: transparent;
}

.rma-btn--ghost:hover {
  border-color: var(--rma-muted);
  color: var(--rma-text-2);
}

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

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

body.erma-popup-open {
  overflow: hidden;
}

.erma-popup-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 9999;
}

.erma-popup-root[hidden] {
  display: none !important;
}

.erma-popup-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(3, 20, 41, 0.48);
  cursor: pointer;
}

.erma-popup {
  position: relative;
  width: min(500px, calc(100% - 24px));
  border-radius: var(--rma-radius-lg);
  border: 1px solid var(--rma-border-light);
  background: #fff;
  box-shadow: 0 24px 70px rgba(26, 40, 64, 0.28);
  overflow: hidden;
}

.erma-popup::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--rma-accent);
}

.erma-popup--success::before {
  background: var(--rma-success);
}

.erma-popup--error::before {
  background: var(--rma-error);
}

.erma-popup--warning::before {
  background: var(--rma-warning);
}

.erma-popup-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--rma-border-light);
}

.erma-popup-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.erma-popup-close {
  border: 0;
  background: transparent;
  color: var(--rma-muted);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.erma-popup-close:hover {
  color: var(--rma-text);
}

.erma-popup-body {
  padding: 24px 24px 16px;
}

.erma-popup-message {
  margin: 0;
  color: var(--rma-text-2);
  font-size: 14px;
  line-height: 1.5;
}

.erma-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px 24px;
}

.rma-popup-btn {
  min-width: 96px;
  border-color: var(--rma-border);
  color: var(--rma-text);
  background: #fff;
}

.rma-popup-btn:hover {
  border-color: var(--rma-muted);
}

@keyframes rma-fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1120px) {
  .rma-grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rma-grid--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .site-main {
    padding: 0 0 32px;
  }

  .rma-shell {
    max-width: calc(100% - 24px);
    gap: 16px;
    margin-top: 16px;
  }

  .rma-card {
    padding: 16px;
  }

  .rma-grid--4,
  .rma-grid--3,
  .rma-grid--2 {
    grid-template-columns: 1fr;
  }

  .rma-address-grid {
    grid-template-columns: 1fr;
  }

  .rma-address-grid > .erma-control:not(:last-child) {
    border-right: 0;
    border-bottom: 1px solid #d2dcea;
  }

  .rma-serial-entry {
    grid-template-columns: 1fr;
  }

  .rma-serial-actions {
    width: 100%;
  }

  .rma-serial-actions .rma-btn {
    flex: 1;
  }

  .rma-serial-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .rma-serial-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .rma-serial-item .rma-serial-value {
    flex: 1 1 auto;
    min-width: 0;
    padding-right: 8px;
  }

  .rma-serial-item .rma-btn {
    flex: 0 0 auto;
  }

  .rma-actions {
    padding: 12px;
    flex-wrap: wrap;
  }

  .rma-actions__credit {
    width: 100%;
    margin-right: 0;
    font-size: 12px;
    text-align: center;
  }

  .rma-btn,
  .erma-btn {
    flex: 1;
    justify-content: center;
  }
}

@media print {
  body {
    background: #fff;
  }

  .site-main {
    padding: 0;
  }

  .rma-appbar {
    background: #fff;
    color: var(--rma-text);
  }

  .rma-card {
    box-shadow: none;
    border: 1px solid var(--rma-border);
    background: #fff;
  }

  .rma-actions,
  .erma-popup-root {
    display: none !important;
  }
}
