@import url("tokens.css");

/*
 * Loaded after sb-admin-2.min.css on every page. Bootstrap 4's compiled CSS
 * bakes hex literals into every rule (no build step here to swap Sass
 * variables), so re-theming happens at the declaration level: same
 * selectors, later in the cascade, same specificity -> last-wins.
 */

/* ---------- Font stack (Space Grotesk self-hosted for headings/nav/titles
   only -- body text and UI controls stay the system stack) ---------- */

body, .btn, .form-control {
    font-family: var(--font-body);
}

h1, h2, h3, h4, h5, h6,
.sidebar-brand-text, .navbar-nav .nav-link span {
    font-family: var(--font-display);
}

code, pre, .font-mono {
    font-family: var(--font-mono);
}

/* ---------- Brand color repaints (Bootstrap's stock indigo -> app teal) ---------- */

.btn-primary {
    background-color: var(--teal);
    border-color: var(--teal);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:not(:disabled):not(.disabled):active {
    background-color: var(--teal);
    filter: brightness(0.92);
    border-color: var(--teal);
}

.btn-outline-primary {
    color: var(--teal);
    border-color: var(--teal);
}

.btn-outline-primary:hover {
    background-color: var(--teal);
    border-color: var(--teal);
    color: var(--on-accent);
}

.bg-primary { background-color: var(--teal) !important; }
.text-primary { color: var(--teal) !important; }
.border-primary { border-color: var(--teal) !important; }

/* Fixed (not var()-driven) brand indigo -- the sidebar is meant to stay a
   constant dark panel across both page themes (see the dark-mode note in
   CLAUDE.md/the migration plan), but --teal itself shifts between light and
   dark mode (a small-accent color, not meant to cover a whole panel) --
   using it here would re-tint the sidebar on every theme toggle and risk
   breaking the white nav-link text's contrast. Literal hex, deliberately,
   not the live custom property. White text checked at 6.3:1 (top stop) and
   11.4:1 (bottom stop). */
.bg-gradient-primary,
.sidebar.bg-gradient-primary {
    background-color: #4f46e5;
    background-image: linear-gradient(180deg, #4f46e5 0%, #312e81 100%);
}

a { color: var(--teal); }
a:hover { color: var(--teal); filter: brightness(0.85); }

/* Focus rings -- every interactive control needs a visible :focus-visible
   state (WCAG 2.4.7); don't let Bootstrap's default blue focus ring clash
   with the repainted teal brand color, or silently vanish on a custom
   control. */
.btn:focus, .btn.focus,
.form-control:focus,
.dropdown-toggle:focus,
select:focus {
    box-shadow: 0 0 0 0.2rem rgba(var(--teal-rgb), 0.35);
    border-color: var(--teal);
}

/* ---------- Status color mapping (reuse this app's semantic tokens) ---------- */

.text-success, .badge-success { color: var(--good) !important; }
.bg-success, .badge-success { background-color: var(--good) !important; }
.text-warning, .badge-warning { color: var(--warning) !important; }
.bg-warning, .badge-warning { background-color: var(--warning) !important; }
.text-danger, .badge-danger { color: var(--critical) !important; }
.bg-danger, .badge-danger { background-color: var(--critical) !important; }

/* Stat-card left-accent border: map onto this app's categorical series
   colors instead of Bootstrap's stock success/info/warning/danger hexes,
   so KPI tiles stay visually consistent with the already-audited
   categorical palette used everywhere else (charts, heatmap). */
.border-left-primary { border-left: 0.25rem solid var(--cat-teal) !important; }
.border-left-success { border-left: 0.25rem solid var(--cat-green) !important; }
.border-left-info { border-left: 0.25rem solid var(--cat-violet) !important; }
.border-left-warning { border-left: 0.25rem solid var(--cat-amber) !important; }
.border-left-danger { border-left: 0.25rem solid var(--cat-coral) !important; }

/* ---------- Shape tokens (soft rounded look instead of BS4 defaults) ---------- */

.card, .dropdown-menu, .modal-content {
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

/* Bootstrap's own .dropdown-menu padding is `.5rem 0` -- vertical breathing
   room but zero horizontal, so every popover's labels/selects/buttons sat
   flush against its left/right edges. Every popover on the page (add
   filter, segments, alert bell, custom range) is built on this same
   .dropdown-menu base, so fixing it here covers all of them at once. */
.dropdown-menu {
    padding: 0.9rem 1rem;
}

.btn, .form-control, .custom-select {
    border-radius: var(--radius-sm);
}

/* ---------- Maximalist icon chips (sidebar links + card headers) ----------
   A small colored square housing a Font Awesome glyph, placed before a nav
   link's label or a card-header's title. The 6 numbered variants cycle the
   same fixed categorical order used everywhere else (indigo/amber/emerald/
   rose/violet/cyan) -- decorative section icons, not data series identity,
   so this is a fixed per-section assignment (set in the HTML via
   icon-chip-1..6), not something that should ever auto-cycle against live
   data. */
.sidebar .nav-link i {
    width: 1.1rem;
    text-align: center;
    margin-right: 0.6rem;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.85rem;
}

.sidebar .nav-item.active .nav-link i,
.sidebar .nav-item .nav-link:hover i {
    color: #fff;
}

.icon-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    margin-right: 0.65rem;
    font-size: 0.8rem;
    color: #fff;
    flex-shrink: 0;
}

.icon-chip-1 { background: var(--cat-teal); }
.icon-chip-2 { background: var(--cat-coral); }
.icon-chip-3 { background: var(--cat-amber); }
.icon-chip-4 { background: var(--cat-violet); }
.icon-chip-5 { background: var(--cat-green); }
.icon-chip-6 { background: var(--cat-magenta); }

/* Hero KPI gradient tiles: .stat--fill* base rules live in app-custom.css
   (which loads after this file on site.html and would otherwise win) --
   see that file for the actual gradient treatment. */

/* ---------- Base surfaces ---------- */

body {
    background: var(--bg);
    color: var(--ink);
}

/* SB Admin 2's actual compiled rule is the compound selector
   #wrapper #content-wrapper{background-color:#f8f9fc} (two IDs,
   specificity 2,0,0) -- a bare #content-wrapper override (1,0,0) loses to
   it regardless of cascade order, which shipped as a real bug: the light
   strip stayed visible behind the filter-bar, section titles, and card
   gaps in dark mode despite this file loading after sb-admin-2.min.css.
   Matching the compound selector, not !important, to stay consistent
   with this file's stated re-theming strategy (see header comment). */
#wrapper #content-wrapper {
    background-color: var(--bg);
}

.card {
    background: var(--surface);
    border-color: var(--hairline);
}

.card-header {
    background-color: var(--surface);
    border-bottom-color: var(--hairline);
    /* So an .icon-chip (inline-flex) sits beside the h2/h3 title instead of
       stacking above it (the title is block-level) -- cards that also need
       an action button on the right keep their explicit
       .justify-content-between utility class, which wins over this
       default via Bootstrap's own !important utilities. */
    display: flex;
    align-items: center;
}

.topbar.bg-white, .navbar.bg-white {
    background-color: var(--surface) !important;
    border-bottom: var(--bw) solid var(--hairline);
}

/* ---------- Theme-aware surface repaints ----------
   SB Admin 2 ships light-only, with hardcoded hex in every compiled rule.
   These re-declarations use var(--surface)/var(--ink)/etc instead of a
   literal color, so they self-adjust for whichever theme is active with NO
   [data-theme="dark"] gating needed -- tokens.css's own dual guard
   (@media(prefers-color-scheme) + :root[data-theme]) already makes those
   variables resolve correctly for OS-preference-default dark AND an
   explicit toggle AND light. In light mode these values equal Bootstrap's
   own stock colors, so applying them unconditionally is a no-op there and
   only changes anything once a theme actually goes dark. (This replaces an
   earlier draft of this section that gated everything behind an explicit
   [data-theme="dark"] attribute selector -- that version left a real gap
   for a first-time OS-dark visitor who hadn't toggled the theme yet, since
   Bootstrap's own hardcoded hex would've stayed light until they did.) */

.topbar.bg-white,
.navbar.bg-white,
.bg-white {
    background-color: var(--surface) !important;
    border-color: var(--hairline);
}

.card {
    background-color: var(--surface);
    border-color: var(--hairline);
    color: var(--ink);
}

.card-header {
    background-color: var(--surface);
    border-color: var(--hairline);
    color: var(--ink);
}

.modal-content {
    background-color: var(--surface);
    color: var(--ink);
    border-color: var(--hairline);
}

.modal-header,
.modal-footer {
    border-color: var(--hairline);
}

.dropdown-menu {
    background-color: var(--surface);
    border-color: var(--hairline);
    color: var(--ink);
}

.dropdown-item {
    color: var(--ink);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--surface-2);
    color: var(--ink);
}

