/**
 * ============================================
 * BRAINDUMP V3 - MODAL DESIGN SYSTEM
 * ============================================
 *
 * @version 1.1.0
 * @date 2026-01-07
 *
 * Based on mockups: docs/20260106_V3/modals/
 *
 * Modal Types:
 * - Record Note (Voice) - coral header
 * - Add Link - teal header
 * - Upload Document - teal header
 * - Save Changes - teal header
 * - Delete Document - warning/yellow header
 * - Analyzing Document - teal header with progress
 * ============================================
 */

/* ============================================
   BASE MODAL STYLES
   ============================================ */

.v3-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.v3-modal.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.v3-modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

.v3-modal__container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: v3-modal-enter 0.2s ease-out;
}

@keyframes v3-modal-enter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ============================================
   MODAL HEADER
   ============================================ */

.v3-modal__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  color: white;
}

/* Header color variants */
.v3-modal__header--teal {
  background: #0F8C8D;
}

.v3-modal__header--coral {
  background: #E85A5A;
}

.v3-modal__header--warning {
  background: #F59E0B;
}

.v3-modal__header--success {
  background: #10B981;
}

.v3-modal__header-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.v3-modal__header-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.v3-modal__title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.v3-modal__close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.v3-modal__close:hover {
  opacity: 1;
}

/* ============================================
   MODAL BODY
   ============================================ */

.v3-modal__body {
  padding: 20px;
  background: #ffffff;
  color: #1f2937;
}

/* Dark theme support */
[data-theme="dark"] .v3-modal__container,
body:not([data-theme]) .v3-modal__container {
  background: #1e293b;
}

[data-theme="dark"] .v3-modal__body,
body:not([data-theme]) .v3-modal__body {
  background: #1e293b;
  color: #f1f5f9;
}

/* ============================================
   MODAL FOOTER / ACTIONS
   ============================================ */

.v3-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

[data-theme="dark"] .v3-modal__footer,
body:not([data-theme]) .v3-modal__footer {
  background: #0f172a;
  border-top-color: #334155;
}

/* Button base styles */
.v3-modal__btn {
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 100px;
}

/* Cancel / Secondary button */
.v3-modal__btn--secondary {
  background: transparent;
  border: 1px solid #d1d5db;
  color: #6b7280;
}

.v3-modal__btn--secondary:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

[data-theme="dark"] .v3-modal__btn--secondary,
body:not([data-theme]) .v3-modal__btn--secondary {
  border-color: #475569;
  color: #94a3b8;
}

[data-theme="dark"] .v3-modal__btn--secondary:hover,
body:not([data-theme]) .v3-modal__btn--secondary:hover {
  background: #334155;
  border-color: #64748b;
}

/* Primary button - Teal */
.v3-modal__btn--primary {
  background: #0F8C8D;
  border: 1px solid #0F8C8D;
  color: white;
}

.v3-modal__btn--primary:hover {
  background: #0d7a7b;
  border-color: #0d7a7b;
}

/* Danger button - Red */
.v3-modal__btn--danger {
  background: #E85A5A;
  border: 1px solid #E85A5A;
  color: white;
}

.v3-modal__btn--danger:hover {
  background: #d14949;
  border-color: #d14949;
}

/* Disabled state */
.v3-modal__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Recording state - pulsing red button */
.v3-modal__btn--recording {
  background: #E85A5A !important;
  border-color: #E85A5A !important;
  animation: v3-btn-pulse 1s ease-in-out infinite;
}

.v3-modal__btn--recording:hover {
  background: #d14949 !important;
  border-color: #d14949 !important;
}

@keyframes v3-btn-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(232, 90, 90, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(232, 90, 90, 0);
  }
}

/* ============================================
   INPUT STYLES
   ============================================ */

.v3-modal__input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  background: #ffffff;
  color: #1f2937;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.v3-modal__input:focus {
  outline: none;
  border-color: #0F8C8D;
  box-shadow: 0 0 0 3px rgba(15, 140, 141, 0.1);
}

