/*
 * Component layer for the UI overhaul. Every rule is token-driven and every
 * class name here is NEW (nl-btn, nl-card, ...)
 */

/* ---- buttons */
.nl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: 600;
    line-height: 1;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .05s ease;
    text-decoration: none;
    white-space: nowrap;
}
.nl-btn:hover { background: var(--surface-3); }
.nl-btn:active { transform: translateY(1px); }
.nl-btn:disabled,
.nl-btn[disabled] { opacity: .55; cursor: not-allowed; }

.nl-btn--primary {
    background: var(--accent);
    color: var(--on-accent);
}
.nl-btn--primary:hover { background: var(--accent-strong); }

.nl-btn--ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.nl-btn--ghost:hover { background: var(--surface-2); border-color: var(--accent-strong); }

.nl-btn--danger { background: var(--danger); color: #fff; }
.nl-btn--success { background: var(--success); color: #fff; }

.nl-btn--sm { padding: 6px 11px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.nl-btn--lg { padding: 13px 22px; font-size: var(--text-md); }
.nl-btn--icon { padding: 9px; }

/* Default inline-icon size. Contexts with their own svg sizing (sidebar nav,
   collapse button) win on specificity; buttons get a slightly smaller glyph. */
.nl-icon { width: 18px; height: 18px; flex: none; }
.nl-btn .nl-icon { width: 16px; height: 16px; }
.nl-btn--sm .nl-icon { width: 15px; height: 15px; }

/* ---- icon action button (compact square, replaces emoji btn-groups) */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent-strong); background: var(--surface-2); }
.icon-btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn .nl-icon { width: 16px; height: 16px; }
.icon-btn.icon-btn--danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.row-actions { display: inline-flex; align-items: center; gap: 6px; }

/* ---- token pills (replace Bootstrap badge bg-*) */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.4;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    white-space: nowrap;
}
.pill--list { background: var(--accent-soft); color: var(--accent-strong); }
.pill--tpl { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.pill--muted { background: var(--surface-2); color: var(--text-muted); border-color: var(--border-soft); }
.pill--ok { background: var(--success-soft); color: var(--success); }
.pill--off { background: var(--surface-2); color: var(--text-faint); border-color: var(--border-soft); }
.pill--fail { background: var(--danger-soft); color: var(--danger); }
.pill .dotc { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; background: var(--accent-strong); }

/* ---- cards */
.nl-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}
.nl-card__head {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}
.nl-card__title { margin: 0; font-size: var(--text-md); font-weight: 700; }
.nl-card__body { padding: var(--space-5); }

/* ---- form controls */
.nl-input,
.nl-select,
.nl-textarea {
    width: 100%;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--text);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 9px 12px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.nl-textarea { min-height: 96px; resize: vertical; }
.nl-input::placeholder,
.nl-textarea::placeholder { color: var(--text-faint); }
.nl-input:focus,
.nl-select:focus,
.nl-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}
.nl-label {
    display: inline-block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

/* ---- tables */
.nl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}
.nl-table th,
.nl-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
}
.nl-table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: var(--text-xs);
}
.nl-table tbody tr:hover { background: var(--surface-2); }

/* ---- badges */
.nl-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    background: var(--surface-3);
    color: var(--text-muted);
}
.nl-badge--accent { background: var(--accent-soft); color: var(--accent-strong); }
.nl-badge--success { background: var(--success-soft); color: var(--success); }
.nl-badge--warning { background: var(--warning-soft); color: var(--warning); }
.nl-badge--danger { background: var(--danger-soft); color: var(--danger); }

/* ---- alerts / banners */
.nl-alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    font-size: var(--text-base);
}
/* Fades the alert out; 25-shell.js then sets display:none on animationend so the
   space it occupied is reclaimed. */
@keyframes alertFadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}
.nl-alert--success { background: var(--success-soft); border-color: var(--success); color: var(--success); animation: alertFadeOut 300ms ease 5s forwards; }
.nl-alert--danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); animation: alertFadeOut 300ms ease 10s forwards; }
.nl-alert--warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.nl-alert--info { background: var(--accent-soft); border-color: var(--accent-strong); color: var(--accent-strong); }
.nl-alert--dismissible {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}
.nl-alert__close {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
}

.nl-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-4);
    background: var(--warning-soft);
    color: var(--warning);
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
}

