/* ============================================================
   Tesla Launchpad Dashboard - Premium In-Car Touchscreen CSS
   Optimized for Tesla Chromium Browser (Model 3, Y, S, X, Cybertruck)
   ============================================================ */

:root {
    --bg-main: #090a0f;
    --bg-card: rgba(18, 21, 29, 0.72);
    --bg-card-hover: rgba(28, 32, 45, 0.88);
    --bg-card-active: rgba(38, 44, 62, 0.95);
    --border-card: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.22);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --tesla-red: #e82127;
    --tesla-red-glow: rgba(232, 33, 39, 0.35);
    --accent: #e82127;
    --accent-glow: rgba(232, 33, 39, 0.3);
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
    --radius-card: 0px;
    --radius-tile: 0px;
    --radius-pill: 0px;
    --radius-btn: 0px;
    --radius-input: 0px;
    --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Theme: OLED Deep Black */
[data-theme="oled-black"] {
    --bg-main: #000000;
    --bg-card: rgba(12, 12, 14, 0.85);
    --bg-card-hover: rgba(22, 22, 26, 0.95);
    --border-card: rgba(255, 255, 255, 0.09);
    --border-hover: rgba(255, 255, 255, 0.3);
}

/* Theme: Cyber Neon */
[data-theme="cyber-neon"] {
    --bg-main: #060913;
    --accent: #00f0ff;
    --accent-glow: rgba(0, 240, 255, 0.4);
    --border-card: rgba(0, 240, 255, 0.12);
    --border-hover: rgba(0, 240, 255, 0.45);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html, body {
    width: 100%;
    min-height: 100vh;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-stack);
    overflow-x: hidden;
    touch-action: manipulation;
}

body {
    background-image: 
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(232, 33, 39, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 90% 100%, rgba(30, 58, 138, 0.08), transparent);
    background-attachment: fixed;
    display: flex;
    flex-direction: column;
    padding-top: 46px; /* Offset for fixed top status bar */
}

/* Fullscreen Car Container */
.tesla-viewport {
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 32px 48px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    flex: 1;
}

/* ============================================================
   Top Tesla Bar: Clock, Brand, Controls (Full-Width Edge-to-Edge Fixed)
   ============================================================ */
.tesla-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 24px;
    min-height: 46px;
    height: 46px;
    box-sizing: border-box;
    background: rgba(14, 16, 21, 0.94);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid var(--border-card);
    border-radius: 0px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.65);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    flex-shrink: 0;
}

.brand-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 0px;
    background: linear-gradient(135deg, rgba(232, 33, 39, 0.2), rgba(232, 33, 39, 0.05));
    border: 1px solid rgba(232, 33, 39, 0.35);
    color: #ffffff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.brand-logo-wrap svg {
    width: 18px;
    height: 18px;
    fill: #ffffff;
}

.brand-text h1 {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    line-height: 1;
}

.brand-text .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 0px;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    display: inline-block;
}

.brand-text p {
    display: none;
}

/* Digital Clock & Weather in Center (Inline Sleek Ribbon) */
.clock-display {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-shrink: 0;
}

.clock-time {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 16px rgba(255, 255, 255, 0.2);
    line-height: 1;
}

.clock-date {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.4px;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.clock-date::before {
    content: "•";
    color: var(--text-muted);
    font-size: 11px;
}

/* Header Action Buttons */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 0px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.btn-icon:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.18);
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

/* ============================================================
   Search & Filter Navigation
   ============================================================ */
.filter-search-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================
   Spotlight Search Modal (Cyberpunk / Tesla Minimalist)
   ============================================================ */
#search-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 999999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(40px, 12vh, 120px) 20px 20px 20px;
    animation: tessieModalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#search-modal[style*="display: none"] {
    display: none !important;
}

.search-modal-card {
    background: #0f1218;
    background: linear-gradient(180deg, #161b24 0%, #0d1017 100%);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 0px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.95), 0 0 0 1px rgba(232, 33, 39, 0.35);
    width: 100%;
    max-width: 680px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    animation: tessieModalScaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-modal-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #e82127, #ff4d4d, #e82127);
    z-index: 10;
}

.search-modal-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    position: relative;
}