.form-control,
.custom-select {
    background-color: var(--surface-2);
    border-color: var(--hairline);
    color: var(--ink);
}

.form-control:focus {
    background-color: var(--surface-2);
    color: var(--ink);
}

.text-gray-800,
.text-gray-600 {
    color: var(--ink) !important;
}

.text-gray-300 {
    color: var(--ink-faint) !important;
}

/* .sidebar-dark stays visually constant across both page themes -- it's a
   fixed hex (not var()-driven, see the .bg-gradient-primary comment above)
   by design intent, independent of the light/dark page toggle. */

/* ---------- Custom components with no Bootstrap equivalent ---------- */

/* Messages (login.html, index.html) -- kept byte-identical to the original
   dashboard.css rule so the existing JS (`msg.className = 'msg error'`)
   needs zero changes. */
.msg {
    margin-top: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    display: none;
    font-family: var(--font-mono);
    font-weight: 600;
}

.msg.error {
    display: block;
    background: rgba(var(--critical-rgb), 0.1);
    border: var(--bw) solid var(--critical);
    color: var(--critical);
}

.msg.success {
    display: block;
    background: rgba(var(--good-rgb), 0.1);
    border: var(--bw) solid var(--good);
    color: var(--good);
}

/* Custom buttons with no clean Bootstrap equivalent (index.html's row
   action buttons, built by dashboard.js's template strings as
   class="btn btn-ghost"/"btn btn-badge danger" -- kept verbatim so
   dashboard.js needs zero changes, same "reskin CSS not JS" pattern as
   Phase 1's login page). Bootstrap's own .btn sets padding/border-radius
   as a base; these override color/background/border on top of it. */