.v3-modal__input::placeholder {
  color: #9ca3af;
}

[data-theme="dark"] .v3-modal__input,
body:not([data-theme]) .v3-modal__input {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .v3-modal__input::placeholder,
body:not([data-theme]) .v3-modal__input::placeholder {
  color: #64748b;
}

.v3-modal__textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #ffffff;
  color: #1f2937;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.v3-modal__textarea:focus {
  outline: none;
  border-color: #0F8C8D;
  box-shadow: 0 0 0 3px rgba(15, 140, 141, 0.1);
}

[data-theme="dark"] .v3-modal__textarea,
body:not([data-theme]) .v3-modal__textarea {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}

/* ============================================
   LINK MODAL - TAG SUGGESTIONS
   ============================================ */

.v3-modal__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.v3-modal__tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: rgba(15, 140, 141, 0.1);
  border: 1px solid rgba(15, 140, 141, 0.3);
  border-radius: 16px;
  font-size: 12px;
  color: #0F8C8D;
  cursor: pointer;
  transition: all 0.15s;
}

.v3-modal__tag:hover {
  background: rgba(15, 140, 141, 0.2);
  border-color: #0F8C8D;
}

.v3-modal__tag--active {
  background: #0F8C8D;
  color: white;
  border-color: #0F8C8D;
}

[data-theme="dark"] .v3-modal__tag,
body:not([data-theme]) .v3-modal__tag {
  background: rgba(15, 140, 141, 0.15);
  border-color: rgba(15, 140, 141, 0.4);
}

.v3-modal__copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
  margin-top: 12px;
  transition: all 0.15s;
}

.v3-modal__copy-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

[data-theme="dark"] .v3-modal__copy-btn,
body:not([data-theme]) .v3-modal__copy-btn {
  border-color: #475569;
  color: #94a3b8;
}

[data-theme="dark"] .v3-modal__copy-btn:hover,
body:not([data-theme]) .v3-modal__copy-btn:hover {
  background: #334155;
}

/* ============================================
   VOICE MODAL - WAVEFORM
   ============================================ */

.v3-modal__waveform {
  height: 80px;
  background: rgba(15, 140, 141, 0.1);
  border-radius: 8px;
  margin: 16px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.v3-modal__waveform-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 60px;
}

.v3-modal__waveform-bar {
  width: 4px;
  background: #0F8C8D;
  border-radius: 2px;
  animation: v3-waveform-pulse 0.5s ease-in-out infinite alternate;
}

.v3-modal__waveform-bar:nth-child(odd) {
  animation-delay: 0.1s;
}

.v3-modal__waveform-bar:nth-child(even) {
  animation-delay: 0.2s;
}

/* Silent/no signal state - bars turn gray/red */
.v3-modal__waveform-bars--silent .v3-modal__waveform-bar {
  background: #94a3b8;
  transition: background 0.3s;
}

@keyframes v3-waveform-pulse {
  from {
    height: 10px;
  }
  to {
    height: 50px;
  }
}

.v3-modal__timer {
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  color: #0F8C8D;
  font-variant-numeric: tabular-nums;
}

.v3-modal__recording-label {
  text-align: center;
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 8px;
}

[data-theme="dark"] .v3-modal__recording-label,
body:not([data-theme]) .v3-modal__recording-label {
  color: #94a3b8;
}

.v3-modal__recording-label--error {
  color: #E85A5A !important;
}

.v3-modal__recording-label--warning {
  color: #F59E0B !important;
}

/* Microphone hint message */
.v3-modal__mic-hint {
  text-align: center;
  font-size: 12px;
  color: #E85A5A;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(232, 90, 90, 0.1);
  border-radius: 6px;
  display: none;
}

.v3-modal__mic-hint--visible {
  display: block;
}

