/**
 * RMRR Forms - UI Components
 * Reusable component styles
 */

/* ============================================
   BUTTONS
   ============================================ */

/* Base button styles */
button,
.btn {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  padding: var(--space-md) var(--space-xl);
  min-height: var(--touch-target-min);
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  text-decoration: none;
  white-space: nowrap;

  /* Improve tap target on mobile */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Shared Thumbnail Remove Button (red circular X) */
.photo-remove,
.thumbnail-remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;

  /* force fixed shape */
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  max-width: 28px;
  max-height: 28px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  border-radius: 50%;

  font-size: 22px;
  font-weight: bold;
  line-height: 0;
  padding: 0;

  /* prevent parent scaling from distorting circle */
  box-sizing: content-box;
  transform: none !important;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button variants */

/* Blue - Navigation/UI actions (changing pages, adding rows) */
.btn-primary,
button:not([class*="btn-"]):not(.modal-close-btn):not(.photo-remove):not(
    .nav-tab
  ):not(.category-header):not(.stepper-btn):not(.segment) {
  background: var(--color-btn-primary);
  color: var(--color-text-inverse);
}

.btn-primary:hover,
button:not([class*="btn-"]):not(.nav-tab):not(.category-header):not(
    .stepper-btn
  ):not(.segment):hover {
  background: var(--color-btn-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active,
button:not([class*="btn-"]):not(.nav-tab):not(.category-header):not(
    .stepper-btn
  ):not(.segment):active {
  background: var(--color-btn-primary-active);
  transform: translateY(0);
}

/* Gray - Secondary actions (cancel, back) */
.btn-secondary {
  background: var(--color-btn-secondary);
  color: var(--color-text-inverse);
}

.btn-secondary:hover {
  background: var(--color-btn-secondary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary:active {
  background: var(--color-btn-secondary-active);
  transform: translateY(0);
}

/* Green - Data processing (submit, done scanning, update) */
.btn-success {
  background: var(--color-btn-success);
  color: var(--color-text-inverse);
}

.btn-success:hover {
  background: var(--color-btn-success-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-success:active {
  background: var(--color-btn-success-active);
  transform: translateY(0);
}

/* Red - Destructive actions (delete, clear) */
.btn-danger {
  background: var(--color-btn-danger);
  color: var(--color-text-inverse);
}

.btn-danger:hover {
  background: var(--color-btn-danger-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-danger:active {
  background: var(--color-btn-danger-active);
  transform: translateY(0);
}

/* Button sizes */
.btn-sm {
  font-size: var(--font-size-sm);
  padding: var(--space-sm) var(--space-md);
  min-height: 36px;
}

.btn-lg {
  font-size: var(--font-size-lg);
  padding: var(--space-lg) var(--space-2xl);
  min-height: 52px;
}

/* Full width button */
.btn-block {
  width: 100%;
  display: flex;
}

/* Inline button (for use inside text/status areas) */
.btn-inline {
  margin-left: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  min-height: auto;
}

/* ============================================
   FORMS
   ============================================ */

/* Form groups */
.form-group {
  margin-bottom: var(--space-xl);
}

.form-row {
  display: grid;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

/* Labels */
label {
  display: block;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

/* Input fields */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  min-height: var(--touch-target-min);
  padding: var(--space-md);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background: var(--color-bg-container);
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-base),
    box-shadow var(--transition-base);

  /* Mobile optimizations */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Focus states */
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-btn-primary);
  box-shadow: 0 0 0 3px rgba(33, 148, 221, 0.15);
}

html.dark-mode input:focus,
html.dark-mode textarea:focus,
html.dark-mode select:focus {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

/* Disabled state */
input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--color-bg-elevated);
}

/* Placeholder text */
::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

/* Select dropdown arrow */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M10.293 3.293L6 7.586 1.707 3.293A1 1 0 00.293 4.707l5 5a1 1 0 001.414 0l5-5a1 1 0 10-1.414-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  padding-right: var(--space-3xl);
  cursor: pointer;
}

/* Textarea specific */
textarea {
  min-height: 100px;
  resize: vertical;
}

/* ============================================
   VALIDATION STATES
   ============================================ */

/* Error state */
.form-group.has-error input,
.form-group.has-error textarea,
.form-group.has-error select,
input.error,
textarea.error,
select.error {
  border-color: var(--color-error);
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.15);
}

/* Duplicate facility warning state (amber/gold) */
input.duplicate {
  border-color: #f59e0b;
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.error-message,
.validation-error {
  display: block;
  color: var(--color-error);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
  line-height: var(--line-height-normal);
}

/* Error alert box */
.error-alert {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  color: var(--color-error);
  font-size: var(--font-size-sm);
  display: none;
}

.error-alert.show {
  display: block;
}

/* Success state */
.form-group.has-success input,
.form-group.has-success textarea,
.form-group.has-success select {
  border-color: var(--color-success);
}

.success-message {
  display: block;
  color: var(--color-success);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
}

/* Warning state */
.warning-message {
  display: block;
  color: var(--color-warning);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
}

/* ============================================
   COLLAPSIBLE SECTIONS
   ============================================ */
.collapsible-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  min-height: var(--touch-target-min);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.collapsible-toggle:hover {
  background: var(--color-bg-page);
  box-shadow: var(--shadow-sm);
}

.collapsible-toggle:active {
  transform: scale(0.98);
}

.collapsible-toggle .toggle-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-base);
}

.collapsible-toggle .toggle-icon::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--color-text-primary);
  transition: transform var(--transition-base);
}

.collapsible-toggle .toggle-icon.open::after {
  transform: rotate(180deg);
}

.collapsible-toggle + .collapsible-content {
  overflow: hidden;
  transition: max-height var(--transition-slow);
  padding: var(--space-lg);
  border: 1px solid var(--color-border-light);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.collapsible-toggle + .collapsible-content.hidden {
  display: none;
}

/* ============================================
   TOGGLE SWITCHES
   ============================================ */
.toggle-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) 0;
  gap: var(--space-lg);
}

.toggle-info {
  flex: 1;
}

.toggle-label {
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  font-size: var(--font-size-base);
  margin-bottom: var(--space-xs);
}

.toggle-description {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.toggle-switch-container {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch-container input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-switch {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-border-medium);
  transition: var(--transition-base);
  border-radius: var(--radius-full);
}

.toggle-switch:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 2px;
  bottom: 2px;
  background-color: var(--color-bg-container);
  transition: var(--transition-base);
  border-radius: 50%;
}

input:checked + .toggle-switch {
  background-color: var(--color-btn-primary);
}

input:checked + .toggle-switch:before {
  transform: translateX(24px);
}

input:focus + .toggle-switch {
  box-shadow: 0 0 0 3px rgba(33, 148, 221, 0.2);
}

/* Dark mode toggle specifically */
.dark-mode-toggle {
  position: fixed;
  top: var(--space-xl);
  right: var(--space-xl);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  cursor: pointer;
  user-select: none;
  z-index: var(--z-sticky);
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   LISTS & LINKS
   ============================================ */
.forms-list,
.menu-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.forms-list li {
  margin-bottom: var(--space-lg);
}

.forms-list a {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg) var(--space-xl);
  background: var(--color-btn-primary);
  color: var(--color-text-inverse);
  text-decoration: none;
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-md);
  min-height: 52px;
}

