/* =============================================================================
   WireBuddy - Custom Styles
   ============================================================================= */

/* -----------------------------------------------------------------------------
   CSS Variables (aligned with Bootstrap defaults)
   ----------------------------------------------------------------------------- */
:root {
    --wb-primary: #88171a;
    --wb-primary-hover: #6f1215;
    --bs-primary: #88171a;
    --bs-primary-rgb: 136, 23, 26;
    --wb-accent-red: #ff6384;
    --wb-accent-red-rgb: 255, 99, 132;
    --wb-accent-red-strong: #b4234d;
    --wb-success: #198754;
    --wb-danger: #dc3545;
    --wb-warning: #ffc107;
    --wb-info: #0dcaf0;
    --wb-info-strong: #0a58ca;
    --wb-secondary: #6c757d;
    --wb-sidebar-link-color: #4b5563;
    --wb-bg-soft: #f8f9fa;
    --wb-bg-strong: #e9ecef;
    /* Z-index layering */
    --wb-z-banner: 1080;
    --wb-z-toast: 1090;
    --wb-monospace-fg: #495057;
    --wb-monospace-bg: rgba(0, 0, 0, 0.05);
    --wb-danger-strong: #b02a37;
    --wb-modal-backdrop-bg: rgba(15, 23, 42, 0.6);
    --wb-modal-backdrop-blur: 8px;
    --wb-modal-backdrop-saturate: 0.8;
}

[data-bs-theme="dark"] {
    --wb-bg-soft: #1f2937;
    --wb-bg-strong: #111827;
    /* Dark mode surfaces and borders */
    --wb-bg-surface: #1f2937;
    --wb-bg-elevated: #4b5563;
    --wb-border-subtle: #374151;
    --wb-border-strong: #4b5563;
    --wb-sidebar-link-color: #b0b8c4;
    --wb-text-primary: #f3f4f6;
    --wb-text-secondary: #dee2e6;
    --wb-text-tertiary: #d1d5db;
    --wb-text-muted: #9ca3af;
    --wb-monospace-fg: #dbe4ee;
    --wb-monospace-bg: rgba(255, 255, 255, 0.08);
    --wb-accent-red-strong: #ff8aa5;
    --wb-info-strong: #6edff6;
    --wb-danger-strong: #ff6384;
}

/* -----------------------------------------------------------------------------
   Custom Fonts
   ----------------------------------------------------------------------------- */
@font-face {
    font-family: 'Roboto Flex';
    src: url('/static/vendor/fonts/RobotoFlex.woff2') format('woff2-variations');
    font-weight: 100 1000;
    font-stretch: 25% 151%;
    font-style: oblique -10deg 0deg;
    font-display: swap;
}

/* -----------------------------------------------------------------------------
   Base Styles
   ----------------------------------------------------------------------------- */
body {
    font-family: 'Roboto Flex', system-ui, -apple-system, 'Segoe UI', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bs-body-bg);
    overflow-x: hidden;
    overflow-y: auto;
}

.modal-backdrop.show {
    background-color: var(--wb-modal-backdrop-bg);
    -webkit-backdrop-filter: blur(var(--wb-modal-backdrop-blur)) saturate(var(--wb-modal-backdrop-saturate));
    backdrop-filter: blur(var(--wb-modal-backdrop-blur)) saturate(var(--wb-modal-backdrop-saturate));
}

h1 {
    font-weight: 700;
}

/* Summary element focus indicator (used in details/summary) */
summary:focus,
summary:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: 2px;
    border-radius: var(--wb-radius-sm);
}

/* Material Icons base styles are in wb-ui-system.css Section 13 */

/* Timestamp Display - Monospace Font */
.peer-last-seen,
td[data-label="Last Seen"] {
    font-family: 'Roboto Flex', 'Courier New', Courier, monospace;
    font-variant-numeric: tabular-nums;
}

/* Code Tag - Override Bootstrap red color with neutral dark */
code,
kbd,
samp {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    color: var(--wb-monospace-fg);
    background-color: var(--wb-monospace-bg);
    border-radius: var(--wb-radius-sm);
    padding: 0.1rem 0.35rem;
}

