header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: var(--bg-color);
    border-bottom: 2px solid var(--border-color);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    -webkit-text-stroke: 0.5px var(--primary-color);
    paint-order: stroke fill;
    background: linear-gradient(
        120deg,
        var(--primary-color) 0%,
        var(--primary-text-color) 35%,
        var(--primary-color) 50%,
        var(--primary-text-color) 65%,
        var(--primary-color) 100%
    );
    background-size: 250% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: titleShimmer 6s ease-in-out infinite;
}

@keyframes titleShimmer {
    0%, 100% { background-position: 100% 50%; }
    50%      { background-position: 0% 50%; }
}

h2 {
    margin-bottom: 20px;
    color: var(--text-color);
    font-size: 1.5rem;
}

.header-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 3px 4px;
}

.header-toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border-color);
    margin: 0 3px;
    flex-shrink: 0;
}

.header-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 5px;
    transition: color 0.2s, background 0.2s;
}

.header-link:hover {
    color: var(--text-color);
    background: var(--bg-secondary);
}

.header-locale {
    padding: 2px 4px;
    border: none;
    border-radius: 5px;
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.header-locale:hover {
    color: var(--text-color);
    background: var(--bg-secondary);
}

#server-version {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary);
    background: var(--border-color);
    padding: 2px 8px;
    border-radius: 10px;
    letter-spacing: 0.03em;
    transition: background 0.3s, color 0.3s, box-shadow 0.3s;
}

#server-version.has-update {
    background: var(--warning-color);
    color: #fff;
    cursor: pointer;
    animation: updatePulse 2s ease-in-out infinite;
}

@keyframes updatePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(255, 152, 0, 0); }
}

/* ── Update banner ── */
.update-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--primary-color);
    color: var(--text-color);
    font-size: 0.85rem;
    font-weight: 600;
    animation: bannerSlideDown 0.3s var(--ease-out);
}

.update-banner-text {
    color: var(--primary-color);
}

.update-banner-action {
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.update-banner-action:hover {
    color: var(--primary-color);
    background: var(--border-color);
}

/* ── Donation banner ── */
.donation-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 0.85rem;
    animation: bannerSlideDown 0.3s var(--ease-out);
}

.donation-banner-text {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.donation-banner-text .icon {
    width: 14px;
    height: 14px;
    color: #e25555;
    flex-shrink: 0;
}

.donation-banner-action {
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.donation-banner-action:hover {
    color: var(--primary-color);
    background: var(--border-color);
}

.donation-banner-donate {
    color: #e25555;
}

.donation-banner-donate:hover {
    color: #ff6b6b;
    background: rgba(226, 85, 85, 0.1);
}

@keyframes bannerSlideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.status-badge {
    font-size: 1rem;
    animation: pulse 2s infinite;
}

.status-badge.online {
    color: var(--primary-color);
}

.status-badge.offline {
    color: var(--danger-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Demo mode badge (header) */
.demo-badge {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #1a1a1a;
    background: #ffb300;
    padding: 2px 10px;
    border-radius: 10px;
    text-transform: uppercase;
    animation: demoPulse 3s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes demoPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Demo mode banner (top of page) */
.demo-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    background: linear-gradient(90deg, #ff8f00, #ffb300);
    color: #1a1a1a;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    z-index: var(--z-sticky, 100);
    position: relative;
}

.demo-banner-dismiss {
    background: none;
    border: none;
    color: #1a1a1a;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
    line-height: 1;
    flex-shrink: 0;
}

.demo-banner-dismiss:hover {
    opacity: 1;
}

/* Connection lost overlay */
.connection-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-connection);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    overflow: hidden;
}

.connection-overlay-content {
    text-align: center;
    color: #fff;
}

.connection-overlay-content h2 {
    margin: 16px 0 8px;
    font-size: 1.4rem;
}

.connection-overlay-content p {
    margin: 0;
    opacity: 0.7;
    font-size: 0.95rem;
}

.connection-spinner-lg {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: conn-spin 0.8s linear infinite;
}

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

/* Device card ping button spinning animation */
.card-ping-btn.spinning svg {
    animation: conn-spin 0.8s linear infinite;
}

/* Visually hidden — screen readers only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* WLED device health indicator */
.health-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    flex-shrink: 0;
}

.health-dot.health-online {
    background-color: var(--primary-color);
    box-shadow: 0 0 6px color-mix(in srgb, var(--primary-color) 60%, transparent); /* --primary-color glow */
}

.health-dot.health-offline {
    background-color: var(--danger-color);
    box-shadow: 0 0 6px color-mix(in srgb, var(--danger-color) 60%, transparent); /* --danger-color glow */
}

.health-dot.health-unknown {
    background-color: var(--text-secondary);
    animation: pulse 2s infinite;
}

.health-latency {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--primary-text-color);
    margin-left: auto;
    padding-left: 8px;
    opacity: 0.85;
}

.health-latency.offline {
    color: var(--danger-color);
}

/* Tabs */
.tab-bar {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s ease, border-color 0.25s ease;
}

.tab-btn:hover {
    color: var(--text-color);
}

.tab-btn.active {
    color: var(--primary-text-color);
    border-bottom-color: var(--primary-color);
}

.tab-badge {
    background: var(--border-color);
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 4px;
    min-width: 16px;
    text-align: center;
    line-height: 1.3;
    display: inline-block;
}

.tab-btn.active .tab-badge {
    background: var(--primary-color);
    color: var(--primary-contrast);
}

.tab-panel {
    display: none;
    position: relative;
}

.tab-panel.active {
    display: block;
    animation: tabFadeIn 0.25s ease-out;
}

@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Thin animated bar at top of tab panel during data refresh */
.tab-panel.refreshing::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 40%;
    height: 2px;
    background: var(--primary-color);
    border-radius: 1px;
    animation: tab-loading-slide 1.2s ease-in-out infinite;
    z-index: 2;
}