.search-modal-input-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.search-modal-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: #e82127;
    pointer-events: none;
}

.search-modal-input {
    width: 100%;
    padding: 18px 48px 18px 54px;
    background: transparent;
    border: none;
    border-radius: 0px;
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 500;
    font-family: inherit;
    outline: none;
    user-select: text;
}

.search-modal-input::placeholder {
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 400;
}

.search-clear-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-secondary);
    border-radius: 0px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    transition: var(--transition);
}

.search-clear-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.search-clear-btn.visible {
    display: flex;
}

.search-modal-close {
    width: 52px;
    height: 56px;
    background: transparent;
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.search-modal-close:hover {
    background: rgba(232, 33, 39, 0.15);
    color: #fff;
}

.search-modal-results {
    overflow-y: auto;
    max-height: calc(80vh - 65px);
    display: flex;
    flex-direction: column;
}

.search-modal-hints {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.search-modal-badge {
    padding: 2px 7px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0px;
    font-size: 11px;
    color: var(--text-secondary);
    font-family: monospace;
}

.search-results-list {
    display: flex;
    flex-direction: column;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    text-decoration: none;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    border-left: 3px solid transparent;
    transition: background 0.12s ease, border-color 0.12s ease;
    cursor: pointer;
}

.search-result-item:hover,
.search-result-item.selected {
    background: rgba(255, 255, 255, 0.06);
    border-left-color: #e82127;
}

.search-result-icon {
    width: 36px;
    height: 36px;
    border-radius: 0px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.search-result-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.search-result-icon svg {
    width: 20px;
    height: 20px;
}

.search-result-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.search-result-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-title mark,
.search-result-desc mark {
    background: rgba(232, 33, 39, 0.35);
    color: #fff;
    padding: 0 2px;
    border-radius: 0px;
}

.search-result-star {
    color: #f59e0b;
    font-size: 12px;
}

.search-result-desc {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.search-result-cat {
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 2px 7px;
    border-radius: 0px;
}

.search-result-arrow {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    opacity: 0.5;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.search-result-item:hover .search-result-arrow,
.search-result-item.selected .search-result-arrow {
    opacity: 1;
    color: #e82127;
    transform: translateX(2px);
}

.search-result-badge-kbd {
    font-size: 11px;
    font-family: monospace;
    padding: 2px 7px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text-secondary);
}

.search-modal-no-results {
    padding: 32px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
}

.search-modal-no-results strong {
    color: #fff;
}

/* Category Filter Tabs */
.category-tabs {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    padding: 12px 22px;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-card);
    border-radius: 0px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tab-btn:hover {
    color: #ffffff;
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.tab-btn.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.tab-btn:active {
    transform: scale(0.95);
}

.tab-count {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 0px;
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   Touch-Friendly App Grid
   ============================================================ */
.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

/* Individual App Card / Launchpad Tile */
.app-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-card);
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    min-height: 180px;
}

.app-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--tile-color, var(--accent));
    opacity: 0.7;
    transition: var(--transition);
}

.app-tile:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-5px);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 0 25px rgba(255, 255, 255, 0.05);
}

.app-tile:hover::before {
    height: 4px;
    opacity: 1;
    box-shadow: 0 0 12px var(--tile-color, var(--accent));
}

.app-tile:active {
    transform: scale(0.94);
    background: var(--bg-card-active);
}

/* Icon Box inside Tile */
.tile-icon-wrapper {
    width: 72px;
    height: 72px;
    border-radius: 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.09);
    position: relative;
    transition: var(--transition);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.app-tile:hover .tile-icon-wrapper {
    transform: scale(1.08);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4), 0 0 18px var(--tile-glow, rgba(255, 255, 255, 0.15));
}

.tile-icon-svg {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tile-color, #ffffff);
}

.tile-icon-svg svg {
    width: 100%;
    height: 100%;
}