:where(.wb-monospace-value, .font-monospace:not(input):not(textarea):not(select):not(button):not(td):not(th):not(table):not(tr):not(tbody):not(thead), .asn-badge, .asn-inline) {
    color: var(--wb-monospace-fg);
    background-color: var(--wb-monospace-bg);
    border-radius: var(--wb-radius-sm);
    padding: 0.1rem 0.35rem;
    display: inline-block;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

html:not(.login-page)[data-bs-theme="light"] body {
    background: linear-gradient(180deg, #f8fbff 0%, #e8eef6 52%, #dde6f0 100%);
}

html:not(.login-page)[data-bs-theme="dark"] body {
    background: var(--bs-body-bg);
}

html:not(.login-page)[data-bs-theme="dark"] .main-content {
    background-color: var(--bs-body-bg);
}

/* -----------------------------------------------------------------------------
   Login Page
   ----------------------------------------------------------------------------- */
html.login-page {
    height: 100%;
}

html.login-page body {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: calc(1rem + env(safe-area-inset-top));
    padding-right: calc(1rem + env(safe-area-inset-right));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    padding-left: calc(1rem + env(safe-area-inset-left));
    overflow-y: auto;
}

/* Ensure scrollability on mobile when keyboard appears */
@media (max-width: 767.98px) {
    html.login-page body {
        overflow-y: auto;
    }
}

html.login-page[data-bs-theme="light"] body {
    background: linear-gradient(135deg, #88171a 0%, #b73639 100%);
}

html.login-page[data-bs-theme="dark"] body {
    background: linear-gradient(135deg, #581012 0%, #88171a 100%);
}

.login-card {
    max-width: 400px;
    width: calc(100% - 2rem);
    margin: 0 auto;
    /* Ensure card is scrollable within viewport on mobile */
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
}

.logo-icon {
    font-size: 3rem;
    color: var(--wb-primary);
}

/* Logo theming - invert for visibility based on theme */
.logo-themed {
    filter: invert(0) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.18));
}

[data-bs-theme="dark"] .logo-themed {
    filter: invert(1) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.login-tagline {
    color: var(--bs-secondary-color);
}

html.login-page[data-bs-theme="dark"] .login-tagline {
    color: #fff;
}

/* -----------------------------------------------------------------------------
   Cards
   ----------------------------------------------------------------------------- */
/* Base .card styles (border, shadow, radius, overflow) are in wb-ui-system.css */

html.login-page .login-card {
    box-shadow: 0 20px 48px -18px rgba(5, 23, 49, 0.45), 0 8px 18px rgba(5, 23, 49, 0.2);
}

[data-bs-theme="dark"] .card {
    background-color: var(--wb-bg-surface);
    border-color: var(--wb-border-subtle);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

html.login-page[data-bs-theme="dark"] .login-card {
    box-shadow: 0 22px 52px -20px rgba(0, 0, 0, 0.75), 0 10px 20px rgba(0, 0, 0, 0.45);
}

/* Dark mode card headers - app pages use body-bg, login uses surface */
html:not(.login-page)[data-bs-theme="dark"] .card-header {
    background-color: var(--bs-body-bg);
    border-bottom-color: rgba(255, 255, 255, 0.14);
}

html.login-page[data-bs-theme="dark"] .card-header,
[data-bs-theme="dark"] .login-card .card-header {
    background-color: var(--wb-bg-surface);
    border-bottom-color: var(--wb-border-subtle);
}

/* Dark mode card bodies - app pages use body-bg, login uses surface */
html:not(.login-page)[data-bs-theme="dark"] .card-body {
    background-color: var(--bs-body-bg);
}

html.login-page[data-bs-theme="dark"] .card-body,
[data-bs-theme="dark"] .login-card .card-body {
    background-color: var(--wb-bg-surface);
}

/* Dark mode tables within cards */
html:not(.login-page)[data-bs-theme="dark"] .card .table {
    --bs-table-bg: var(--bs-body-bg);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.04);
    color: var(--bs-body-color);
}

html.login-page[data-bs-theme="dark"] .card .table,
[data-bs-theme="dark"] .login-card .table {
    --bs-table-bg: var(--wb-bg-surface);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.04);
    color: var(--bs-body-color);
}

/* Dark mode table-danger (blocked DNS queries) */
[data-bs-theme="dark"] .table-danger {
    --bs-table-color: var(--wb-text-primary);
    --bs-table-bg: rgba(220, 53, 69, 0.15);
    --bs-table-border-color: rgba(220, 53, 69, 0.3);
    --bs-table-striped-bg: rgba(220, 53, 69, 0.2);
    --bs-table-striped-color: var(--wb-text-primary);
    --bs-table-hover-bg: rgba(220, 53, 69, 0.25);
    --bs-table-hover-color: var(--wb-text-primary);
    color: var(--bs-table-color);
}

[data-bs-theme="dark"] .table-danger td,
[data-bs-theme="dark"] .table-danger th {
    color: var(--wb-text-primary);
}

[data-bs-theme="dark"] .table-danger .text-muted {
    color: var(--wb-text-tertiary);
}

/* -----------------------------------------------------------------------------
   Badges
   ----------------------------------------------------------------------------- */
.badge {
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

[data-bs-theme="dark"] .badge {
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

/* -----------------------------------------------------------------------------
   Forms (Dark Mode)
   ----------------------------------------------------------------------------- */
[data-bs-theme="dark"] .form-control {
    background-color: var(--wb-border-subtle);
    border-color: var(--wb-border-strong);
    color: var(--wb-text-primary);
}

[data-bs-theme="dark"] .form-control:focus {
    background-color: var(--wb-bg-elevated);
    border-color: var(--wb-primary);
    color: var(--wb-text-primary);
}

.form-check-input:checked {
    background-color: var(--wb-primary);
    border-color: var(--wb-primary);
}

.form-switch .form-check-input {
    background-position: left 2px center;
}

.form-switch .form-check-input:checked {
    background-position: right 2px center;
}

.form-switch .form-check-input:focus {
    border-color: rgba(var(--bs-primary-rgb), 0.55);
    box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.22);
}

/* -----------------------------------------------------------------------------
   Custom WireBuddy button base class
   ----------------------------------------------------------------------------- */
.wb-btn {
    background-color: transparent;
    border: 1px solid #ced4da;
    border-radius: var(--wb-radius-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    color: var(--bs-body-color);
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
}

.wb-btn:hover {
    background-color: rgba(0, 0, 0, 0.04);
    border-color: #adb5bd;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    color: var(--bs-body-color);
}

.wb-btn:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.wb-btn:active {
    background-color: rgba(0, 0, 0, 0.07);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* Dark mode base for WireBuddy buttons */
[data-bs-theme="dark"] .wb-btn {
    border-color: #495057;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    color: var(--wb-text-secondary);
}

[data-bs-theme="dark"] .wb-btn:hover {
    background-color: rgba(255, 255, 255, 0.06);
    border-color: #6c757d;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    color: #f8f9fa;
}

[data-bs-theme="dark"] .wb-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
}

/* =============================================================================
   Bootstrap Button Overrides
   
   Bootstrap 5.3 reads these CSS custom properties:
     Base:   color: var(--bs-btn-color)           bg: var(--bs-btn-bg)
     Hover:  color: var(--bs-btn-hover-color)      bg: var(--bs-btn-hover-bg)
     Active: color: var(--bs-btn-active-color)     bg: var(--bs-btn-active-bg)
   
   All hover/active variables MUST be set on the BASE selector, NOT in :hover
   pseudo-class rules, because Bootstrap reads them from the element's
   computed custom properties.
   ============================================================================= */

/* ── Primary action buttons (filled: login, create, save, modal OK) ───────── */
.btn.btn-primary {
    --bs-btn-bg: var(--wb-primary);
    --bs-btn-border-color: var(--wb-primary);
    --bs-btn-color: #fff;
    --bs-btn-hover-bg: var(--wb-primary-hover);
    --bs-btn-hover-border-color: var(--wb-primary-hover);
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: var(--wb-primary-hover);
    --bs-btn-active-border-color: var(--wb-primary-hover);
    --bs-btn-active-color: #fff;
    --bs-btn-disabled-bg: var(--wb-primary);
    --bs-btn-disabled-border-color: var(--wb-primary);
    --bs-btn-disabled-color: #fff;
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    box-shadow: 0 1px 3px rgba(var(--bs-primary-rgb), 0.2);
}

.btn.btn-primary:hover {
    box-shadow: 0 2px 6px rgba(var(--bs-primary-rgb), 0.3);
}

.btn.btn-primary:focus,
.btn.btn-primary:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: 2px;
}

/* ── Danger buttons (filled) ───────────────────────────────────────────────── */
.btn.btn-danger {
    --bs-btn-bg: var(--wb-danger);
    --bs-btn-border-color: var(--wb-danger);
    --bs-btn-color: #fff;
    --bs-btn-hover-bg: #bb2d3b;
    --bs-btn-hover-border-color: #bb2d3b;
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: #b02a37;
    --bs-btn-active-border-color: #b02a37;
    --bs-btn-active-color: #fff;
    --bs-btn-focus-shadow-rgb: 220, 53, 69;
    box-shadow: 0 1px 3px rgba(220, 53, 69, 0.2);
}

.btn.btn-danger:hover {
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.3);
}

.btn.btn-danger:focus,
.btn.btn-danger:focus-visible {
    outline: 2px solid var(--wb-danger);
    outline-offset: 2px;
}

/* ── Outline danger buttons ────────────────────────────────────────────────── */
.btn.btn-outline-danger {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--wb-danger);
    --bs-btn-color: var(--wb-danger);
    --bs-btn-hover-bg: var(--wb-danger);
    --bs-btn-hover-border-color: var(--wb-danger);
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: #bb2d3b;
    --bs-btn-active-border-color: #b02a37;
    --bs-btn-active-color: #fff;
    --bs-btn-focus-shadow-rgb: 220, 53, 69;
    box-shadow: 0 1px 3px rgba(220, 53, 69, 0.1);
}

.btn.btn-outline-danger:hover {
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.25);
}