.forms-list a:hover {
  background: var(--color-btn-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.forms-list a:active {
  background: var(--color-btn-primary-active);
  transform: translateY(0);
}

/* ============================================
   LOADING STATES
   ============================================ */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text::after {
  content: "";
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%,
  20% {
    content: "";
  }
  40% {
    content: ".";
  }
  60% {
    content: "..";
  }
  80%,
  100% {
    content: "...";
  }
}

/* ============================================
   CARDS & CONTAINERS
   ============================================ */
.card {
  background: var(--color-bg-container);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
}

.card-elevated {
  box-shadow: var(--shadow-lg);
}

.card:hover {
  box-shadow: var(--shadow-xl);
  transform: translateY(-2px);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Spacing utilities */
.mt-sm {
  margin-top: var(--space-sm);
}
.mt-md {
  margin-top: var(--space-md);
}
.mt-lg {
  margin-top: var(--space-lg);
}
.mt-xl {
  margin-top: var(--space-xl);
}

.mb-sm {
  margin-bottom: var(--space-sm);
}
.mb-md {
  margin-bottom: var(--space-md);
}
.mb-lg {
  margin-bottom: var(--space-lg);
}
.mb-xl {
  margin-bottom: var(--space-xl);
}

.p-sm {
  padding: var(--space-sm);
}
.p-md {
  padding: var(--space-md);
}
.p-lg {
  padding: var(--space-lg);
}
.p-xl {
  padding: var(--space-xl);
}

/* Text utilities */
.text-center {
  text-align: center;
}
.text-left {
  text-align: left;
}
.text-right {
  text-align: right;
}

.text-muted {
  color: var(--color-text-muted);
}
.text-primary {
  color: var(--color-btn-primary);
}
.text-danger {
  color: var(--color-error);
}
.text-success {
  color: var(--color-success);
}

/* Display utilities */
.hidden {
  display: none !important;
}
.block {
  display: block;
}
.flex {
  display: flex;
}
.inline-flex {
  display: inline-flex;
}

/* Gap utilities */
.gap-sm {
  gap: var(--space-sm);
}
.gap-md {
  gap: var(--space-md);
}
.gap-lg {
  gap: var(--space-lg);
}

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */
@media (max-width: 360px) {
  .btn {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
  }
}

@media (min-width: 768px) {
  .form-row-desktop {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   SEARCH CLEAR ICON
   ============================================ */
.search-clear-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: #6b7280;
  cursor: pointer;
  display: none;
}

/* ============================================
   INSET GROUPS (iOS Settings Style)
   ============================================ */
.inset-group {
  background: var(--color-bg-container);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-xl);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

html.dark-mode .inset-group {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.inset-group-header {
  padding: var(--space-lg) var(--space-lg) var(--space-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: transparent;
}

.inset-group-content {
  padding: 0 var(--space-lg) var(--space-lg);
}

/* For groups that need full-bleed content (like lists with dividers) */
.inset-group-content.flush {
  padding: 0;
}

/* Inset group list items with dividers */
.inset-group-item {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.inset-group-item:last-child {
  border-bottom: none;
}

/* Standalone inset card (for single items like headers) */
.inset-card {
  background: var(--color-bg-container);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-lg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

html.dark-mode .inset-card {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ============================================
   DASHBOARD LANDING PAGE STYLES
   ============================================ */

/* Hero Section with Logo - Card background in both modes */
.dashboard-hero {
  text-align: center;
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
  background: var(--color-bg-container);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--color-border-light);
}

.dashboard-hero img {
  max-width: 260px;
  height: auto;
  margin-bottom: var(--space-sm);
}

.dashboard-hero .tagline {
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.5px;
}

/* Dashboard Grid - 2 column layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  padding: 0;
  margin-bottom: var(--space-2xl);
}

/* Dashboard Cards */
.dashboard-card {
  background: var(--color-bg-container);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl) var(--space-lg);
  text-decoration: none;
  color: var(--color-text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
  border: 1px solid transparent;
  min-height: 140px;
}

.dashboard-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  border-color: var(--color-border-light);
}

.dashboard-card:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Card Icons */
.dashboard-card .icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: rgba(33, 148, 221, 0.1);
  color: var(--color-btn-primary);
  transition: all 0.2s ease;
}

.dashboard-card:hover .icon {
  background: var(--color-btn-primary);
  color: white;
  transform: scale(1.05);
}

.dashboard-card .icon svg {
  width: 24px;
  height: 24px;
}

/* Card Labels */
.dashboard-card .label {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  text-align: center;
  line-height: 1.3;
}

/* Dark Mode Adjustments */
html.dark-mode .dashboard-hero {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  border-color: var(--color-border-medium);
}

html.dark-mode .dashboard-card {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

html.dark-mode .dashboard-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  border-color: var(--color-border-medium);
}

html.dark-mode .dashboard-card .icon {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
}

html.dark-mode .dashboard-card:hover .icon {
  background: #60a5fa;
  color: #1a1a1a;
}

/* Responsive: Single column on very small screens */
@media (max-width: 360px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}