/* ---- tabs */
.nl-tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border);
}
.nl-tabs__tab {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 14px;
    cursor: pointer;
    text-decoration: none;
    transition: color .15s ease, border-color .15s ease;
}
.nl-tabs__tab:hover { color: var(--text); }
.nl-tabs__tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.nl-tabs--vertical {
    flex-direction: column;
    gap: 2px;
    border-bottom: none;
    border-right: 1px solid var(--border);
}
.nl-tabs--vertical .nl-tabs__tab {
    border-bottom: none;
    border-right: 2px solid transparent;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    text-align: left;
}
.nl-tabs--vertical .nl-tabs__tab.is-active {
    border-right-color: var(--accent);
    background: var(--surface-2);
}

/* ---- modal */
.nl-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(3, 8, 10, .6);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
}
.nl-modal {
    background: var(--surface-1);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow: auto;
}
.nl-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-soft);
}
.nl-modal__title { margin: 0; font-size: var(--text-md); font-weight: 700; }
.nl-modal__body { padding: var(--space-5); }
.nl-modal__foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-soft);
}

/* ---- Bootstrap-shaped modals, token-themed */
.nl-modal-backdrop-el {
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(3, 8, 10, .6);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity .15s ease;
}
.nl-modal-backdrop-el.show { opacity: 1; }
body.nl-modal-open { overflow: hidden; }

.modal-content {
    background: var(--surface-1);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
}
.modal-header,
.modal-footer {
    border-color: var(--border-soft);
}
.modal-title {
    color: var(--text);
    font-weight: 700;
}
/* Bootstrap's .btn-close is a dark SVG; invert it on dark surfaces. */
.dark .btn-close {
    filter: invert(1) grayscale(1) brightness(1.6);
}

/* ---- switch */
.nl-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 52px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--surface-3);
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: background .18s ease;
}
.nl-switch__thumb {
    position: absolute;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    transition: transform .18s ease;
}
.nl-switch[aria-checked="true"] { background: var(--accent); }
.nl-switch[aria-checked="true"] .nl-switch__thumb { transform: translateX(24px); }

/* ---- loading spinner overlay */
.spinner {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1200;
    width: 100%;
    height: 100vh;
    overflow: auto;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(3, 8, 10, .75);
    /* The scrim is always dark regardless of theme, so spinner text is a fixed
       light color (not the theme --text, which is dark in light mode). */
    color: #eaf3f7;
}
.spinner-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);

    padding: 16px 16px;
    min-width: 450px;
    min-height: 320px;
    justify-content: center;
    background: var(--surface-1);
    border: 3px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.spinner-card img { max-width: 120px; height: auto; }
/* the recommendations pull appends its Cancel button here so the border box
   wraps the spinner, text and cancel together */
.spinner-card #recs-cancel-btn { margin-top: var(--space-2); }
.spinner-card p { margin-top: var(--space-3); }
/* Determinate progress bar fed by /pull_progress polling; spinner.js shows it
   only for operations that report progress. Fixed colors match the tip line
   because the scrim is always dark regardless of theme. */
.spinner-progress {
    width: 300px;
    height: 6px;
    border-radius: 3px;
    background: rgba(233, 241, 242, .18);
    overflow: hidden;
}
.spinner-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: 3px;
    background: var(--accent, #62a1a4);
    transition: width .3s ease;
}
/* Rotating flavor line under the pinned action text. The scrim is always dark
   (theme-independent), so this uses a fixed light-muted color, not a token. */
.spinner-tip {
    margin-top: var(--space-2);
    max-width: 420px;
    padding: 0 var(--space-4);
    text-align: center;
    font-size: var(--text-sm);
    color: rgba(233, 241, 242, .72);
    min-height: 1.2em;
}
/* Contributor shout-outs echo the About page tiers. Fixed colors (the dark
   status tones) since the scrim is always dark; gold = --warning, green =
   --success. */