.btn.btn-outline-danger:focus,
.btn.btn-outline-danger:focus-visible {
    outline: 2px solid var(--wb-danger);
    outline-offset: 2px;
}

/* ── Secondary / cancel modal buttons ──────────────────────────────────────── */
.btn.btn-secondary {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: #ced4da;
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-hover-bg: rgba(0, 0, 0, 0.04);
    --bs-btn-hover-border-color: #adb5bd;
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-active-bg: rgba(0, 0, 0, 0.07);
    --bs-btn-active-border-color: #adb5bd;
    --bs-btn-active-color: var(--bs-body-color);
    --bs-btn-focus-shadow-rgb: 108, 117, 125;
}

.btn.btn-secondary:focus,
.btn.btn-secondary:focus-visible {
    outline: 2px solid #6c757d;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(108, 117, 125, 0.25);
}

[data-bs-theme="dark"] .btn.btn-secondary {
    --bs-btn-border-color: #495057;
    --bs-btn-color: var(--wb-text-secondary);
    --bs-btn-hover-bg: rgba(255, 255, 255, 0.08);
    --bs-btn-hover-border-color: #6c757d;
    --bs-btn-hover-color: #f8f9fa;
    --bs-btn-active-bg: rgba(255, 255, 255, 0.12);
    --bs-btn-active-border-color: #6c757d;
    --bs-btn-active-color: #f8f9fa;
}

