/* Variables */
:root {
    --bg-color: #efefef;
    --text-color: #777777;
    --disabled-text-color: #cccccc;
    --active-section-bg: white;
    --separator-color: #cccccc;
    --button-bg: #dddddd;
    --button-text: #333333;
    --button-highlight: #f0f0f0;
    --info-bg: #d0d0d0;
    --tesla-blue: #0077ff;
    --tesla-red: #ff0000;
    --button-radius: 13px;
    --weather-switch-slider: #ffffff;
    --weather-warning-color: #ff7700;
    --status-poor: #E65100;
    --status-good: #0fa215;
    --status-unavailable: #888888;
    --status-rain: #00a1ff;
    --heading-font-size: 17pt;
    --heading-font-weight: 500;
    --stock-up: #0fa215;
    --stock-down: #dc3545;
    --stock-neutral: #888888;
    --notification-bg: rgba(255, 255, 255, 0.9);
    --notification-success-bg: rgba(255, 255, 255, 0.9);
    --notification-error-bg: rgba(255, 255, 255, 0.9);
    --notification-info-bg: rgba(255, 255, 255, 0.9);
    --notification-text: #333333;
    --notification-text-alt: #333333;
    --indicator-container-bg: rgba(239, 239, 239, 0.8);
}

body.dark-mode {
    --bg-color: #1d1d1d;
    --disabled-text-color: #444444;
    --active-section-bg: #333333;
    --separator-color: #444444;
    --button-bg: #333333;
    --button-text: #d6d6d6;
    --button-highlight: #bdbdbd;
    --info-bg: #302f39;
    --weather-switch-slider: #222222;
    --weather-warning-color: #ff9900;
    --status-poor: #ffcd27;
    --status-good: #5eff19;
    --status-unavailable: #888888;
    --status-rain: #4fb8ff;
    --stock-up: #3ad45b;
    --stock-down: #ff4d5e;
    --stock-neutral: #888888;
    --notification-bg: rgba(70, 70, 70, 0.9);
    --notification-success-bg: rgba(70, 70, 70, 0.9);
    --notification-error-bg: rgba(70, 70, 70, 0.9);
    --notification-info-bg: rgba(70, 70, 70, 0.9);
    --notification-text: #ffffff;
    --notification-text-alt: #ffffff;
    --indicator-container-bg: rgba(29, 29, 29, 0.8);
}

/* Basic HTML Elements */
* {
    font-family: "Inter";
    font-optical-sizing: auto;
    font-variant-ligatures: all;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16pt;
    padding: 0;
    text-align: left;
}

a {
    color: var(--tesla-blue);
    text-decoration: none;
    font-weight: 500;
}

h1 {
    color: var(--button-text);
    font-size: 19pt;
    margin: 0 0 15px 0;
    font-weight: 250;
}

h2 {
    color: var(--button-text);
    font-size: var(--heading-font-size);
    margin: 28px 0 9px 0;
    font-weight: var(--heading-font-weight);
}

h3 {
    color: var(--button-text);
    font-size: calc(var(--heading-font-size) - 1pt);
    font-weight: calc(var(--heading-font-weight) - 100);
    margin: 16px 0 7px 0;
}

p {
    margin: 12px 0;
    text-align: justify;
    max-width: 980px;
}

ul {
    padding-left: 25px;
    margin: 0;
    text-align: justify;
    max-width: 940px;
}

li {
    margin: 11px 0;
}

hr {
    border: 0;
    border-top: 1px solid var(--separator-color);
    margin: 28px 0;
}

/* Layout */
.frame-container {
    display: flex;
    height: 100vh;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
}

.left-frame {
    width: 300px;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 10px 10px 5px 15px;
    box-sizing: border-box;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    position: relative;
    z-index: 0;
}

.right-frame {
    flex-grow: 1;
    height: 100%;
    overflow-y: auto;
    padding: 20px 45px 20px 15px;
    box-sizing: border-box;
    scrollbar-width: thin;
    position: relative;
    z-index: 1;
}