.btn-ghost {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--hairline);
}

.btn-ghost:hover {
    border-color: var(--teal);
    color: var(--teal);
}

.btn-badge {
    background: transparent;
    color: var(--ink-dim);
    border: var(--bw) solid var(--hairline);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.4rem 0.75rem;
    box-shadow: none;
}

.btn-badge:hover {
    color: var(--ink);
    border-color: var(--teal);
}

.btn-badge.danger:hover {
    color: var(--critical);
    border-color: var(--critical);
}

.logo {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: var(--teal);
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--on-accent);
    flex-shrink: 0;
}

/* Bootstrap 4 has no gap utility (added in v5) */
.gap-2 { gap: 0.5rem; }

.theme-toggle {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    background: var(--surface-2);
    border-color: var(--hairline);
    border-radius: var(--radius-sm);
}

.theme-toggle:hover { border-color: var(--teal); color: var(--teal); }

/* Row list (sites list, API tokens list -- index.html) */
.counter-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.counter-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: var(--bw) solid var(--hairline);
    animation: fadeUp 0.4s ease both;
}

.counter-row:last-of-type { border-bottom: none; }

.counter-name {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--ink);
    font-weight: 500;
}

.counter-meta {
    font-size: 0.7rem;
    color: var(--ink-faint);
    margin-top: 0.2rem;
}

.counter-count {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--teal);
    text-align: right;
    min-width: 60px;
    font-variant-numeric: tabular-nums;
}

.counter-actions {
    display: flex;
    gap: 0.35rem;
    justify-content: flex-end;
}

.snippet-box {
    background: var(--bg);
    border: var(--bw) solid var(--hairline);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--ink-faint);
    word-break: break-all;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.snippet-box:hover {
    color: var(--ink-dim);
    border-color: var(--teal);
}

.snippet-box::after {
    content: 'click to copy';
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    color: var(--ink-faint);
    opacity: 0;
    transition: opacity 0.2s;
}

.snippet-box:hover::after { opacity: 1; }

.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: var(--bw) solid var(--hairline);
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--ink-faint);
}

.empty-state p {
    color: var(--ink-faint);
    font-size: 0.85rem;
}

.empty-state p strong {
    color: var(--ink-dim);
    font-weight: 600;
}

.loading-state {
    padding: 3rem;
    text-align: center;
    color: var(--ink-faint);
    font-size: 0.85rem;
}

.loading-dot {
    display: inline-block;
    animation: pulse 1.5s ease infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

.stat-sub {
    font-size: 0.7rem;
    color: var(--ink-dim);
    font-family: var(--font-mono);
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}

@keyframes pulse {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

/* Remaining custom components (filter-chip, bar-row, heatmap, sparkline,
   chart-tooltip, funnel-step) are filled in during the site.html
   migration phase as each one moves out of dashboard.css and into this
   file. */
