/**
 * Component System CSS
 * Styles for reusable components created via utils/components.js
 */

/* ============================================================================
   FORM GROUPS
   ============================================================================ */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-primary);
}

.form-group .required {
  color: var(--danger-color, #ef4444);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.checkbox-group label {
  margin: 0;
  cursor: pointer;
  user-select: none;
}

/* ============================================================================
   SPINNER / LOADING
   ============================================================================ */

.spinner-container {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.spinner {
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-small {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner-medium {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

.spinner-large {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

.spinner-text {
  color: var(--text-secondary);
  font-size: 14px;
}

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

/* Loading state for buttons */
.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0.6;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  font-size: 14px;
  line-height: 1.5;
  pointer-events: auto;
  animation: toastSlideIn 0.3s ease;
}

.toast .close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.toast .close-btn:hover {
  background: var(--bg-tertiary);
}

/* Toast types */
.toast-info {
  border-left: 4px solid var(--primary-color);
  color: var(--text-primary);
}

.toast-success {
  border-left: 4px solid #10b981;
  color: var(--text-primary);
}

.toast-warning {
  border-left: 4px solid #f59e0b;
  color: var(--text-primary);
}

.toast-error {
  border-left: 4px solid #ef4444;
  color: var(--text-primary);
}

@keyframes toastSlideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ============================================================================
   SECTION HEADER
   ============================================================================ */

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================================
   MODAL DIALOGS
   ============================================================================ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 12px;
  width: 90%;
  max-width: 450px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

.modal-header h2 {
  font-size: 18px;
  margin: 0;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  color: var(--text-primary);
}

.modal-body p {
  margin: 0;
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

.modal-footer .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}

.close-btn {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.close-btn:hover {
  background: var(--bg-tertiary);
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ---- Action menu (utils/components.js openActionMenu) ---- */

.sd-menu {
  position: fixed;
  z-index: 1300; /* above modals (1000-range) */
  min-width: 230px;
  padding: 6px;
  background: var(--sd-bg, var(--bg-primary, #fff));
  border: 1px solid var(--sd-line, var(--border-color, #ddd));
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sd-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sd-fg, var(--text-primary, #111));
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sd-menu-item:hover,
.sd-menu-item:focus-visible {
  background: var(--sd-well, var(--bg-secondary, #f2f2f2));
  outline: none;
}

.sd-menu-item-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sd-menu-item-label {
  font-size: 14px;
  font-weight: 600;
}

.sd-menu-item-hint {
  font-size: 12px;
  color: var(--sd-fg-muted, var(--text-secondary, #777));
}

.sd-menu-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--sd-accent, var(--primary-color, #111));
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ---- Post-signing sentiment prompt (utils/review-prompt.js) ---- */

/* These dialogs appear unprompted, so they must read at a glance:
   larger title, larger body copy, roomier layout than a regular modal. */
.sd-prompt-modal .modal-content {
  max-width: 460px;
}

.sd-prompt-modal .modal-header h2 {
  font-size: 23px;
}

.sd-prompt-modal .modal-body {
  padding-top: 20px;
  padding-bottom: 20px;
}

.sd-prompt-modal .modal-body p {
  font-size: 16.5px;
  line-height: 1.55;
}

.sd-prompt-modal .btn {
  font-size: 15px;
  padding: 11px 20px;
}

.sd-sentiment {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sd-sentiment-question {
  margin: 0;
  color: var(--sd-fg);
}

.sd-sentiment-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.sd-sentiment-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  background: var(--sd-well);
  border: 1px solid var(--sd-line);
  border-radius: var(--sd-radius-card);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.sd-sentiment-btn:hover,
.sd-sentiment-btn:focus-visible {
  background: var(--sd-well-hover);
  transform: translateY(-2px);
}

.sd-sentiment-emoji {
  font-size: 38px;
  line-height: 1;
}

.sd-sentiment-label {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--sd-fg);
}

.sd-feedback-text,
.sd-feedback-email {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--sd-line);
  border-radius: var(--sd-radius-card);
  background: var(--sd-bg);
  color: var(--sd-fg);
  font: inherit;
  resize: vertical;
}

.sd-feedback-text:focus,
.sd-feedback-email:focus {
  outline: 2px solid var(--sd-accent);
  outline-offset: 1px;
}

.sd-feedback-review-link {
  font-size: 13px;
  color: var(--sd-fg-soft);
  text-decoration: underline;
  align-self: flex-start;
}

/* ============================================================================
   FORM-FILL DIALOG (signing/form-filler.js)
   ========================================================================= */

/* A document can carry dozens of fields; the list scrolls, the footer does not. */
.form-fill-fields {
  max-height: 60vh;
  overflow-y: auto;
}

.form-fill-intro {
  margin: 0 0 16px;
  color: var(--text-secondary);
}

/* Multi-select option lists render as a checkbox per option. */
.form-fill-fields fieldset.form-group {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 16px;
}

.form-fill-fields legend {
  padding: 0 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
