/* ============================================
   MOBILE TABLES & FORMS OPTIMIZATION
   Responsive table and form styling for all devices
   ============================================ */

/* ============================================
   TABLE RESPONSIVE STYLES
   ============================================ */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

.table-responsive table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

/* Mobile-first: Stack table cells */
@media (max-width: 767px) {
  .table-responsive,
  .table-responsive > table {
    display: block;
    width: 100%;
  }

  .table-responsive table thead {
    display: none;
  }

  .table-responsive table tbody,
  .table-responsive table tr,
  .table-responsive table td {
    display: block;
    width: 100%;
  }

  .table-responsive table tr {
    margin-bottom: 1.5rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 10px;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(26, 31, 46, 0.9) 0%, rgba(33, 40, 53, 0.4) 100%);
  }

  .table-responsive table td {
    padding: 0.75rem 0;
    text-align: right;
    padding-right: 50%;
    position: relative;
  }

  .table-responsive table td:before {
    content: attr(data-label);
    position: absolute;
    left: 1rem;
    text-align: left;
    font-weight: 700;
    color: var(--accent-cyan);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .table-responsive table td[data-label=""]:before {
    content: "";
  }
}

/* Tablet and up: Show normal table */
@media (min-width: 768px) {
  .table-responsive {
    overflow-x: visible;
  }

  .table-responsive table thead {
    display: table-header-group;
  }

  .table-responsive table tbody,
  .table-responsive table tr {
    display: table-row-group;
  }

  .table-responsive table tr {
    margin-bottom: 0;
    border: none;
    background: none;
    padding: 0;
  }

  .table-responsive table td {
    display: table-cell;
    text-align: left;
    padding-right: auto;
  }

  .table-responsive table td:before {
    display: none;
  }
}

/* ============================================
   FORM STYLES - MOBILE OPTIMIZED
   ============================================ */

.form-wrapper {
  width: 100%;
  max-width: 100%;
}

.form-group {
  margin-bottom: 1.5rem;
  width: 100%;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #d1d5db;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
textarea,
select {
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 1rem;
  font-size: 16px; /* Prevent iOS zoom */
  font-family: inherit;
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.8);
  color: #e5e7eb;
  transition: all 0.3s ease;
  -webkit-appearance: none; /* Remove iOS styling */
  appearance: none;
  box-sizing: border-box;
}

/* Remove input type spinner buttons on number inputs */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/* Select dropdown styling */
select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='2'%3e%3cpath d='M6 9l6 6 6-6'%3e%3c/path%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1.5rem;
  padding-right: 2.5rem;
}

/* Focus styles for form inputs */
.form-control:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), inset 0 0 0 1px rgba(59, 130, 246, 0.2);
  background: rgba(15, 23, 42, 0.95);
  transform: translateY(-1px);
}

/* Hover state */
.form-control:hover,
input:hover,
textarea:hover,
select:hover {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(15, 23, 42, 0.9);
}

/* Disabled state */
.form-control:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  background: rgba(15, 23, 42, 0.5);
  border-color: rgba(59, 130, 246, 0.1);
  color: #64748b;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Placeholder styling */
.form-control::placeholder,
input::placeholder,
textarea::placeholder {
  color: #6b7280;
  font-weight: 400;
}

/* Textarea specific */
textarea {
  min-height: 120px;
  resize: vertical;
  max-height: 300px;
  font-family: 'Inter', monospace, sans-serif;
}

/* ============================================
   FORM LAYOUT - GRID & FLEX
   ============================================ */

.form-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.form-row.row-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