.tile-icon-img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 0px;
}

/* App Title & Subtitle */
.tile-title {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    text-align: center;
    margin-bottom: 4px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.tile-desc {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 32px;
}

/* Favorite Pin Badge */
.tile-star {
    position: absolute;
    top: 10px;
    right: 12px;
    color: #f59e0b;
    opacity: 0.85;
    font-size: 13px;
}

.tile-category-tag {
    position: absolute;
    top: 10px;
    left: 12px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 0px;
}

/* Empty State / No Results */
.no-results-box {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border: 1px dashed var(--border-card);
    border-radius: var(--radius-card);
    display: none;
}

.no-results-box.active {
    display: block;
}

.no-results-box h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.no-results-box p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================
   Bottom Tesla Bar (Full-Width Edge-to-Edge)
   ============================================================ */
.tesla-footer {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 32px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-card);
    border-bottom: none;
    border-left: none;
    border-right: none;
    border-radius: 0px;
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: auto;
}

.footer-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 0px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-card);
    font-size: 12px;
}

.badge-pill svg {
    width: 14px;
    height: 14px;
}

/* ============================================================
   Dual Row Widget Layout (Victron Solar & Weather Side-by-Side)
   ============================================================ */
.widgets-dual-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 28px;
    width: 100%;
    align-items: stretch;
}

.widgets-dual-row > *:only-child {
    grid-column: 1 / -1;
}

.widgets-dual-row .vrm-card,
.widgets-dual-row .weather-card {
    height: 100%;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

.widgets-dual-row .vrm-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.widgets-dual-row .vrm-node {
    padding: 14px 10px;
    min-height: 110px;
}

.widgets-dual-row .vrm-power-huge {
    font-size: 24px;
}

.widgets-dual-row .vrm-node-sub {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widgets-dual-row .weather-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr 1.35fr;
    gap: 12px;
}

.widgets-dual-row .weather-box {
    padding: 14px 12px;
    min-height: 110px;
}

.widgets-dual-row .weather-temp-huge {
    font-size: 32px;
}

/* Collapsed state handling */
.widgets-dual-row .vrm-card.collapsed,
.widgets-dual-row .weather-card.collapsed {
    height: auto !important;
    align-self: start;
}

/* Medium viewports (between 1101px and 1450px): VRM gracefully adapts to 2x2 */
@media (max-width: 1450px) and (min-width: 1101px) {
    .widgets-dual-row .vrm-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .widgets-dual-row .vrm-power-huge {
        font-size: 26px;
    }
}

/* Tablet & Mobile below 1100px: Stack into 1 column */
@media (max-width: 1100px) {
    .widgets-dual-row {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .widgets-dual-row .vrm-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 16px;
    }

    .widgets-dual-row .vrm-power-huge {
        font-size: 32px;
    }

    .widgets-dual-row .weather-grid {
        grid-template-columns: 1.2fr 1fr 1.6fr;
        gap: 16px;
    }
}

/* ============================================================
   Tesla Responsive Touch Breakpoints
   ============================================================ */
@media (max-width: 1024px) {
    .tesla-viewport {
        padding: 16px;
        gap: 20px;
    }
    
    .apps-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 14px;
    }
    
    .tile-icon-wrapper {
        width: 60px;
        height: 60px;
    }
    
    .clock-time {
        font-size: 18px;
    }
}

@media (max-width: 768px) {
    body {
        padding-top: 46px;
    }
    
    .tesla-header {
        padding: 6px 12px;
        min-height: 46px;
        height: 46px;
        gap: 6px;
        justify-content: space-between;
    }
    
    .clock-display {
        gap: 8px;
    }

    .clock-date {
        display: none;
    }
    
    .header-actions {
        gap: 6px;
    }
    
    .apps-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 12px;
    }
    
    .app-tile {
        padding: 18px 10px;
        min-height: 150px;
    }
    
    .tile-desc {
        display: none;
    }
    
    .tesla-footer {
        padding: 14px 16px;
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
}