/* Scroll indicators */
.scroll-indicator {
    position: fixed;
    left: 300px;
    right: 10px;
    height: 64px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.top-fade {
    top: 0;
    background: linear-gradient(to bottom, var(--bg-color), transparent);
}

.bottom-fade {
    bottom: 0;
    background: linear-gradient(to top, var(--bg-color), transparent);
}

/* Scroll-to-top arrow for mobile */
.scroll-to-top {
    display: none;
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    z-index: 1000;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

@media only screen and (min-width: 901px) {
    .scroll-to-top {
        display: none !important;
    }
}

.section {
    display: none;
}

.hidden {
    display: none !important;
}

/* External site container */
#external-site {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

#external-site iframe {
    width: 100%;
    height: 100%;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    padding: 0;
    margin: 0;
}

/* Navigation */
.section-buttons {
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    box-sizing: border-box;
}

.section-button {
    color: var(--text-color);
    border-radius: var(--button-radius);
    font-weight: 600;
    background-color: var(--bg-color);
    font-size: 19pt;
    padding: 13px 20px;
    border: none;
    cursor: pointer;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    transition: background-color 0.3s, color 0.3s;
}

.section-button.disabled {
    color: var(--disabled-text-color) !important;
    cursor: not-allowed;
}

.section-button.disabled:hover {
    background-color: var(--bg-color);
}

.logout-button {
    color: var(--button-text);
    background-color: var(--button-bg);
    border-radius: var(--button-radius);
    font-size: 16pt;
    font-weight: 600;
    padding: 16px 20px;
    border: none;
    cursor: pointer;
    text-align: center;
    margin-top: 15px;
    transition: background-color 0.3s;
}

.logout-button:hover {
    background-color: var(--active-section-bg);
}

.button-icon {
    width: 24px;
    height: 24px;
    margin-right: 14px;
    stroke: currentColor;
    fill: none;
}

.section-button.active,
.section-button:hover {
    background-color: var(--active-section-bg);
    color: var(--button-text);
}

/* Notification dot */
.section-button.has-notification {
    position: relative;
}

.section-button.has-notification::after {
    content: attr(data-count);
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    min-width: 20px;
    height: 26px;
    background-color: var(--tesla-blue);
    border-radius: 13px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 12pt;
    font-weight: 750;
    padding: 0 9px;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.section-button.notification-transition::after {
    opacity: 0;
}

/* Weather alert count indicator */
.section-button.has-weather-alert {
    position: relative;
}

.section-button.has-weather-alert::after {
    content: attr(data-alert-count);
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    min-width: 20px;
    height: 26px;
    background-color: #8B0000;
    border-radius: 13px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 12pt;
    font-weight: 750;
    padding: 0 9px;
    opacity: 1;
    transition: opacity 0.5s ease;
}

/* Link Button Lists */
.button-list {
    /* works for <ul> or <div> container */
    list-style: none;
    padding: 0;
    margin-top: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, 280px);
    gap: 15px;
    justify-content: start;
    max-width: calc(280px * 5 + 16px * 4);
}

.button-list > * {
    /* reset margin for direct children (anchors or item wrappers) */
    margin: 0;
}

.button-list a {
    color: var(--button-text);
    background-color: var(--button-bg);
    border-radius: var(--button-radius);
    display: flex;
    padding: 23px 5px;
    font-weight: 600;
    align-items: center;
    justify-content: center;
    gap: 11px;
}

.button-list a img {
    height: 36px;
    width: auto;
    border-radius: 7px;
}

/* Enhanced Image Visibility Classes */
.img-adaptive,
.img-adaptive-light-invert,
.img-adaptive-dark-invert {
    filter: grayscale(100%) contrast(1.5);
    transition: filter 0.3s;
}

body:not(.dark-mode) .img-adaptive,
body:not(.dark-mode) .img-adaptive-light-invert {
    filter: invert(100%);
}

body.dark-mode .img-adaptive-dark-invert {
    filter: invert(100%);
}

.img-white-transparent {
    mix-blend-mode: multiply;
    transition: filter 0.3s;
}

body.dark-mode .img-white-transparent {
    mix-blend-mode: screen;
    filter: invert(100%) brightness(125%);
}

/* Indicator container */
.control-container {
    position: fixed;
    top: -3px;
    right: 11px;
    display: flex;
    align-items: center;
    background-color: var(--indicator-container-bg);
    border-radius: 5px;
    padding: 8px 2px;
    z-index: 100;
    transition: transform 0.2s ease-out;
    transform-origin: right center;
    will-change: transform;
}

body.forecast-popup-active .control-container {
    z-index: 0;
}

.status-indicator {
    height: 24px;
    margin-right: 11px;
    margin-left: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

/* Network Status Indicator */
.network-icon {
    height: 16px;
    filter: invert(0%);
    transition: filter 0.3s ease;
}

/* Dark mode: white icon */
body.dark-mode .network-icon {
    filter: invert(70%);
}

.network-status .network-bar {
    transition: fill 0.3s ease;
}

.network-status.unavailable .network-bar {
    fill: var(--status-unavailable);
}

.network-status.poor .bar-1 {
    fill: var(--status-poor);
}

.network-status.poor .bar-2,
.network-status.poor .bar-3,
.network-status.poor .bar-4 {
    fill: var(--status-unavailable);
}

.network-status.fair .bar-1,
.network-status.fair .bar-2 {
    fill: var(--status-poor);
}

.network-status.fair .bar-3,
.network-status.fair .bar-4 {
    fill: var(--status-unavailable);
}

.network-status.good .bar-1,
.network-status.good .bar-2,
.network-status.good .bar-3 {
    fill: var(--status-good);
}

.network-status.good .bar-4 {
    fill: var(--status-unavailable);
}

.network-status.excellent .bar-1,
.network-status.excellent .bar-2,
.network-status.excellent .bar-3,
.network-status.excellent .bar-4 {
    fill: var(--status-good);
}

/* GPS Status Indicator */
.gps-status.unavailable {
    color: var(--status-unavailable);
}

.gps-status.poor {
    color: var(--status-poor);
}

.gps-status.good {
    color: var(--status-good);
}

.gps-status {
    color: var(--status-unavailable);
}

/* Rain Status Indicator */
.rain-status {
    color: var(--weather-warning-color);
    animation: pulse-rain 2s infinite;
    display: flex;
    align-items: center;
    gap: 3px;
}

.rain-status #rain-timing-text {
    color: var(--weather-warning-color);
    font-size: 11pt;
    font-weight: 800;
    white-space: nowrap;
}

@keyframes pulse-rain {
    0% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.7;
    }
}