/* ── Outline buttons (ghost style with semantic colors) ───────────────────── */
.btn.btn-outline-primary {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--wb-primary);
    --bs-btn-color: var(--wb-primary);
    --bs-btn-hover-bg: rgba(var(--bs-primary-rgb), 0.08);
    --bs-btn-hover-border-color: var(--wb-primary-hover);
    --bs-btn-hover-color: var(--wb-primary-hover);
    --bs-btn-active-bg: rgba(var(--bs-primary-rgb), 0.12);
    --bs-btn-active-border-color: var(--wb-primary-hover);
    --bs-btn-active-color: var(--wb-primary-hover);
    box-shadow: 0 1px 3px rgba(var(--bs-primary-rgb), 0.1);
}

.btn.btn-outline-primary:hover {
    box-shadow: 0 2px 6px rgba(var(--bs-primary-rgb), 0.15);
}

.btn.btn-outline-primary:focus,
.btn.btn-outline-primary:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.25);
}

.btn.btn-outline-secondary {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: #ced4da;
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-hover-bg: rgba(0, 0, 0, 0.04);
    --bs-btn-hover-border-color: #adb5bd;
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-active-bg: rgba(0, 0, 0, 0.07);
    --bs-btn-active-border-color: #adb5bd;
    --bs-btn-active-color: var(--bs-body-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn.btn-outline-secondary:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.btn.btn-outline-secondary:focus,
.btn.btn-outline-secondary:focus-visible {
    outline: 2px solid #6c757d;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(108, 117, 125, 0.25);
}

.btn.btn-outline-info {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--wb-info);
    --bs-btn-color: var(--wb-info);
    --bs-btn-hover-bg: rgba(13, 202, 240, 0.08);
    --bs-btn-hover-border-color: #0dcaf0;
    --bs-btn-hover-color: #0aa2c0;
    --bs-btn-active-bg: rgba(13, 202, 240, 0.12);
    --bs-btn-active-border-color: #0aa2c0;
    --bs-btn-active-color: #0aa2c0;
    box-shadow: 0 1px 3px rgba(13, 202, 240, 0.1);
}

.btn.btn-outline-info:hover {
    box-shadow: 0 2px 6px rgba(13, 202, 240, 0.15);
}

.btn.btn-outline-info:focus,
.btn.btn-outline-info:focus-visible {
    outline: 2px solid var(--wb-info);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(13, 202, 240, 0.25);
}

.btn.btn-outline-success {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--wb-success);
    --bs-btn-color: var(--wb-success);
    --bs-btn-hover-bg: rgba(25, 135, 84, 0.08);
    --bs-btn-hover-border-color: #157347;
    --bs-btn-hover-color: #157347;
    --bs-btn-active-bg: rgba(25, 135, 84, 0.12);
    --bs-btn-active-border-color: #146c43;
    --bs-btn-active-color: #146c43;
    box-shadow: 0 1px 3px rgba(25, 135, 84, 0.1);
}

.btn.btn-outline-success:hover {
    box-shadow: 0 2px 6px rgba(25, 135, 84, 0.15);
}

.btn.btn-outline-success:focus,
.btn.btn-outline-success:focus-visible {
    outline: 2px solid var(--wb-success);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.25);
}

.btn.btn-outline-warning {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--wb-warning);
    --bs-btn-color: #856404;
    --bs-btn-hover-bg: rgba(255, 193, 7, 0.08);
    --bs-btn-hover-border-color: #e0a800;
    --bs-btn-hover-color: #664d03;
    --bs-btn-active-bg: rgba(255, 193, 7, 0.12);
    --bs-btn-active-border-color: #d39e00;
    --bs-btn-active-color: #664d03;
    box-shadow: 0 1px 3px rgba(255, 193, 7, 0.1);
}