[data-theme="dark"] .v3-modal__mic-hint,
body:not([data-theme]) .v3-modal__mic-hint {
  background: rgba(232, 90, 90, 0.15);
}

/* ============================================
   UPLOAD MODAL - DROP ZONE
   ============================================ */

.v3-modal__dropzone {
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}

.v3-modal__dropzone:hover,
.v3-modal__dropzone--active {
  border-color: #0F8C8D;
  background: rgba(15, 140, 141, 0.05);
}

.v3-modal__dropzone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: #9ca3af;
}

.v3-modal__dropzone-icon svg {
  width: 100%;
  height: 100%;
}

.v3-modal__dropzone-text {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 4px;
}

.v3-modal__dropzone-hint {
  font-size: 12px;
  color: #9ca3af;
}

[data-theme="dark"] .v3-modal__dropzone,
body:not([data-theme]) .v3-modal__dropzone {
  border-color: #475569;
}

[data-theme="dark"] .v3-modal__dropzone-text,
body:not([data-theme]) .v3-modal__dropzone-text {
  color: #94a3b8;
}

/* File preview in dropzone */
.v3-modal__file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  margin-top: 12px;
}

.v3-modal__file-icon {
  width: 32px;
  height: 32px;
  color: #0F8C8D;
}

.v3-modal__file-info {
  flex: 1;
  text-align: left;
}

.v3-modal__file-name {
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
  margin-bottom: 2px;
}

.v3-modal__file-size {
  font-size: 12px;
  color: #6b7280;
}

.v3-modal__file-remove {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
}

.v3-modal__file-remove:hover {
  color: #E85A5A;
}

[data-theme="dark"] .v3-modal__file-preview,
body:not([data-theme]) .v3-modal__file-preview {
  background: #0f172a;
}

[data-theme="dark"] .v3-modal__file-name,
body:not([data-theme]) .v3-modal__file-name {
  color: #f1f5f9;
}

/* ============================================
   CONFIRMATION MODALS
   ============================================ */

.v3-modal__message {
  font-size: 14px;
  line-height: 1.6;
  color: #4b5563;
  margin-bottom: 16px;
}

[data-theme="dark"] .v3-modal__message,
body:not([data-theme]) .v3-modal__message {
  color: #94a3b8;
}

.v3-modal__warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 8px;
  margin-bottom: 16px;
}

.v3-modal__warning-icon {
  width: 20px;
  height: 20px;
  color: #F59E0B;
  flex-shrink: 0;
}

.v3-modal__warning-text {
  font-size: 13px;
  color: #92400e;
}

[data-theme="dark"] .v3-modal__warning-text,
body:not([data-theme]) .v3-modal__warning-text {
  color: #fbbf24;
}

/* Checkbox for delete confirmation */
.v3-modal__checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: #4b5563;
}

.v3-modal__checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #0F8C8D;
}

[data-theme="dark"] .v3-modal__checkbox,
body:not([data-theme]) .v3-modal__checkbox {
  color: #94a3b8;
}

/* ============================================
   COMPARISON VIEW (Save Changes)
   ============================================ */

.v3-modal__comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.v3-modal__comparison-item {
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.v3-modal__comparison-item--old {
  background: #fef2f2;
  border-color: #fecaca;
}

.v3-modal__comparison-item--new {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

[data-theme="dark"] .v3-modal__comparison-item--old,
body:not([data-theme]) .v3-modal__comparison-item--old {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .v3-modal__comparison-item--new,
body:not([data-theme]) .v3-modal__comparison-item--new {
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.3);
}

.v3-modal__comparison-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #6b7280;
  margin-bottom: 8px;
}

.v3-modal__comparison-content {
  font-size: 14px;
  color: #1f2937;
}

.v3-modal__comparison-item--old .v3-modal__comparison-content {
  text-decoration: line-through;
  color: #dc2626;
}

.v3-modal__comparison-item--new .v3-modal__comparison-content {
  color: #16a34a;
}

[data-theme="dark"] .v3-modal__comparison-content,
body:not([data-theme]) .v3-modal__comparison-content {
  color: #f1f5f9;
}

/* ============================================
   PROGRESS MODAL (Analyzing)
   ============================================ */

.v3-modal__progress {
  margin-bottom: 20px;
}

.v3-modal__progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.v3-modal__progress-fill {
  height: 100%;
  background: #0F8C8D;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.v3-modal__progress-text {
  font-size: 12px;
  color: #6b7280;
  text-align: right;
}

[data-theme="dark"] .v3-modal__progress-bar,
body:not([data-theme]) .v3-modal__progress-bar {
  background: #334155;
}

.v3-modal__steps {
  list-style: none;
  padding: 0;
  margin: 0;
}

.v3-modal__step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: #6b7280;
}

