/* ==========================================================================
   Opportunity Form — Drawer
   Prefix: opf-   Uses SMA Design System CSS variables
   ========================================================================== */

/* ── Overlay ─────────────────────────────────────────────────────────────── */
.opf-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.opf-overlay:not([aria-hidden="true"]) {
  opacity: 1;
  pointer-events: all;
}

/* ── Drawer ──────────────────────────────────────────────────────────────── */
.opf-drawer {
  background: #fff;
  width: 100%;
  max-width: 520px;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.10);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  font-family: var(--sma-font-family, inherit);
}

.opf-overlay:not([aria-hidden="true"]) .opf-drawer {
  transform: translateX(0);
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.opf-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--sma-gray-100, #f3f4f6);
  flex-shrink: 0;
}

.opf-drawer-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--sma-gray-900, #111827);
  font-family: var(--sma-font-family, inherit);
  letter-spacing: -0.01em;
}

.opf-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: var(--sma-gray-100, #f3f4f6);
  color: var(--sma-gray-500, #6b7280);
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
  transition: background 0.15s, color 0.15s;
  font-family: var(--sma-font-family, inherit);
  flex-shrink: 0;
}

.opf-close-btn:hover {
  background: var(--sma-gray-200, #e5e7eb);
  color: var(--sma-gray-800, #1f2937);
}

/* ── Scrollable body ─────────────────────────────────────────────────────── */
.opf-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ── Form ────────────────────────────────────────────────────────────────── */
.opf-form {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ── Sections ────────────────────────────────────────────────────────────── */
.opf-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.opf-section-title {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--sma-gray-400, #9ca3af);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--sma-font-family, inherit);
}

/* ── Grid row ────────────────────────────────────────────────────────────── */
.opf-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

/* ── Field ───────────────────────────────────────────────────────────────── */
.opf-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.opf-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--sma-gray-700, #374151);
  font-family: var(--sma-font-family, inherit);
  display: block;
}

.opf-required {
  color: #ef4444;
  margin-left: 1px;
}

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.opf-input,
.opf-select,
.opf-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--sma-gray-200, #e5e7eb);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--sma-font-family, inherit);
  color: var(--sma-gray-900, #111827);
  background: var(--sma-gray-50, #f9fafb);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  line-height: 1.5;
}

/* Restore native appearance for date input so the picker stays functional */
.opf-date {
  appearance: auto;
  -webkit-appearance: auto;
}

.opf-input::placeholder,
.opf-textarea::placeholder {
  color: var(--sma-gray-400, #9ca3af);
}

.opf-input:hover,
.opf-select:hover,
.opf-textarea:hover {
  border-color: var(--sma-gray-300, #d1d5db);
}

.opf-input:focus,
.opf-select:focus,
.opf-textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--sma-primary, #0052CC);
  box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.10);
}

.opf-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239ca3af' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
  cursor: pointer;
}

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

/* ── Radio — pill toggle style ───────────────────────────────────────────── */
.opf-radio-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.opf-radio {
  display: inline-flex;
  cursor: pointer;
  font-family: var(--sma-font-family, inherit);
  position: relative;
}

.opf-radio input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  pointer-events: none;
}

.opf-radio span {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  border: 1.5px solid var(--sma-gray-200, #e5e7eb);
  border-radius: 100px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sma-gray-600, #4b5563);
  background: var(--sma-gray-50, #f9fafb);
  transition: all 0.15s;
  user-select: none;
  line-height: 1;
}

.opf-radio:hover span {
  border-color: var(--sma-gray-300, #d1d5db);
  background: #fff;
  color: var(--sma-gray-800, #1f2937);
}

.opf-radio input[type="radio"]:checked + span {
  border-color: var(--sma-primary, #0052CC);
  background: rgba(0, 82, 204, 0.06);
  color: var(--sma-primary, #0052CC);
  font-weight: 600;
}

.opf-radio input[type="radio"]:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.15);
}

/* ── Success state ───────────────────────────────────────────────────────── */
.opf-success {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 48px 32px;
  flex: 1;
}

.opf-success.is-visible {
  display: flex;
}

.opf-success-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}

.opf-success-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--sma-gray-900, #111827);
  font-family: var(--sma-font-family, inherit);
  letter-spacing: -0.01em;
}

.opf-success-body {
  margin: 0;
  font-size: 14px;
  color: var(--sma-gray-500, #6b7280);
  max-width: 340px;
  line-height: 1.6;
  font-family: var(--sma-font-family, inherit);
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.opf-drawer-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--sma-gray-100, #f3f4f6);
  padding: 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
}

/* ── Field error state ───────────────────────────────────────────────────── */
/* The form is `novalidate`, so nothing native marks an empty required field.
   These are applied by opportunity-form.js on a failed submit and removed as
   soon as the user touches the field again. */
.opf-field-error .opf-label {
  color: #e11d48;
}

.opf-field-error .opf-input,
.opf-field-error .opf-select,
.opf-field-error .opf-textarea {
  border-color: #fda4af;
  background: #fff1f2;
}

.opf-field-error .opf-input:focus,
.opf-field-error .opf-select:focus,
.opf-field-error .opf-textarea:focus {
  border-color: #e11d48;
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.10);
}

.opf-field-error .opf-radio-group {
  border-radius: 8px;
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.10);
}

/* ── Error banner ────────────────────────────────────────────────────────── */
.opf-error-banner {
  display: none;
  background: #fff1f2;
  border: 1.5px solid #fecdd3;
  border-radius: 8px;
  padding: 10px 14px;
}

.opf-error-banner.is-visible {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opf-error-banner::before {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Ccircle cx='8' cy='8' r='7' stroke='%23f43f5e' stroke-width='1.5'/%3E%3Cpath d='M8 5v3.5M8 11h.01' stroke='%23f43f5e' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

.opf-error-message {
  color: #e11d48;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--sma-font-family, inherit);
}

/* ── Actions ─────────────────────────────────────────────────────────────── */
.opf-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Cancel — ghost style */
.opf-actions .opd-button {
  padding: 9px 20px;
  font-size: 13.5px;
  border-radius: 8px;
  height: auto;
  line-height: 1.4;
}

/* Primary submit button */
.opd-button-primary {
  background: var(--sma-primary, #0052CC) !important;
  color: #fff !important;
  border-color: var(--sma-primary, #0052CC) !important;
}

.opd-button-primary:hover:not(:disabled) {
  background: #003fa3 !important;
  border-color: #003fa3 !important;
}

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

/* Loading state */
.opf-btn-loading { display: none; }
#opf-submit.is-loading .opf-btn-label  { display: none; }
#opf-submit.is-loading .opf-btn-loading { display: inline; }

/* Post-submit state. The footer stays visible over the success panel, so the
   primary button has to stop reading as "submit this again" — it starts a fresh
   opportunity instead, and Cancel becomes Close. */
.opf-btn-label-done { display: none; }
.opf-drawer.is-success .opf-btn-label      { display: none; }
.opf-drawer.is-success .opf-btn-label-done { display: inline; }

/* ── Body scroll lock ────────────────────────────────────────────────────── */
.opf-body-locked {
  overflow: hidden;
}