.btn.btn-outline-warning:hover {
    box-shadow: 0 2px 6px rgba(255, 193, 7, 0.15);
}

.btn.btn-outline-warning:focus,
.btn.btn-outline-warning:focus-visible {
    outline: 2px solid var(--wb-warning);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.25);
}

/* Dark mode adjustments for outline buttons */
[data-bs-theme="dark"] .btn.btn-outline-primary {
    --bs-btn-color: #ff9496;
    --bs-btn-hover-bg: rgba(var(--bs-primary-rgb), 0.15);
    --bs-btn-hover-color: #ffb4b6;
}

[data-bs-theme="dark"] .btn.btn-outline-secondary {
    --bs-btn-border-color: #6c7683;
    --bs-btn-color: #f2f5f8;
    --bs-btn-hover-bg: rgba(255, 255, 255, 0.08);
    --bs-btn-hover-border-color: #8c96a3;
    --bs-btn-hover-color: #f8f9fa;
    --bs-btn-active-bg: rgba(255, 255, 255, 0.12);
    --bs-btn-active-border-color: #8c96a3;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

[data-bs-theme="dark"] .text-danger {
    color: var(--wb-danger-strong) !important;
}

[data-bs-theme="dark"] .btn.btn-outline-info {
    --bs-btn-color: #6edff6;
    --bs-btn-hover-bg: rgba(13, 202, 240, 0.15);
    --bs-btn-hover-color: #9be7fb;
}

[data-bs-theme="dark"] .btn.btn-outline-success {
    --bs-btn-color: #75b798;
    --bs-btn-hover-bg: rgba(25, 135, 84, 0.15);
    --bs-btn-hover-color: #9dd3bb;
}

[data-bs-theme="dark"] .btn.btn-outline-warning {
    --bs-btn-border-color: #ffcd39;
    --bs-btn-color: #ffcd39;
    --bs-btn-hover-bg: rgba(255, 193, 7, 0.15);
    --bs-btn-hover-color: #ffe69c;
}

[data-bs-theme="dark"] .btn.btn-outline-danger {
    --bs-btn-border-color: #ff6384;
    --bs-btn-color: #ff6384;
    --bs-btn-hover-bg: rgba(220, 53, 69, 0.15);
    --bs-btn-hover-color: #ff8a8a;
}

[data-bs-theme="dark"] .btn.btn-outline-secondary:hover,
[data-bs-theme="dark"] .btn.btn-outline-info:hover,
[data-bs-theme="dark"] .btn.btn-outline-success:hover,
[data-bs-theme="dark"] .btn.btn-outline-warning:hover,
[data-bs-theme="dark"] .btn.btn-outline-danger:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ── Warning buttons ─────────────────────────────────────────────────────────── */
.btn.btn-warning {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--wb-warning);
    --bs-btn-color: #856404;
    --bs-btn-hover-bg: var(--wb-warning);
    --bs-btn-hover-border-color: var(--wb-warning);
    --bs-btn-hover-color: #212529;
    --bs-btn-active-bg: #e0a800;
    --bs-btn-active-border-color: #d39e00;
    --bs-btn-active-color: #212529;
    --bs-btn-focus-shadow-rgb: 255, 193, 7;
    box-shadow: 0 1px 3px rgba(255, 193, 7, 0.15);
}

.btn.btn-warning:focus,
.btn.btn-warning:focus-visible {
    outline: 2px solid var(--wb-warning);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.25);
}

[data-bs-theme="dark"] .btn.btn-warning {
    --bs-btn-border-color: #ffcd39;
    --bs-btn-color: #ffcd39;
    --bs-btn-hover-bg: #ffcd39;
    --bs-btn-hover-border-color: #ffcd39;
    --bs-btn-hover-color: #212529;
}

/* =============================================================================
   Dark Mode Fixes
   ============================================================================= */

/* ── Fix: btn-light focus-visible for light mode ────────────────────────── */
.btn.btn-light:focus,
.btn.btn-light:focus-visible {
    outline: 2px solid #6c757d;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(108, 117, 125, 0.25);
}

/* ── Fix: btn-light in Dark Mode (used for interface action buttons) ─────── */
[data-bs-theme="dark"] .btn.btn-light {
    --bs-btn-bg: #273244;
    --bs-btn-border-color: var(--wb-border-subtle);
    --bs-btn-color: #e5e7eb;

    --bs-btn-hover-bg: #334155;
    --bs-btn-hover-border-color: var(--wb-border-strong);
    --bs-btn-hover-color: #ffffff;

    --bs-btn-active-bg: var(--wb-bg-surface);
    --bs-btn-active-border-color: var(--wb-border-strong);
    --bs-btn-active-color: #ffffff;

    --bs-btn-disabled-bg: var(--wb-bg-surface);
    --bs-btn-disabled-border-color: var(--wb-border-subtle);
    --bs-btn-disabled-color: #6b7280;

    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

[data-bs-theme="dark"] .btn.btn-light:focus,
[data-bs-theme="dark"] .btn.btn-light:focus-visible {
    outline: 2px solid var(--wb-border-strong);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(75, 85, 99, 0.25);
}

/* ── Icon buttons focus indicator ───────────────────────────── */
.btn-icon:focus,
.btn-icon:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: 2px;
}

