/* ALERTS */
.alert-success {
    --bs-alert-color: #004d12;
    --bs-alert-bg: #e3f5e8;
    --bs-alert-border-color: #b3dfc0;
}

.alert-danger {
    --bs-alert-color: #7a1016;
    --bs-alert-bg: #fde8ea;
    --bs-alert-border-color: #f5b8bc;
}

.alert-warning {
    --bs-alert-color: #7a3500;
    --bs-alert-bg: #fdf0e3;
    --bs-alert-border-color: #f9ccaa;
}

.alert-info {
    --bs-alert-color: #1a3040;
    --bs-alert-bg: #e3edf2;
    --bs-alert-border-color: #b3c8d4;
}

/* TABS */
.custom-tabs .nav-link {
    font-weight: 500;
    color: var(--text-medium);
    border: none;
    border-bottom: 2px solid transparent;
    background-color: transparent;
    border-radius: 0;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    transition: color 0.15s, background-color 0.15s;
}

.custom-tabs .nav-link.active {
    border-bottom: 2px solid var(--brand-primary);
    background-color: transparent;
    color: var(--brand-primary);
    font-weight: 600;
}

.custom-tabs .nav-link:hover:not(.active) {
    border-color: var(--ui-border);
    color: var(--text-dark);
    text-decoration: none;
    background-color: var(--ui-light);
}

.custom-tabs .disabled {
    color: #6c757d;
    pointer-events: none;
}

/* KPI CARDS */
.kpi-card {
    cursor: pointer;
    background-color: white;
    padding: 1em;
    border-radius: 0.5em;
    border: 1px solid var(--ui-border);
    color: var(--text-dark);
    text-align: right;
}

.kpi-card:hover {
    background-color: var(--ui-light);
    opacity: 0.9;
    transform: translateY(-2px);
}

.kpi-card h5 {
    margin-bottom: 0;
    margin-right: 10px;
    font-size: 4em;
    color: var(--text-medium);
}

.kpi-card p {
    margin-bottom: 0;
    margin-right: 10px;
    color: var(--text-medium);
}