/* Two column layout on tablet and up */
@media (min-width: 480px) {
  .form-row.row-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Three column layout on desktop */
@media (min-width: 768px) {
  .form-row.row-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .form-row.row-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   BUTTONS - FORM SUBMISSION
   ============================================ */

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 2rem;
  width: 100%;
}

.btn-group.horizontal {
  flex-direction: row;
  flex-wrap: wrap;
}

@media (min-width: 480px) {
  .btn-group {
    flex-direction: row;
  }

  .btn-group .btn {
    flex: 1;
    min-width: 120px;
  }
}

/* Button states */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn:disabled:active {
  transform: none !important;
}

/* ============================================
   FORM VALIDATION STYLES
   ============================================ */

.form-group.has-error .form-control,
.form-group.has-error input,
.form-group.has-error textarea,
.form-group.has-error select {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

.form-group.has-error .form-control:focus,
.form-group.has-error input:focus {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1), inset 0 0 0 1px rgba(239, 68, 68, 0.2);
}

.form-group.has-success .form-control,
.form-group.has-success input,
.form-group.has-success textarea,
.form-group.has-success select {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.08);
}

.form-group.has-success .form-control:focus,
.form-group.has-success input:focus {
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1), inset 0 0 0 1px rgba(34, 197, 94, 0.2);
}

/* Validation messages */
.form-error,
.error-message,
.invalid-feedback {
  display: block;
  font-size: 0.75rem;
  color: #ef4444;
  margin-top: 0.25rem;
  font-weight: 500;
  animation: shake 0.3s ease;
}

.form-success,
.success-message,
.valid-feedback {
  display: block;
  font-size: 0.75rem;
  color: #22c55e;
  margin-top: 0.25rem;
  font-weight: 500;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ============================================
   CHECKBOXES & RADIO BUTTONS
   ============================================ */

input[type="checkbox"],
input[type="radio"] {
  min-width: 44px;
  min-height: 44px;
  accent-color: #3b82f6;
  cursor: pointer;
  margin-right: 0.75rem;
}

.checkbox-group,
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checkbox-item,
.radio-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  transition: all 0.3s ease;
  cursor: pointer;
  user-select: none;
}

.checkbox-item:hover,
.radio-item:hover {
  background: rgba(59, 130, 246, 0.08);
}

.checkbox-item input[type="checkbox"],
.checkbox-item input[type="radio"],
.radio-item input[type="checkbox"],
.radio-item input[type="radio"] {
  margin: 0;
}

.checkbox-item label,
.radio-item label {
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}

/* ============================================
   INPUT GROUPS
   ============================================ */

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.input-group-prepend,
.input-group-append {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: #94a3b8;
  font-size: 0.875rem;
  border-radius: 10px;
}

.input-group-text {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

/* ============================================
   HELP TEXT & DESCRIPTIONS
   ============================================ */

.form-text,
.help-text,
.description {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 0.25rem;
  font-weight: 400;
}

/* ============================================
   MODAL FORMS
   ============================================ */

.modal-form {
  padding: 1.5rem;
  max-width: 100%;
  width: 100%;
}

@media (min-width: 480px) {
  .modal-form {
    padding: 2rem;
  }
}

.modal-form .form-group:last-child {
  margin-bottom: 0;
}

/* ============================================
   MOBILE-FIRST SPACING
   ============================================ */

.form-spacer {
  height: 1rem;
  display: block;
}

.form-divider {
  border: none;
  border-top: 1px solid rgba(59, 130, 246, 0.2);
  margin: 1.5rem 0;
}

/* ============================================
   LOADING STATE
   ============================================ */

.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 1rem;
  height: 1rem;
  top: 50%;
  left: 50%;
  margin-left: -0.5rem;
  margin-top: -0.5rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   RESPONSIVE MEDIA QUERIES OVERRIDES
   ============================================ */

@media (min-width: 768px) {
  .form-group {
    margin-bottom: 1.75rem;
  }

  .form-label {
    font-size: 0.875rem;
  }

  .form-control,
  input,
  textarea,
  select {
    min-height: 44px;
    font-size: 1rem;
  }

  .btn-group {
    margin-top: 2.5rem;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .form-group {
    page-break-inside: avoid;
  }

  .btn,
  .btn-group {
    display: none;
  }

  .form-control,
  input,
  textarea,
  select {
    border: 1px solid #000;
    background: white;
    color: black;
  }
}