/* ── Form range (sliders) focus indicator ───────────────────── */
.form-range:focus,
.form-range:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: 2px;
}

.form-range:focus {
    box-shadow: none;
}

/* ── Optional: subtle action accent on hover (interfaces) ─────────────────── */
[data-bs-theme="dark"] .btn.btn-light[data-action="up"]:hover {
    border-color: var(--wb-success);
}

[data-bs-theme="dark"] .btn.btn-light[data-action="down"]:hover {
    border-color: var(--wb-danger);
}

[data-bs-theme="dark"] .btn.btn-light[data-action="restart"]:hover {
    border-color: var(--wb-warning);
}

/* Improve disabled clarity */
[data-bs-theme="dark"] .btn.btn-light:disabled {
    opacity: 0.45;
}

/* -----------------------------------------------------------------------------
   Banners & Toast Container
   ----------------------------------------------------------------------------- */
#keyMismatchBanner {
    position: sticky;
    top: 0;
    z-index: var(--wb-z-banner);
    border-left: 0;
    border-right: 0;
    border-top: 0;
}

#wbToastContainer {
    z-index: var(--wb-z-toast);
}

/* -----------------------------------------------------------------------------
   Navbar
   ----------------------------------------------------------------------------- */
.navbar {
    background: linear-gradient(135deg, var(--wb-primary) 0%, #b73639 100%);
    flex-shrink: 0;
}

.navbar-brand {
    font-weight: 700;
    letter-spacing: -0.5px;
}

.navbar-logo {
    height: 48px;
    width: auto;
    filter: brightness(0) invert(1) drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.7));
    transition: transform 0.1s ease-in-out;
}

.navbar-logo:hover {
    animation: shake 0.5s ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .navbar-logo:hover {
        animation: none;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0) rotate(0deg);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-2px) rotate(-1deg);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(2px) rotate(1deg);
    }
}

.navbar .nav-item {
    display: flex;
    align-items: center;
}

.navbar .nav-link {
    display: flex;
    align-items: center;
}

.navbar .navbar-actions {
    gap: 0.85rem;
}

.navbar .navbar-user-label {
    margin: 0;
    font-weight: 600;
    line-height: 1;
}

.navbar .navbar-theme-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    min-height: 1.4rem;
    text-decoration: none;
}

.navbar .navbar-theme-btn .material-icons {
    font-size: 1rem;
    line-height: 1;
}

.navbar .navbar-logout-btn {
    gap: 0.35rem;
    padding: 0.34rem 0.68rem;
}