/* Stock Status Indicator */
.stock-status {
    width: auto;
    font-size: 11pt;
    font-weight: 600;
    transition: color 0.3s ease;
    font-variant-numeric: tabular-nums;
}

.stock-status.up {
    color: var(--status-good);
}

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

.stock-status.neutral {
    color: var(--stock-neutral);
}

/* Stock ticker container */
#stock-indicators {
    margin: 0 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#stock-indicators .stock-ticker-track {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0;
    position: relative;
    z-index: 0;
}

#stock-indicators.ticker-mode {
    overflow: hidden;
    width: var(--ticker-window-width, 520px);
    max-width: 100%;
}

#stock-indicators.ticker-mode .stock-ticker-track {
    animation: ticker-scroll var(--ticker-animation-duration, 18s) linear infinite;
    gap: 11px;
}

#stock-indicators.ticker-mode .stock-status {
    white-space: nowrap;
    margin: 0;
}

#stock-indicators.ticker-mode::before,
#stock-indicators.ticker-mode::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 12px;
    pointer-events: none;
    z-index: 1;
}

#stock-indicators.ticker-mode::before {
    left: -1px;
    background: linear-gradient(to right, var(--indicator-container-bg) 0%, transparent 100%);
}

#stock-indicators.ticker-mode::after {
    right: -1px;
    background: linear-gradient(to left, var(--indicator-container-bg) 0%, transparent 100%);
}

@keyframes ticker-scroll {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(var(--ticker-scroll-distance, -50%));
    }
}

/* Simple Text Data Display */
.data-info, .data-info-column {
    row-gap: 18px;
    width: auto;
}

.data-info {
    display: grid;
    grid-template-columns: repeat(auto-fill, 240px);
    column-gap: 28px;
}

.data-info-column {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
}

.data-info-column .data-item {
    margin-right: 0;
    width: auto;
}

.data-item {
    color: var(--button-text);
    font-weight: 600;
    font-size: var(--heading-font-size);
    display: block;
    margin-right: 0;
    padding-top: 0px;
}

.data-item:last-child {
    margin-bottom: 0;
}

.data-item h2 {
    color: var(--text-color);
    margin-top: 0px;
    margin-bottom: 4px;
}

