/* ============================================================================
   Magic Tilt Team Portal — shared MODAL system (dark, Tailwind-faithful)
   ----------------------------------------------------------------------------
   Two things live here:

   (A) The .tm-* component — a self-contained reproduction of the Tailwind Plus
       "centered modal" (gray-800 panel, icon circle, reversed footer, enter/
       leave animation). Driven by js/team-modal.js (window.TeamModal). NO
       Tailwind runtime or @tailwindplus/elements is required — this is plain
       CSS + a native <dialog> element.

   (B) A LEGACY RE-SKIN — overrides for the portal's pre-existing custom modals
       (.modal*, .csv-modal*, .status-modal*, .pdf-modal*, .audit-modal*) so
       they pick up the same dark gray-800 look with zero per-page CSS edits.
       This file is linked LAST (right after team-theme.css) on every page, so
       these rules win on equal specificity / later source order.

   Palette mirrors the Tailwind tokens from the source snippet:
     gray-800 #1f2937 · gray-900/50 bg · gray-700/25 footer · white/10 ring
     gray-400 #9ca3af body · red-500/400 · blue-500/400 · green · amber
   ============================================================================ */

:root {
    --tm-panel:        #1f2937;  /* gray-800 */
    --tm-panel-2:      #111827;  /* gray-900 — inputs / deeper surface */
    --tm-footer:       rgba(55, 65, 81, .25);   /* gray-700/25 */
    --tm-backdrop:     rgba(17, 24, 39, .5);     /* gray-900/50 */
    --tm-ring:         rgba(255, 255, 255, .10); /* white/10 */
    --tm-ring-soft:    rgba(255, 255, 255, .05); /* white/5 */
    --tm-title:        #ffffff;
    --tm-text:         #9ca3af;  /* gray-400 */
    --tm-text-strong:  #e5e7eb;  /* gray-200 */
    --tm-text-muted:   #6b7280;  /* gray-500 (placeholders) */
    --tm-shadow:       0 20px 25px -5px rgba(0, 0, 0, .5), 0 8px 10px -6px rgba(0, 0, 0, .4);
}

/* ============================================================================
   (A) .tm-* COMPONENT
   ========================================================================== */