.navbar .navbar-logout-icon {
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

.navbar .navbar-logout-label {
    font-weight: 600;
    line-height: 1;
}

@media (max-width: 991.98px) {
    .navbar .container-fluid {
        padding-left: 1.5rem;
        padding-right: 0;
    }
}

/* Align top logo with desktop sidebar menu content start */
@media (min-width: 992px) {
    .navbar .container-fluid {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }

    .navbar .navbar-brand {
        margin-left: 0.5rem;
    }

    .navbar .navbar-actions {
        gap: 0.85rem;
    }

    .navbar .navbar-user-label {
        margin: 0;
    }
}

/* -----------------------------------------------------------------------------
   Sidebar
   ----------------------------------------------------------------------------- */
.sidebar {
    width: 240px;
    background-color: #f8f9fa;
    border-right: 1px solid #e5e7eb;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: calc(100vh - var(--wb-footer-height, 48px));
    overflow-y: auto;
}

[data-bs-theme="dark"] .sidebar {
    background-color: var(--bs-body-bg);
    border-right-color: var(--wb-border-subtle);
}

.sidebar .nav-link {
    color: var(--wb-sidebar-link-color);
    padding: 0.75rem 1rem;
    border-radius: var(--wb-radius-md);
    margin: 0.25rem 0.5rem;
    transition: background-color 0.15s ease-in-out;
}

.sidebar .nav-link:hover {
    background-color: #e5e7eb;
}

[data-bs-theme="dark"] .sidebar .nav-link:hover {
    background-color: var(--wb-border-subtle);
}

.sidebar .nav-link.active {
    background-color: var(--wb-primary);
    color: white;
}

.sidebar .nav-link:focus-visible {
    outline: 2px solid var(--wb-primary);
    outline-offset: -2px;
}

.sidebar .nav-link .material-icons {
    font-size: 20px;
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.wb-shell {
    position: relative;
    min-height: 0;
    padding-bottom: var(--wb-footer-height);
    overflow: hidden;
}

@media (max-width: 991.98px) {
    .wb-shell {
        padding-bottom: 0;
    }
}

@media (min-width: 992px) {

    html:not(.login-page),
    html:not(.login-page) body {
        height: 100vh;
        overflow: hidden;
    }

    .wb-shell::after {
        content: "";
        position: absolute;
        left: 240px;
        top: 0;
        bottom: var(--wb-footer-height);
        width: 1px;
        background-color: #e5e7eb;
        pointer-events: none;
        z-index: 1;
    }

    [data-bs-theme="dark"] .wb-shell::after {
        background-color: var(--wb-border-subtle);
    }
}

/* -----------------------------------------------------------------------------
   Main Content
   ----------------------------------------------------------------------------- */
.main-content {
    flex: 1;
    min-width: 0;
    min-height: 0;
    /* Prevent flex overflow bugs */
    padding: var(--wb-space-3);
    padding-bottom: calc(var(--wb-space-3) + var(--wb-footer-height));
    /* Page-level scrolling only (no double-scroll) */
    overflow: visible;
}

/* -----------------------------------------------------------------------------
   Status Indicators
   ----------------------------------------------------------------------------- */
.status-up {
    color: var(--wb-success);
}

.status-down {
    color: var(--wb-danger);
}

.status-warning {
    color: var(--wb-warning);
}

/* -----------------------------------------------------------------------------
   Toasts
   ----------------------------------------------------------------------------- */
.toast {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

[data-bs-theme="dark"] .toast {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

/* -----------------------------------------------------------------------------
   Footer
   ----------------------------------------------------------------------------- */
.wb-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 0.75rem;
    line-height: 1.25;
    color: var(--bs-secondary-color);
    background: var(--bs-body-bg);
    border-top: 1px solid var(--bs-border-color);
    z-index: 1000;
}

.wb-footer-content {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    row-gap: 0.15rem;
    column-gap: 0;
}

.wb-footer-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: inherit;
    line-height: inherit;
}

.wb-footer-link:hover,
.wb-footer-link:focus,
.wb-footer-link:active,
.wb-footer-link:visited {
    color: inherit;
}

.wb-footer-link-icon {
    width: 14px;
    height: 14px;
    display: block;
    flex: 0 0 14px;
}

/* Footer slide-in animation on mobile */
@media (max-width: 767.98px) and (prefers-reduced-motion: no-preference) {
    .wb-footer {
        animation: footerSlideIn 0.35s ease-out;
    }
}

@keyframes footerSlideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* -----------------------------------------------------------------------------
   Mobile Touch Improvements
   ----------------------------------------------------------------------------- */
@media (max-width: 991.98px) {

    /* Larger touch targets for mobile navigation */
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
    }

    /* Better touch target for logout button */
    .navbar .btn-outline-light {
        padding: 0.5rem 0.75rem;
    }

    .sidebar {
        display: none;
    }
}

/* Touch-safe minimum sizes for coarse pointers */
@media (pointer: coarse) {

    .navbar .navbar-theme-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .navbar .navbar-logout-btn {
        min-height: 44px;
        padding: 0.5rem 0.85rem;
    }

    .sidebar .nav-link {
        min-height: 44px;
    }
}

/* Mobile Navigation Grid (2×3) */
.navbar-mobile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem 0.75rem;
    /* Isolate layout calculations to prevent reflow propagation */
    contain: layout;
}

/* ── Smooth mobile navbar open/close animation ────────────────────────────── */
@media (max-width: 991.98px) {
    .navbar-collapse.collapsing {
        overflow: hidden;
        transition: height 0.24s ease;
    }

    .navbar-mobile-grid {
        opacity: 0;
        transform: translateY(-8px);
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    .navbar-collapse.show .navbar-mobile-grid,
    .navbar-collapse.wb-nav-opening .navbar-mobile-grid {
        opacity: 1;
        transform: translateY(0);
    }

    .navbar-collapse.wb-nav-closing .navbar-mobile-grid {
        opacity: 0;
        transform: translateY(-6px);
    }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) and (max-width: 991.98px) {

    .navbar-collapse.collapsing,
    .navbar-mobile-grid {
        transition: none;
    }

    .navbar-mobile-grid {
        opacity: 1;
        transform: none;
    }
}

.navbar-mobile-grid .nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    font-size: 0.95rem;
    border-radius: var(--wb-radius-md);
    transition: background-color 0.15s ease;
    white-space: nowrap;
}