/* Dashboard Nav Stats */
.nav-container {
    display: flex;
    gap: 15px;
    margin: 30px 0px -25px 0px;
    align-items: flex-start;
}

.nav-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: 10px 0;
    width: 420px;
}

/* When extra detail is on, use 3x2 layout */
.nav-stats.extra-detail {
    grid-template-columns: repeat(3, 1fr);
    width: 720px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    height: 120px;
}

.value-container {
    display: flex;
    align-items: baseline;
}

.stat-value {
    color: var(--button-text);
    font-size: 48pt;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stat-arrow {
    color: var(--button-text);
    font-size: 18pt;
    font-weight: 800;
    line-height: 1.2;
}

.stat-arrow-unit {
    display: inline-flex;
    flex-direction: column;
    align-self: flex-end;
    margin-left: 3px;
    margin-bottom: 9px;
}

.stat-arrow-unit .stat-unit {
    margin-left: 0;
}

.stat-unit {
    font-size: 17pt;
    font-weight: 700;
    margin-left: 3px;
}

.stat-label {
    color: var(--text-color);
    font-size: 13pt;
    font-weight: 500;
    margin-top: -3px;
    display: block;
}

/* Dashboard Display */
.radar-container {
    position: relative;
    padding-top: 30px;
    margin-right: 30px;
}

.radar-title {
    position: absolute;
    top: 0px;
    left: 24px;
    text-align: center;
    margin: 0;
}

#radarDisplay {
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.1);
}

.dark-mode #radarDisplay {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Waze frame */
.teslawaze-container {
    height: calc(100vh - 370px);
    min-height: 280px;
    margin-bottom: 0;
    position: relative;
}

#teslawaze {
    border-radius: var(--button-radius);
    width: 100%;
    height: 100%;
    border: none;
}

/* Modal Login Dialog */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    justify-content: center;
    align-items: center;
}

.modal-content {
    font-size: 14pt;
    background-color: var(--bg-color);
    border-radius: var(--button-radius);
    padding: 25px;
    padding-top: 0px;
    max-width: 90%;
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.75);
}

/* Login form */
.login-form {
    margin-top: 20px;
}

.login-form label {
    font-weight: 500;
    font-size: 14pt;
    width: 80px;
    margin-right: 15px;
    margin-bottom: 10px;
    color: var(--button-text);
    vertical-align: middle;
}

.login-form input {
    font-size: 16px;
    width: calc(100% - 90px);
    padding: 12px 15px;
    border: 2px solid var(--separator-color);
    border-radius: 8px;
    background-color: var(--active-section-bg);
    color: var(--button-text);
    box-sizing: border-box;
    vertical-align: middle;
}