.spinner-tip--gold { color: #d6a53a; }
.spinner-tip--green { color: #3fae74; }

/* ---- chips (BCC recipients) - token-driven, owns the .nl-chip name */
.nl-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: stretch;
    padding: 8px;
    min-height: 44px;
    max-height: 240px;
    overflow-y: auto;
    border-radius: var(--radius-md);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.nl-chips:focus-within {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}
.nl-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-width: 0;
    gap: 6px;
    border-radius: var(--radius-full);
    padding: 4px 10px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: var(--text-xs);
}
/* long emails/usernames truncate rather than overhang the chip */
.nl-chip > span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nl-chip .remove {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: inherit;
    padding: 0;
}

/* ---- emoji picker (re-pointed at tokens from the legacy style.css block) */
#emoji-picker-container emoji-picker {
    --background: var(--surface-1);
    --border-color: var(--border);
    --category-font-color: var(--text);
    --input-border-color: var(--border);
    --input-font-color: var(--text);
    --input-placeholder-color: var(--text-faint);
    --outline-color: var(--accent);
    --category-button-active-background: var(--accent-soft);
    --border-size: 1px;
    border-radius: var(--radius-md);
}

/* ---- theme toggle */
.nl-theme-toggle {
    position: relative;
    flex: none;
    width: 52px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--surface-3);
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: background .18s ease;
}
.nl-theme-toggle .tt-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
}
.nl-theme-toggle .tt-sun { left: 7px; color: #d9a441; }
.nl-theme-toggle .tt-moon { right: 7px; color: var(--text-faint); }
.nl-theme-toggle .tt-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    transition: transform .18s ease;
}
.nl-theme-toggle[aria-checked="true"] .tt-thumb { transform: translateX(24px); }

/* ======================================================================
   Legacy shared primitives migrated verbatim from style.css.
   These classes are shared across the builder and schedule_preview (and,
   for .card, scheduling), so they live in this shared sheet rather than a
   page sheet. Page sheets load after this file and keep overriding them
   with tokens exactly as before, so the move is visually a no-op. Colors
   are the original hardcoded values on purpose (move, not restyle)
   ====================================================================== */

/* preview iframe (builder + schedule_preview) */
.frame {
    height: 30rem;
    min-height: 30rem;
    max-height: 60rem;
    width: 100%;
    max-width: 60rem;
    border: 1px solid #444;
    border-radius: 8px;
    background: #8acbd4 !important;
    position: sticky;
    top: 80px;
    overflow: auto;
}
.dark .frame {
    border: 1px solid #ccc;
    background: #333 !important;
}

/* logo helpers (sidebar/standalone/settings) */
.logo {
    height: 50px;
    margin-right: 10px;
}
.logo-preview-small {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 5px 0;
}
.logo-preview-img-small {
    max-width: 80px;
    max-height: 30px;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 2px;
    padding: 2px;
}
.logo-filename-small {
    color: #666;
    font-size: 0.9em;
}

/* recently-added blurred backdrop cards (builder preview + schedule_preview) */
.blur-container {
    position: relative;
    height: 100%;
    width: 100%;
    overflow: hidden;
    display: inline-block;
}
.bg-blur {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(4px) brightness(0.75);
    z-index: 0;
}
.content-table {
    position: relative;
    z-index: 1;
}
.table-striped {
    background-size: cover;
    background-position: center;
}
.table-striped tbody tr td {
    background-blend-mode: overlay;
    background-color: rgba(255, 255, 255, 0.5);
}

/* legacy global form field colors (pages/compat override where restyled) */
input, textarea {
    padding: 0 8px;
}
input, textarea, select, #statSelector, #graphSelector {
    border-radius: 5px;
    background-color: #8acbd4;
    color: #333;
}
.dark input, .dark textarea, .dark select, .dark #statSelector, .dark #graphSelector {
    background-color: #333;
    color: #8acbd4;
}
.dark .form-label {
    color: #8acbd4;
}
.form-select {
    background-color: #8acbd4;
}

/* legacy Bootstrap-shaped card (builder snap-ins, scheduling, schedule_preview) */
.card {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    transition: all 0.2s ease;
}
.card-header {
    background-color: #8acbd4 !important;
    padding: 12px 16px;
    border-radius: 8px 8px 0 0;
    color: #495057 !important;
}
.card-body {
    padding: 0;
    background-color: #62a1a4;
    border-radius: 0 0 8px 8px;
}
.dark .card {
    background-color: #4a4a4a;
    border-color: #666;
}
.dark .card-header {
    background-color: #555 !important;
    border-bottom-color: #666;
    color: #8acbd4 !important;
}
.dark .card-body {
    background-color: #222;
}
