/* ==========================================================================
   card-modal.css  —  UX-02 · Card modal tab layout
   All var(--…) names must be defined in styles.css :root (guard enforced).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Modal overlay: full-screen on phones (<768px)
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  #cardModal.modal {
    align-items: flex-end;
  }
  #cardModal .modal-content.card-editor {
    max-width: 100%;
    width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
  }
}

/* --------------------------------------------------------------------------
   Card modal shell: flex column so the sticky footer stays at the bottom
   -------------------------------------------------------------------------- */
.modal-content.card-editor {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden; /* children scroll independently */
}

/* Header never scrolls */
.card-editor .modal-header {
  flex-shrink: 0;
}

/* Header row: subject + private badge inline */
.card-modal-header-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Tab bar
   -------------------------------------------------------------------------- */
.card-modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-dark);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.card-modal-tabs::-webkit-scrollbar { display: none; }

.card-modal-tab {
  flex: 1 1 0;
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 120ms, border-color 120ms;
  outline-offset: -2px;
  line-height: var(--leading-tight);
  text-align: center;
}
.card-modal-tab:hover {
  color: var(--text-primary);
  background: var(--bg-light);
}
.card-modal-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.card-modal-tab i {
  margin-right: var(--space-1);
}

/* Mobile: tabs as a segmented control (44px touch targets) */
@media (max-width: 767px) {
  .card-modal-tabs {
    gap: var(--space-1);
    padding: var(--space-2) var(--space-2) 0;
    background: var(--bg-card);
    border-bottom: none;
  }
  .card-modal-tab {
    flex: 1 1 0;
    min-height: 44px;
    padding: var(--space-2) var(--space-2);
    border: 1px solid var(--border-color);
    border-bottom: 2px solid transparent;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    font-size: var(--text-xs);
  }
  .card-modal-tab.active {
    background: var(--bg-dark);
    border-color: var(--primary);
    border-bottom-color: var(--bg-dark);
    color: var(--primary);
  }
}

/* --------------------------------------------------------------------------
   Tab pane container — scrollable area between tab bar and sticky footer
   -------------------------------------------------------------------------- */
.card-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

.card-tab-pane {
  display: none;
  padding: var(--space-4) var(--space-5);
}
.card-tab-pane.active {
  display: block;
}

/* --------------------------------------------------------------------------
   Sticky footer — always visible, never scrolls away
   -------------------------------------------------------------------------- */
.card-modal-footer {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
  /* Safe-area inset for phones with home indicator */
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 767px) {
  .card-modal-footer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
  /* Make footer buttons fill on very small screens */
  .card-modal-footer .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }
}

/* --------------------------------------------------------------------------
   Within Mail tab: sender info row above the thread/content area
   -------------------------------------------------------------------------- */
.card-mail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.card-mail-meta strong {
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Within Work tab: form layout preserved from original modal-body
   -------------------------------------------------------------------------- */
.card-tab-pane .form-row {
  margin-bottom: var(--space-3);
}

/* --------------------------------------------------------------------------
   Within AI tab: stack panels with a small gap
   -------------------------------------------------------------------------- */
.card-tab-pane .ai-panel + .ai-panel {
  margin-top: var(--space-4);
}

/* --------------------------------------------------------------------------
   Viewing-users row (stays in Work tab footer area)
   -------------------------------------------------------------------------- */
.card-viewers-row {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Task list panel — in the new flex layout it sits between body and footer.
   Give it a max-height and internal scroll so the footer stays visible.
   -------------------------------------------------------------------------- */
.modal-content.card-editor .task-list-panel {
  flex-shrink: 0;
  max-height: 280px;
  border-left: none;
  border-right: none;
  border-radius: 0;
  border-top: 1px solid var(--border-color);
  border-bottom: none;
}
