/* ===== SHARED MODAL COMPONENT =====
   Reusable modal styles for the entire application.
   Uses theme tokens from theme.css for light/dark mode compatibility.

   Usage:
     <div class="app-modal app-modal--hidden" role="dialog" aria-modal="true">
       <div class="app-modal__backdrop"></div>
       <div class="app-modal__container">
         <header class="app-modal__header">
           <h2 class="app-modal__title">Title</h2>
           <button class="app-modal__close"><i class="fas fa-times"></i></button>
         </header>
         <div class="app-modal__body"> ... </div>
         <footer class="app-modal__footer"> ... </footer>
       </div>
     </div>

   JS toggle: add/remove .app-modal--hidden
*/

/* ===== MODAL OVERLAY ===== */
.app-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  box-sizing: border-box;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.app-modal--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ===== BACKDROP ===== */
.app-modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-overlay, rgba(0, 0, 0, 0.5));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* ===== CONTAINER ===== */
.app-modal__container {
  position: relative;
  z-index: var(--z-modal);
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  background: var(--modal-bg, var(--surface));
  border: 1px solid var(--modal-border, var(--border));
  border-radius: 0.75rem;
  box-shadow: var(--modal-shadow, 0 25px 50px -12px rgba(0, 0, 0, 0.25));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.96) translateY(8px);
  transition: transform 0.2s ease;
}

.app-modal:not(.app-modal--hidden) .app-modal__container {
  transform: scale(1) translateY(0);
}

/* ===== HEADER ===== */
.app-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.app-modal__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-strong);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-modal__title i {
  color: var(--primary);
  font-size: 1.125rem;
}

.app-modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.app-modal__close:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-2);
}

/* ===== BODY ===== */
.app-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 1.5rem;
  overflow-y: auto;
  color: var(--text);
}

/* ===== FOOTER ===== */
.app-modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

/* ===== FORM STYLES (for modals with forms) ===== */
.app-modal-form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.app-modal-form__section {
  background: var(--surface-2);
  border-radius: 0.5rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
}

.app-modal-form__section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-modal-form__section-title i {
  color: var(--primary);
  font-size: 0.875rem;
}

.app-modal-form__group {
  margin-bottom: 1rem;
}

.app-modal-form__group:last-child {
  margin-bottom: 0;
}

.app-modal-form__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.app-modal-form__input,
.app-modal-form__select,
.app-modal-form__textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--input-border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--input-text);
  line-height: 1.5;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-modal-form__input:focus,
.app-modal-form__select:focus,
.app-modal-form__textarea:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--input-ring);
}

.app-modal-form__input::placeholder,
.app-modal-form__textarea::placeholder {
  color: var(--input-placeholder);
}

.app-modal-form__select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.625rem center;
  background-repeat: no-repeat;
  background-size: 1rem;
  padding-right: 2.25rem;
}

.app-modal-form__textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.app-modal-form__help {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Checkbox */
.app-modal-form__checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.app-modal-form__checkbox {
  display: none;
}

.app-modal-form__checkbox-visual {
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid var(--border-2);
  border-radius: 0.25rem;
  background: var(--input-bg);
  position: relative;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.app-modal-form__checkbox:checked + .app-modal-form__checkbox-visual {
  background: var(--primary);
  border-color: var(--primary);
}

.app-modal-form__checkbox:checked + .app-modal-form__checkbox-visual::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 4px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Time fields grid */
.app-modal-form__time-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Conditional field containers */
.app-modal-form__conditional--hidden {
  display: none;
}

/* Actions row inside body */
.app-modal-form__actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1.25rem;
}

/* Info badge */
.app-modal-form__info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: var(--surface-3);
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.app-modal-form__info i {
  color: var(--primary);
  flex-shrink: 0;
}

/* Importance slider */
.app-modal-form__slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-4, var(--border));
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  margin: 0.5rem 0;
}

.app-modal-form__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.app-modal-form__slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.app-modal-form__slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.app-modal-form__slider-value {
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
  margin-top: 0.25rem;
}

/* ===== BUTTONS ===== */
.app-modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1.125rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  line-height: 1.5;
}

.app-modal-btn--primary {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

.app-modal-btn--primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.app-modal-btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.app-modal-btn--secondary:hover {
  background: var(--surface-3);
  border-color: var(--border-2);
}

.app-modal-btn--danger {
  background: var(--danger);
  color: var(--text-inverse);
  border-color: var(--danger);
}

.app-modal-btn--danger:hover {
  background: var(--danger-strong);
  border-color: var(--danger-strong);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .app-modal {
    padding: 0.75rem;
  }

  .app-modal__container {
    max-height: 95vh;
  }

  .app-modal__header,
  .app-modal__body,
  .app-modal__footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .app-modal-form__grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .app-modal-form__time-row {
    grid-template-columns: 1fr;
  }

  .app-modal-form__actions {
    flex-direction: column;
  }

  .app-modal-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .app-modal,
  .app-modal__container {
    transition: none;
  }
}