/* TUTORIAL CARDS */
.tutorial-card {
    background-color: white;
    padding: 2em;
    border-radius: 0.5em;
    border: 1px solid var(--ui-border);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.watermark-icon {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 150px;
    height: 150px;
    opacity: 0.15;
    z-index: 0;
    pointer-events: none;
    color: var(--brand-primary);
}

.tutorial-card h2,
.tutorial-card p,
.tutorial-card a {
    position: relative;
    z-index: 2;
}

/* PAGINATION */
.pagination .page-link {
    color: var(--brand-primary);
    background-color: #fff;
    border: 1px solid #dee2e6;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.pagination .page-link:hover,
.pagination .page-link:focus {
    background-color: var(--ui-light);
    text-decoration: none;
}

.pagination .page-item.active .page-link {
    color: #fff;
    background-color: var(--table-header-bg);
    border-color: var(--table-header-bg);
}

.pagination .page-item.disabled .page-link {
    color: #6c757d;
    pointer-events: none;
    background-color: #fff;
    border-color: #dee2e6;
}

/* ════════════════════════════════════════════════════════════════════
 *  STATUS PILL — canonical site-wide component.
 *
 *  Markup:
 *      <span class="status-pill status-pill--success">
 *          <span class="status-pill__dot"></span>Healthy
 *      </span>
 *
 *  Variants: --success / --warning / --danger / --info / --muted.
 *
 *  Soft tinted backgrounds with a leading status dot. The same vocabulary
 *  appears under several scoped aliases (.ap-pill, .dash-pill, .conn-pill,
 *  .pill inside .dash-card) — they all visually agree with this canonical.
 *  Prefer .status-pill for new code.
 * ════════════════════════════════════════════════════════════════════ */

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
    font-family: "Sage UI", "Helvetica Neue", Arial, sans-serif;
}

.status-pill__dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-pill--success { background: #e3f5e8; color: #004d12; }
.status-pill--success .status-pill__dot { background: var(--status-success-bg); }

.status-pill--warning { background: #fdf0e3; color: #7a3500; }
.status-pill--warning .status-pill__dot { background: var(--status-warning-bg); }

.status-pill--danger { background: #fde8ea; color: #7a1016; }
.status-pill--danger .status-pill__dot { background: var(--status-failed-bg); }

.status-pill--info { background: #e3edf2; color: #1a3040; }
.status-pill--info .status-pill__dot { background: #1a3040; }

.status-pill--muted { background: #eef1f2; color: #444; }
.status-pill--muted .status-pill__dot { background: #9aa3a8; }

/* Running variant — pulsing dot for active executions. */
.status-pill--running { background: #e3edf2; color: #1a3040; }
.status-pill--running .status-pill__dot {
    background: #1a3040;
    position: relative;
}
.status-pill--running .status-pill__dot::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1.5px solid #1a3040;
    opacity: 0.5;
    animation: status-pill-pulse 1.4s ease-out infinite;
}
@keyframes status-pill-pulse {
    0%   { transform: scale(.7); opacity: .6; }
    70%  { transform: scale(1.6); opacity: 0; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ── Backwards compatibility ────────────────────────────────────────
 * Legacy markup `<span class="badge status-pill text-bg-success">Label</span>`
 * is still rendered by the `health_badge` / `exec_badge` template tags and
 * by older templates. Map those to the canonical look so the whole site
 * matches without a coordinated rollout. The `badge` Bootstrap class is
 * left in place — its only contribution is `display:inline-block` which
 * we override below. */
.badge.status-pill,
.badge.status-pill.rounded-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 9999px !important;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    height: auto;
}

.badge.status-pill.text-bg-success { background: #e3f5e8 !important; color: #004d12 !important; }
.badge.status-pill.text-bg-danger  { background: #fde8ea !important; color: #7a1016 !important; }
.badge.status-pill.text-bg-warning { background: #fdf0e3 !important; color: #7a3500 !important; }
.badge.status-pill.text-bg-secondary,
.badge.status-pill.text-bg-info    { background: #eef1f2 !important; color: #444 !important; }
.badge.status-pill.text-bg-primary { background: #e3edf2 !important; color: #1a3040 !important; }

/* Plain `<span class="badge text-bg-*">…</span>` (no status-pill modifier)
 * is used in a few places for chips like "Under Maintenance". Match the
 * canonical look so they don't read as off-brand Bootstrap badges. */
.badge.text-bg-success:not(.status-pill) { background: #e3f5e8 !important; color: #004d12 !important; }
.badge.text-bg-danger:not(.status-pill)  { background: #fde8ea !important; color: #7a1016 !important; }
.badge.text-bg-warning:not(.status-pill) { background: #fdf0e3 !important; color: #7a3500 !important; }
.badge.text-bg-secondary:not(.status-pill),
.badge.text-bg-info:not(.status-pill)    { background: #eef1f2 !important; color: #444 !important; }
.badge.text-bg-primary:not(.status-pill) { background: #e3edf2 !important; color: #1a3040 !important; }

/* ── Scoped aliases ────────────────────────────────────────────────
 * The .ap-pill / .dash-pill / .conn-pill / .pill (in .dash-card)
 * scopes were introduced before this canonical existed and live in
 * their respective stylesheets. They already use the same colours and
 * shapes; this block normalises the small font-size differences so
 * pills read identically across every page no matter which alias is
 * applied. */
.dash-page .dash-card .pill,
.dash-page .dash-pill { font-size: 12px; line-height: 1.5; }

/* MODALS */
.add-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(30, 41, 59, 0.35);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(.4, 0, .2, 1);
}

.add-modal-overlay[x-show="open"],
.add-modal-overlay[style*="display: flex"] {
    opacity: 1;
    pointer-events: auto;
}

.add-modal-window {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    max-width: 600px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    padding: 2rem 2rem 1.5rem 2rem;
    position: relative;
    z-index: 1060;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(30px) scale(0.98);
    transition: opacity 0.3s cubic-bezier(.4, 0, .2, 1), transform 0.3s cubic-bezier(.4, 0, .2, 1);
}

.add-modal-wide {
    max-width: 1100px;
    width: 98vw;
}

.add-modal-overlay[x-show="open"] .add-modal-window,
.add-modal-overlay[style*="display: flex"] .add-modal-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: fadeInModal 0.3s;
}

.add-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--text-dark);
    cursor: pointer;
    z-index: 1070;
    width: 2rem;
    height: 2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.add-modal-close:hover {
    color: var(--brand-primary);
    background: var(--ui-light);
    border-radius: 50%;
}

/* Remove Bootstrap's focus ring on btn-close for mouse clicks;
   keep it for keyboard navigation only (accessibility) */
.btn-close:focus {
    box-shadow: none;
    outline: none;
}

.btn-close:focus-visible {
    box-shadow: var(--link-focus-shadow);
    outline: none;
}

@keyframes fadeInModal {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.use_existing_modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
    z-index: 1000;
}

.use_existing_modal[hidden] {
    display: none;
}

.use_existing_modal__dialog {
    background: var(--ui-white);
    border: 1px solid var(--ui-border);
    border-radius: 16px;
    width: min(640px, 92vw);
    max-height: 86vh;
    overflow: auto;
}

.use_existing_modal__header {
    margin-top: 10px;
    margin-left: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.use_existing_modal__header [data-ue-close] {
    margin-top: 5px;
    margin-right: 5px;
    margin-left: auto;
    order: 2;
    line-height: 1;
    font-size: 20px;
    float: none;
}

.use_existing_modal__header .card-title {
    margin: 0;
    order: 1;
}

.use_existing_modal__footer {
    padding: 12px 16px;
    border-bottom: 1px solid var(--ui-border);
}

.use_existing_modal__footer {
    border-top: 1px solid var(--ui-border);
    border-bottom: 0;
}

.use_existing_modal__body {
    padding: 16px;
}

/* NOTIFICATION DOTS */
.actions-notification,
.profile-dot,
.maintenance-dot,
.dropdown-dot {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--status-warning-bg);
    border-radius: 50%;
    display: inline-block;
    z-index: 2;
}

.actions-notification {
    top: 8px;
    right: 0;
    margin-left: 4px;
}

.profile-dot,
.maintenance-dot {
    top: 8px;
    right: -0.35rem;
}

.dropdown-dot {
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
}

/* DASHBOARD MASONRY */
.dashboard-masonry {
    column-count: 1;
    column-gap: 1.5rem;
}

@media (min-width: 768px) {
    .dashboard-masonry {
        column-count: 2;
    }
}

@media (min-width: 1400px) {
    .dashboard-masonry {
        column-count: 3;
    }
}

.dashboard-masonry__item {
    break-inside: avoid;
    margin-bottom: 1.5rem;
}

/* EMPTY STATE */
.border-dashed {
    border: 2px dashed var(--ui-border) !important;
}

/* CONNECTION LOGO CIRCLE
 * Neutral light background so transparent PNG logos render cleanly.
 * Default size (36px) for table rows and compact contexts.
 * Use .conn-logo-circle--lg (44px) for card/banner contexts.
 */
.conn-logo-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--ui-border);
    padding: 0;
}

.conn-logo-circle--lg {
    width: 44px;
    height: 44px;
    padding: 0;
}

.conn-logo-circle--sm {
    width: 28px;
    height: 28px;
    padding: 0;
}

.conn-logo-circle .conn-logo-img {
    transform: scale(1.05);
}

.conn-logo-img {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    object-fit: contain;
    display: block;
}

.conn-logo-initial {
    color: var(--text-dark);
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;
}

.conn-logo-circle--lg .conn-logo-initial {
    font-size: 0.95rem;
}

.conn-logo-circle--sm .conn-logo-initial {
    font-size: 0.7rem;
}

/* LOADERS */
.load-more-spinner {
    display: none;
    width: 1rem;
    height: 1rem;
    margin-left: .5rem;
    border: 2px solid rgba(0, 0, 0, .12);
    border-top-color: rgba(0, 0, 0, .6);
    border-radius: 50%;
}

.load-more-spinner.htmx-request {
    display: inline-block;
    animation: spin 0.7s linear infinite;
}

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