.button-container {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-button {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s;
}

.modal-button.cancel {
    background-color: var(--button-bg);
    color: var(--button-text);
}

.modal-button.submit {
    background-color: var(--tesla-blue);
    color: white;
}

.error-message {
    color: var(--tesla-red);
    margin-bottom: 20px;
    font-size: 14px;
    min-height: 20px;
}

/* Option Switch (Two-option selector) */
.option-switch-container {
    padding-right: 15px;
    padding-top: 11px;
    padding-bottom: 11px;
    cursor: initial;
}

.option-switch {
    display: flex;
    border-radius: calc(var(--button-radius) - 2px);
    overflow: hidden;
    background-color: var(--button-highlight);
}

.option-button {
    flex: 1;
    background: none;
    border: none;
    padding: 8px 14px;
    color: var(--text-color);
    font-size: 14pt;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
}

.option-button.active {
    background-color: var(--tesla-blue);
    color: white;
}

.option-button:hover:not(.active) {
    background-color: rgba(0, 0, 0, 0.05);
}

body.dark-mode .option-button:hover:not(.active) {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Satellite region selector */
.satellite-region-selector .region-switch {
    display: grid;
    grid-template-columns: repeat(var(--region-columns, 3), minmax(0, 1fr));
    gap: 3px;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
}

.satellite-region-selector .option-button {
    min-width: 64px;
    width: 100%;
    text-transform: uppercase;
    font-size: 12pt;
}

/* Disable region selector when using location mode */
.satellite-region-selector.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Mobile Landscape Mode */
@media only screen and (max-width: 900px) {
    :root {
        --heading-font-size: 14pt;
        --heading-font-weight: 500;
        --button-radius: 9px;
    }
    
    body {
        font-size: 12pt;
    }

    p {
        text-align: left;
    }

    ul {
        padding-left: 20px;
        text-align: left;
    }

    .logout-button {
        border-radius: var(--button-radius);
        font-size: 12pt;
        font-weight: 600;
        padding: 7px 20px;
        border: none;
        cursor: pointer;
        text-align: center;
        margin-top: 3px;
        margin-bottom: 6px;
        transition: background-color 0.3s;
    }
    
    /* Hide control div */
    .control-container {
        display: none;
    }
    
    /* Layout adjustment */
    .frame-container {
        flex-direction: column;
        position: static;
        height: auto;
        overflow: visible;
    }

    /* Adjust scroll indicator placement */
    .scroll-indicator {
        left: 0;
        right: 0;
    }
    
    /* Convert left menu to horizontal top menu */
    .left-frame {
        width: 100%;
        height: auto;
        max-height: none;
        padding: 3px;
        overflow: visible;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        position: sticky;
        top: 0;
        z-index: 100;
        background-color: var(--bg-color);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    
    .left-frame::-webkit-scrollbar {
        display: none;
    }
    
    /* Convert section buttons to horizontal layout */
    .section-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        overflow: visible;
    }
    
    .section-buttons h1 {
        display: none;
    }
    
    .section-button {
        font-size: 13pt;
        padding: 0px 9px;
        white-space: nowrap;
        height: 32px;
    }

    .section-button.has-notification {
        padding-right: 42px !important;
    }

    .section-button.has-notification::after {
        right: 6px;
        min-width: 12px;
        height: 18px;
        border-radius: 9px;
        font-size: 8pt;
        padding: 0 5px;
    }

    .button-icon {
        width: 16px;
        height: 16px;
        margin-right: 7px;
    }
    
    /* Right frame takes remaining space */
    .right-frame {
        height: auto;
        padding: 1px 3px;
        overflow: visible;
    }
    
    /* Dashboard adjustments */
    .nav-container {
        gap: 20px;
        margin: 10px 0px -15px 0px;
        flex-direction: column;
        align-items: stretch;
    }

    .nav-stats {
        width: 100%;
    }

    /* Ensure extra-detail layout also takes full width on mobile */
    .nav-stats.extra-detail {
        width: 100%;
    }

    .data-info-column {
        width: 100%;
    }

    .data-info-column .data-item span {
        display: block;
        word-break: break-word;
    }

    .radar-container {
        padding-top: 20px;
        margin-right: 0;
    }
    
    #radarDisplay {
        width: 150px;
        height: 150px;
    }
    
    .stat-box {
        height: 90px;
    }
    
    .stat-value {
        font-size: 36pt;
    }
    
    .stat-unit {
        font-size: 18pt;
    }
    
    .stat-arrow {
        font-size: 28pt;
    }
    
    .stat-label {
        font-size: 12pt;
    }
    
    /* Teslawaze container adjustment */
    .teslawaze-container {
        height: calc(100vh - 300px);
        min-height: 200px;
    }
    
    /* Button lists */
    .button-list {
        grid-template-columns: repeat(auto-fill, 220px);
        gap: 10px;
    }
    
    .button-list a {
        padding: 15px 5px;
        height: 30px;
        font-size: 12pt;
    }
    
    /* Option Switch adjustments for mobile */
    .option-button {
        font-size: 9pt;
        padding: 5px 8px;
    }

    .option-switch-container {
        padding: 6px 8px;
    }

    /* Settings section headers */
    h2 {
        font-size: 12pt;
        margin-top: 18px;
        margin-bottom: 3px;
    }

    h3 {
        font-size: 11pt;
        margin-top: 7px;
        margin-bottom: 7px;
    }

    /* Satellite region selector mobile adjustments */
    .satellite-region-selector .region-switch {
        max-width: 80%;
    }

    .satellite-region-selector .option-button {
        font-size: 8pt;
        min-width: 26px;
        padding: 4px 2px;
    }

    /* Fix external site iframe positioning in mobile mode */
    #external-site {
        position: fixed;
        top: 120px; /* Space for horizontal section menu */
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
    }

    #external-site iframe {
        width: 100%;
        height: 100%;
    }
}