.v3-modal__step-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.v3-modal__step--complete {
  color: #10B981;
}

.v3-modal__step--active {
  color: #0F8C8D;
  font-weight: 500;
}

.v3-modal__step--active .v3-modal__step-icon {
  animation: v3-spin 1s linear infinite;
}

@keyframes v3-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.v3-modal__eta {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 12px;
  text-align: center;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
  .v3-modal__container {
    max-width: 100%;
    margin: 0 8px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .v3-modal__footer {
    flex-direction: column-reverse;
  }

  .v3-modal__btn {
    width: 100%;
  }

  .v3-modal__comparison {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   SEARCH MODAL - Desktop & Mobile
   ============================================ */

.v3-search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.v3-search-modal--open {
  opacity: 1;
  visibility: visible;
}

.v3-search-modal__container {
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  background: var(--v3-bg-app, #0f1419);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(-20px);
  transition: transform 0.2s ease;
}

.v3-search-modal--open .v3-search-modal__container {
  transform: translateY(0);
}

.v3-search-modal__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--v3-bg-secondary, #1a2332);
  border-bottom: 1px solid var(--v3-border, rgba(255,255,255,0.1));
}

.v3-search-modal__back {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--v3-text-primary, #fff);
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s;
}

.v3-search-modal__back:hover {
  background: rgba(255, 255, 255, 0.1);
}

.v3-search-modal__input-wrapper {
  flex: 1;
  position: relative;
}

.v3-search-modal__input {
  width: 100%;
  padding: 10px 16px;
  background: var(--v3-bg-card, #1e2a3a);
  border: 1px solid var(--v3-border, rgba(255,255,255,0.1));
  border-radius: 24px;
  color: var(--v3-text-primary, #fff);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.v3-search-modal__input:focus {
  border-color: var(--v3-accent, #14B8B8);
}

.v3-search-modal__input::placeholder {
  color: var(--v3-text-muted, #666);
}

/* Filter Chips - WhatsApp Style */
.v3-search-modal__filters {
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.v3-search-modal__chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--v3-bg-card, #1e2a3a);
  border: 1px solid var(--v3-border, rgba(255,255,255,0.15));
  border-radius: 20px;
  color: var(--v3-text-secondary, #aaa);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.v3-search-modal__chip:hover {
  background: rgba(20, 184, 184, 0.1);
  border-color: var(--v3-accent, #14B8B8);
}

.v3-search-modal__chip--active {
  background: var(--v3-accent, #14B8B8);
  border-color: var(--v3-accent, #14B8B8);
  color: #0f1419;
}

.v3-search-modal__chip-icon {
  font-size: 16px;
}

/* Search Results */
.v3-search-modal__results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}

.v3-search-modal__empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--v3-text-muted, #666);
}

.v3-search-modal__empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Mobile: Fullscreen search modal */
@media (max-width: 640px) {
  .v3-search-modal {
    padding-top: 0;
    background: var(--v3-bg-app, #0f1419);
  }

  .v3-search-modal__container {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }

  .v3-search-modal__header {
    padding: 12px;
  }

  .v3-search-modal__filters {
    padding: 12px;
  }
}