.navbar-mobile-grid .nav-link .material-icons {
    font-size: 22px;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.navbar-mobile-grid .nav-link:hover,
.navbar-mobile-grid .nav-link:focus {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.navbar-mobile-grid .nav-link.active {
    color: #fff;
    font-weight: 600;
    background-color: rgba(255, 255, 255, 0.15);
}

.navbar-mobile-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    font-size: 0.92rem;
    border-radius: var(--wb-radius-md);
    transition: background-color 0.15s ease;
}

.navbar-mobile-link .material-icons {
    font-size: 20px;
}

.navbar-mobile-link:hover,
.navbar-mobile-link:focus {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.navbar-mobile-link.active {
    color: #fff;
    font-weight: 600;
    background-color: rgba(255, 255, 255, 0.12);
}

/* -----------------------------------------------------------------------------
   Alerts
   ----------------------------------------------------------------------------- */
html.login-page .alert {
    display: none;
}

/* -----------------------------------------------------------------------------
   Leaflet Map Dark Mode Adjustments
   ----------------------------------------------------------------------------- */
[data-bs-theme="dark"] .leaflet-bar {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.8);
}

[data-bs-theme="dark"] .leaflet-bar>a {
    background-color: #343a40;
    border-bottom: 1px solid #495057;
    color: var(--wb-text-secondary);
}

[data-bs-theme="dark"] .leaflet-bar>a:hover,
[data-bs-theme="dark"] .leaflet-bar>a:focus {
    background-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .leaflet-bar>a.leaflet-disabled {
    background-color: #2b3035;
    color: #6c757d;
}

[data-bs-theme="dark"] .leaflet-popup-content-wrapper {
    background-color: var(--wb-bg-surface);
    color: var(--wb-text-primary);
    border: 1px solid var(--wb-border-subtle);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

[data-bs-theme="dark"] .leaflet-popup-tip {
    background-color: var(--wb-bg-surface);
    border: 1px solid var(--wb-border-subtle);
}

[data-bs-theme="dark"] .leaflet-popup-content {
    color: var(--wb-text-primary);
}

[data-bs-theme="dark"] .leaflet-popup-content strong {
    color: #ffffff;
}

[data-bs-theme="dark"] .leaflet-popup-content .text-muted {
    color: #c7d2e0;
}

/* -----------------------------------------------------------------------------
   Chart Empty State
   ----------------------------------------------------------------------------- */
.chart-empty-state {
    width: 100%;
    min-height: 100%;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    text-align: center;
    color: var(--bs-secondary-color);
    padding: 1.5rem 1rem;
}

.chart-empty-state .material-icons {
    font-size: clamp(46px, 5vw, 64px);
    line-height: 1;
    opacity: 0.58;
}

.chart-empty-state-text {
    font-weight: 400;
    opacity: 0.6;
}

.chart-empty-state-text.small {
    margin-top: -0.55rem;
    /* compensate gap to remove spacing */
}

.chart-empty-state-text-tight {
    margin-top: -0.35rem;
}

/* -----------------------------------------------------------------------------
   Mobile Condensed Tables (Roboto Flex width axis)
   Scope to specific class if needed for condensed display
   ----------------------------------------------------------------------------- */
/* @media (max-width: 767.98px) {
    .wb-table-condensed {
        font-stretch: 87.5%;
    }
} */

/* Reconnect / onboarding states */
body.wb-reconnecting .main-content {
    opacity: 0.35;
    filter: blur(8px) saturate(0.8);
    pointer-events: none;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

body.wb-reconnecting .sidebar {
    filter: blur(8px);
    transition: filter 0.3s ease;
}

body.wb-reconnecting .modal-backdrop.show {
    background-color: rgba(15, 23, 42, 0.6);
}

body.wb-onboarding .main-content,
body.wb-onboarding .sidebar {
    filter: blur(8px);
    transition: filter 0.3s ease;
}

body.wb-onboarding .modal-backdrop.show {
    background-color: rgba(15, 23, 42, 0.6);
}

.spinner-border {
    color: var(--bs-primary);
}

/* Spinners inside buttons must inherit button text color */
.btn .spinner-border {
    color: inherit;
}

#wbReconnectModal .modal-dialog {
    max-width: 460px;
}

#wbReconnectModal .modal-content {
    border: 1px solid rgba(128, 128, 128, 0.25);
    border-radius: var(--wb-radius-lg);
}

#wbReconnectModal .spinner-border {
    width: 2.25rem;
    height: 2.25rem;
}

@keyframes wbReconnectSoftPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(var(--bs-primary-rgb), 0);
    }

    50% {
        transform: scale(1.012);
        box-shadow: 0 0 0.85rem rgba(var(--bs-primary-rgb), 0.22);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(var(--bs-primary-rgb), 0);
    }
}

body.wb-reconnecting #wbReconnectModal.show .wb-reconnect-pulse {
    animation: wbReconnectSoftPulse 1.9s ease-in-out infinite;
    transform-origin: center;
}

@media (prefers-reduced-motion: reduce) {
    body.wb-reconnecting #wbReconnectModal.show .wb-reconnect-pulse {
        animation: none;
    }
}