@keyframes tab-loading-slide {
    0%   { left: -40%; }
    100% { left: 100%; }
}

/* Header toolbar buttons */
.header-btn {
    background: transparent;
    border: none;
    padding: 4px 6px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: color 0.2s, background 0.2s;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.header-btn:hover {
    color: var(--text-color);
    background: var(--bg-secondary);
}

/* Reusable color picker popover */
.color-picker-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.color-picker-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.color-picker-swatch:hover {
    box-shadow: 0 0 6px var(--primary-color);
}
.color-picker-popover {
    position: absolute;
    top: calc(100% + 8px);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 8px 24px var(--shadow-color);
    z-index: 200;
    animation: color-picker-pop-in 0.15s ease-out;
}
.color-picker-popover.anchor-right { right: 0; }
.color-picker-popover.anchor-left  { left: 0; }
.color-picker-popover.cp-fixed { z-index: 1000; }
@keyframes color-picker-pop-in {
    from { opacity: 0; transform: translateY(-4px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.color-picker-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    padding: 0;
}
.color-picker-dot:hover {
    transform: scale(1.15);
    box-shadow: 0 0 8px rgba(255,255,255,0.2);
}
.color-picker-dot.active {
    border-color: var(--text-color);
    box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 4px var(--text-color);
}
.color-picker-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.color-picker-reset {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.color-picker-reset:hover {
    color: var(--danger-color);
}
.color-picker-custom input[type="color"] {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

/* Footer */
.app-footer {
    margin-top: 12px;
    padding: 6px 0;
    text-align: center;
}

.footer-content {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.footer-content p {
    margin: 0;
}


.footer-content strong {
    color: var(--text-color);
}

.footer-content a {
    color: var(--primary-text-color);
    text-decoration: none;
    transition: opacity 0.2s;
}

.footer-content a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Command Palette */
#command-palette {
    position: fixed;
    inset: 0;
    z-index: var(--z-command-palette);
    display: flex;
    justify-content: center;
    padding-top: 15vh;
}

.cp-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.15s ease-out;
}

.cp-dialog {
    position: relative;
    width: 520px;
    max-width: 90vw;
    max-height: 60vh;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 16px 48px var(--shadow-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-self: flex-start;
    animation: cpSlideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cpSlideDown {
    from { opacity: 0; transform: translateY(-12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.cp-input {
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
    box-sizing: border-box;
}

.cp-input::placeholder {
    color: var(--text-secondary);
}

.cp-results {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.cp-group-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 8px 16px 4px;
}

.cp-result {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.1s;
    position: relative;
    z-index: 1;
}

.cp-result:hover {
    background: var(--bg-secondary);
}

.cp-result.cp-active {
    background: var(--primary-color);
    color: var(--primary-contrast);
}

.cp-result.cp-active .cp-detail {
    color: var(--primary-contrast);
    opacity: 0.7;
}

.cp-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    font-size: 0.9rem;
}

.cp-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.cp-detail {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.cp-running {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    flex-shrink: 0;
    box-shadow: 0 0 4px var(--primary-color);
}

.cp-action-item .cp-icon {
    opacity: 0.85;
}

.cp-action-item .cp-detail {
    font-weight: 600;
    color: var(--primary-color);
}

.cp-action-item.cp-active .cp-detail {
    color: var(--primary-contrast);
    opacity: 0.9;
}

.cp-loading,
.cp-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.cp-footer {
    padding: 6px 16px;
    border-top: 1px solid var(--border-color);
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
}

@media (max-width: 900px) {
    header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .container {
        padding: 12px;
    }
}

@media (max-width: 600px) {
    .tab-bar {
        flex-wrap: wrap;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
}