dialog.tm-dialog {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    overflow-y: auto;
    color: var(--tm-title);
    font-family: var(--font-body, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
}
dialog.tm-dialog::backdrop { background: transparent; }  /* we animate our own */

.tm-backdrop {
    position: fixed;
    inset: 0;
    background: var(--tm-backdrop);
    opacity: 0;
    transition: opacity .2s ease-in;       /* leave */
}
.tm-dialog[data-state="open"] .tm-backdrop {
    opacity: 1;
    transition: opacity .3s ease-out;      /* enter */
}

.tm-wrap {
    display: flex;
    min-height: 100%;
    align-items: flex-end;
    justify-content: center;
    padding: 1rem;
    text-align: center;
}
@media (min-width: 640px) {
    .tm-wrap { align-items: center; padding: 0; }
}

.tm-panel {
    position: relative;
    overflow: hidden;
    width: 100%;
    border-radius: .5rem;                  /* rounded-lg */
    background: var(--tm-panel);
    color: var(--tm-text-strong);
    text-align: left;
    box-shadow: var(--tm-shadow);
    outline: 1px solid var(--tm-ring);
    outline-offset: -1px;
    opacity: 0;
    transform: translateY(1rem);           /* data-closed: translate-y-4 */
    transition: opacity .2s ease-in, transform .2s ease-in;   /* leave */
}
@media (min-width: 640px) {
    .tm-panel { margin: 2rem 0; max-width: 32rem; transform: scale(.95); }  /* sm:max-w-lg */
}
.tm-dialog[data-state="open"] .tm-panel {
    opacity: 1;
    transform: translateY(0);
    transition: opacity .3s ease-out, transform .3s ease-out;  /* enter */
}
@media (min-width: 640px) {
    .tm-dialog[data-state="open"] .tm-panel { transform: scale(1); }
}

/* --- body --- */
.tm-body {
    background: var(--tm-panel);
    padding: 1.25rem 1rem 1rem;            /* px-4 pt-5 pb-4 */
}
@media (min-width: 640px) {
    .tm-body { padding: 1.5rem 1.5rem 1rem; }  /* sm:p-6 sm:pb-4 */
}
.tm-row { display: block; }
@media (min-width: 640px) {
    .tm-row { display: flex; align-items: flex-start; }
}

/* --- icon circle --- */
.tm-icon {
    margin: 0 auto;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 9999px;
}
@media (min-width: 640px) {
    .tm-icon { margin: 0; width: 2.5rem; height: 2.5rem; }
}
.tm-icon-svg { width: 1.5rem; height: 1.5rem; }

/* --- title + text column --- */
.tm-text-col {
    margin-top: .75rem;
    text-align: center;
}
@media (min-width: 640px) {
    .tm-text-col { margin-top: 0; margin-left: 1rem; text-align: left; }
}
.tm-title {
    margin: 0;
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 600;
    color: var(--tm-title);
}
.tm-body-holder { margin-top: .5rem; }
.tm-text {
    margin: 0;
    font-size: .875rem;
    line-height: 1.35rem;
    color: var(--tm-text);
    white-space: pre-line;                 /* honor \n line breaks from legacy messages */
}
.tm-body-holder .tm-text + .tm-text { margin-top: .5rem; }

/* --- footer --- */
.tm-footer {
    display: flex;
    flex-direction: column-reverse;        /* mobile: primary on top */
    gap: .75rem;
    background: var(--tm-footer);
    padding: .75rem 1rem;
}
@media (min-width: 640px) {
    .tm-footer {
        flex-direction: row;
        justify-content: flex-end;         /* cancel … primary (right) */
        padding: .75rem 1.5rem;
    }
}

/* --- buttons --- */
.tm-btn {
    display: inline-flex;
    width: 100%;
    justify-content: center;
    align-items: center;
    border: 0;
    border-radius: .375rem;
    padding: .5rem .75rem;
    font-size: .875rem;
    font-weight: 600;
    line-height: 1.25rem;
    color: #fff;
    cursor: pointer;
    transition: background-color .12s ease;
}
@media (min-width: 640px) {
    .tm-btn { width: auto; }
}
.tm-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
.tm-btn-cancel {
    background: rgba(255, 255, 255, .10);
    box-shadow: inset 0 0 0 1px var(--tm-ring-soft);
}
.tm-btn-cancel:hover { background: rgba(255, 255, 255, .20); }
.tm-btn-primary { background: #3b82f6; }   /* blue-500 */
.tm-btn-primary:hover { background: #60a5fa; }
.tm-btn-danger  { background: #ef4444; }   /* red-500 */
.tm-btn-danger:hover  { background: #f87171; }
.tm-btn-success { background: #22c55e; }   /* green-500 */
.tm-btn-success:hover { background: #4ade80; }
.tm-btn-warning { background: #f59e0b; color: #1f2937; }  /* amber-500 */
.tm-btn-warning:hover { background: #fbbf24; }

/* --- icon-circle color by variant --- */
.tm-danger  .tm-icon { background: rgba(239, 68, 68, .10);  color: #f87171; }
.tm-primary .tm-icon { background: rgba(59, 130, 246, .10); color: #60a5fa; }
.tm-info    .tm-icon { background: rgba(59, 130, 246, .10); color: #60a5fa; }
.tm-success .tm-icon { background: rgba(34, 197, 94, .10);  color: #4ade80; }
.tm-warning .tm-icon { background: rgba(245, 158, 11, .10); color: #fbbf24; }

/* honor reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .tm-backdrop, .tm-panel,
    .tm-dialog[data-state="open"] .tm-backdrop,
    .tm-dialog[data-state="open"] .tm-panel { transition-duration: .01ms; }
}

/* ============================================================================
   (B) LEGACY MODAL RE-SKIN  (loaded last → wins on equal specificity)
   Darkens the portal's pre-existing custom modals to match the .tm-* look.
   Scoped to known modal class families so page chrome is never affected.
   ========================================================================== */

/* --- backdrops --- */
.modal-overlay,
.csv-modal-overlay,
.status-modal-overlay,
.pdf-modal-overlay,
.audit-modal-overlay {
    background: var(--tm-backdrop) !important;
    backdrop-filter: blur(1px);
}

/* --- panels --- */
.modal,
.modal-content,
.csv-modal,
.status-modal,
.pdf-modal,
.pdf-modal-shell,
.audit-modal {
    background: var(--tm-panel) !important;
    color: var(--tm-text-strong) !important;
    border: 1px solid var(--tm-ring) !important;
    box-shadow: var(--tm-shadow) !important;
}

/* --- headers --- */
.modal-header,
.modal-head,
.csv-modal-header,
.status-modal-header,
.pdf-modal-header,
.audit-modal .modal-header {
    background: transparent !important;
    border-bottom: 1px solid var(--tm-ring) !important;
}
.modal-header h1, .modal-header h2, .modal-header h3,
.modal-head h1, .modal-head h2, .modal-head h3,
.modal-title, .pdf-modal-title,
.csv-modal-header h2, .csv-modal-header h3,
.status-modal-header h2, .status-modal-header h3 {
    color: var(--tm-title) !important;
}
.modal-subtitle { color: var(--tm-text) !important; }

/* --- bodies / generic text --- */
.modal-body, .csv-modal-body, .status-modal-body,
.modal-grid, .modal-content {
    color: var(--tm-text-strong) !important;
}
.modal-body p, .modal-body li, .modal-body dd, .modal-body dt,
.modal-body label, .modal-body span:not([class*="badge"]):not([class*="pill"]):not([class*="chip"]):not([class*="tag"]),
.csv-modal-body p, .csv-modal-body li, .csv-modal-body label,
.status-modal-body p, .status-modal-body label,
.modal-body small, .modal-text {
    color: var(--tm-text-strong) !important;
}
.modal-body .muted, .modal-body .text-muted, .modal-body .hint,
.modal-error { color: var(--tm-text) !important; }
.modal-body strong, .modal-body b { color: var(--tm-title) !important; }
.modal-body a, .csv-modal-body a { color: #60a5fa !important; }
.modal-body hr, .modal-grid > div + div { border-color: var(--tm-ring) !important; }

/* --- close buttons --- */
.modal-close,
.csv-modal-close,
.status-modal-close,
.pdf-modal-close {
    color: var(--tm-text) !important;
    background: transparent !important;
}
.modal-close:hover,
.csv-modal-close:hover,
.status-modal-close:hover,
.pdf-modal-close:hover {
    background: rgba(255, 255, 255, .10) !important;
    color: #fff !important;
}
.modal-close svg { color: inherit !important; }

/* --- footers / action rows --- */
.modal-footer, .modal-foot, .modal-actions,
.csv-modal-footer, .status-modal-footer {
    background: var(--tm-footer) !important;
    border-top: 1px solid var(--tm-ring) !important;
}

/* --- form controls inside modals --- */
.modal input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
.modal select, .modal textarea,
.csv-modal input:not([type="checkbox"]):not([type="radio"]),
.csv-modal select, .csv-modal textarea,
.status-modal input:not([type="checkbox"]):not([type="radio"]),
.status-modal select, .status-modal textarea {
    background: var(--tm-panel-2) !important;
    color: var(--tm-title) !important;
    border: 1px solid var(--tm-ring) !important;
}
.modal input::placeholder, .modal textarea::placeholder,
.csv-modal input::placeholder, .status-modal input::placeholder {
    color: var(--tm-text-muted) !important;
}
.modal select option, .csv-modal select option, .status-modal select option {
    background: var(--tm-panel-2);
    color: #fff;
}

/* --- tables inside modals --- */
.modal table, .csv-modal table, .status-modal table { color: var(--tm-text-strong) !important; }
.modal th, .csv-modal th, .status-modal th {
    color: var(--tm-text) !important;
    border-bottom-color: var(--tm-ring) !important;
}
.modal td, .csv-modal td, .status-modal td {
    border-bottom-color: var(--tm-ring) !important;
}

/* --- legacy modal buttons: keep cancel/secondary readable on dark --- */
.btn-modal.secondary,
.modal-actions .secondary,
.modal-footer .secondary {
    background: rgba(255, 255, 255, .10) !important;
    color: #fff !important;
    border: 1px solid var(--tm-ring-soft) !important;
}
.btn-modal.secondary:hover,
.modal-actions .secondary:hover { background: rgba(255, 255, 255, .20) !important; }
.btn-modal.danger { background: #ef4444 !important; color: #fff !important; border: 0 !important; }
.btn-modal.danger:hover { background: #f87171 !important; }
