/* Privacy and Terms page base styles */
body.privacy-page, body.terms-page {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  padding: 2rem;
  max-width: 800px;
  margin: auto;
  background: #f9f9f9;
  color: #333;
}
body.privacy-page h1, body.privacy-page h2,
body.terms-page h1, body.terms-page h2 {
  color: #222;
}
body.privacy-page h1, body.terms-page h1 {
  margin-bottom: 0.5rem;
}
body.privacy-page hr, body.terms-page hr {
  margin: 2rem 0;
}
body.privacy-page::before, body.terms-page::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('/assets/kennix.png');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  z-index: -1;
  opacity: 0.5;
}

:root {
    --primary-color: #2196F3;
    --primary-light: rgba(33, 150, 243, 0.1);
    --secondary-color: #607D8B;
    --secondary-light: rgba(96, 125, 139, 0.1);
    --background-color: #f8f9fa;
    --card-background: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #607d8b;
    --border-radius: 8px;
    --box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    max-width: none;
    margin: 0 auto;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    position: relative;
}

.clerk-error-message {
    color: red;
    padding: 20px;
    text-align: center;
}

.error {
    color: #f44336;
    margin: 10px 0;
    padding: 10px;
    background-color: #ffebee;
    border-radius: var(--border-radius);
}

#chartContainer {
    margin: 20px 0;
    height: 440px;
    position: relative;
    width: 100%;
    max-width: none;
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 20px;
    box-sizing: border-box;
    min-height: 400px;
    will-change: contents;
    contain: layout;
}

/* Ensure chart container fits when pressure map is present */
@media (min-width: 1200px) {
    #chartContainer {
        max-width: 100%; /* Use full available width within constrained layout */
    }
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 1;
}

.chart-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 10px;
    border-radius: 4px;
    position: relative;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc;
    margin-top: 1px;
}

.status-dot.connected {
    background-color: #47d775;
}

.status-dot.disconnected {
    background-color: #f44336;
}

.status-tooltip {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.status-indicator:hover .status-tooltip {
    opacity: 1;
}

.chart-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 20px;
    gap: 20px;
}

.chart-title {
    font-size: 24px;
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
}

/* Custom dropdown container styling */
.dropdown {
    position: relative;
    width: 144px;  /* Reduced from 180px (20% reduction) */
    user-select: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Container for all main content */
.content-container {
    max-width: none;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    width: 100%;
    overflow-x: hidden;
}

.dropdown-selected {
    padding: 12px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}
.dropdown-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    max-height: 450px;
    overflow-y: auto;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 1001;
    display: none;
}
.dropdown-option {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    position: relative;
}
.dropdown-option:hover {
    background: #f0f0f0;
}
.option-text {
    flex: 1;
}
.expand-icon {
    font-size: 16px;
    margin-left: 8px;
    cursor: pointer;
    width: 40px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #607d8b;
    transition: all 0.2s ease;
    position: absolute;
    right: 0;
    top: 0;
    border-left: 1px solid #eee;
}

.expand-icon:hover {
    background-color: #f0f0f0;
}

.ba-list {
    padding-left: 20px;
    background: #f9f9f9;
    display: none;
    border-left: 1px solid #eee;
}
.ba-option {
    padding: 8px 16px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}
.ba-option:hover {
    background: #eaeaea;
}

#forecastSelector {
    margin: 20px 0;
    padding: 12px 15px;
    background: var(--card-background);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    box-shadow: var(--box-shadow);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    position: relative;
    min-height: 60px; /* Fixed minimum height to prevent page jumping when dates change */
}

.slider-label {
    min-width: 180px;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.forecast-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 200px;
}

.forecast-info:last-child {
    text-align: right;
}

.forecast-info:last-child .forecast-label,
.forecast-info:last-child .forecast-time {
    text-align: right;
}

.forecast-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
}

.forecast-time {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 500;
}

input[type="range"] {
    flex: 1;
    height: 18px; /* Adjusted height for better alignment */
    -webkit-appearance: none;
    background: linear-gradient(to bottom, 
        transparent 8px, /* Center the track */
        #e0e0e0 8px, 
        #e0e0e0 10px, 
        transparent 10px
    ); /* Show only 2px in the middle for better alignment */
    border-radius: 3px;
    outline: none;
    position: relative;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; /* Smaller */
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-top: 0px; /* Center on the track */
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: #1976D2;
}

/* Firefox support */
input[type="range"]::-moz-range-thumb {
    width: 18px; /* Smaller */
    height: 18px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    background: #1976D2;
}

/* For mobile, increase the hitting area without changing visuals */
@media (max-width: 768px) {
    input[type="range"] {
        height: 18px; /* Reduced from 24px to 18px */
        background: linear-gradient(to bottom, 
            transparent 6px, 
            #e0e0e0 6px, 
            #e0e0e0 12px, 
            transparent 12px
        ); /* Show only 6px in the middle */
        padding: 0;
        margin: 8px 0; /* Reduced from 10px to 8px */
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 22px; /* Slightly reduced from 24px but still larger than default */
        height: 22px;
        background: var(--primary-color);
        border-radius: 50%;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        /* Create a smaller visible circle inside the thumb */
        background-image: radial-gradient(
            circle,
            var(--primary-color) 9px,
            transparent 9px
        );
    }

    input[type="range"]::-moz-range-thumb {
        width: 22px;
        height: 22px;
        background: var(--primary-color);
        border-radius: 50%;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        background-image: radial-gradient(
            circle,
            var(--primary-color) 9px,
            transparent 9px
        );
    }
}

.slider-value {
    min-width: 150px;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.slider-tooltip {
    position: absolute;
    background: var(--card-background);
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    white-space: nowrap;
    transform: translateX(-50%);
    left: 180px; /* Start after the label width */
}

.slider-container:hover .slider-tooltip {
    opacity: 1;
}

#statsContainer {
    display: flex;
    gap: 30px;
    margin: 20px 0;
    width: 100%;
    box-sizing: border-box;
}

.stat-box {
    flex: 1;
    padding: 12px 15px 16px; /* Increase bottom padding */
    background: var(--card-background);
    border-radius: var(--border-radius);
    text-align: center;
    min-width: 200px;
    box-shadow: var(--box-shadow);
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
    height: 100px; /* Fixed height */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
}

.stat-sparkline {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.15;
    pointer-events: none;
    z-index: 1;
}

    .stat-content {
        position: relative;
        z-index: 2;
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 100%;
    }

/* Adjust vertical alignment for better balance */
.stat-label {
    font-size: 24px;
    color: var(--text-secondary);
    margin-top: 0;
    margin-bottom: 3px; /* Reduced from 6px */
    font-weight: 500;
    line-height: 1.1;
}

.stat-now {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
    padding: 0;
    font-weight: 400;
    opacity: 0.8;
    height: 14px; /* Fixed height to reserve space even when not displayed */
    display: block; /* Always keep in the document flow */
    line-height: 1;
    margin-bottom: 3px; /* Added small bottom margin */
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    margin-top: 0; /* Reduced from 6px */
    margin-bottom: 8px; /* Increase bottom margin */
    line-height: 1;
}

/* Unit text styling - 4px smaller than main value */
.unit-text {
    font-size: 24px;
}

.no-change {
    color: #bdbdbd;
}

.positive {
    color: #47d775;
}

.negative {
    color: #2196F3;
}

.arrow-icon {
    display: inline-block;
    width: 32px;
    height: 32px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    margin-right: 4px;
}

.arrow-up {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2347d775'%3E%3Cpath d='M14 4l-1.41 1.41L16.17 9H4v2h12.17l-3.58 3.59L14 16l6-6z'/%3E%3C/svg%3E");
    transform: rotate(-45deg);
}

.arrow-down {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232196F3'%3E%3Cpath d='M14 4l-1.41 1.41L16.17 9H4v2h12.17l-3.58 3.59L14 16l6-6z'/%3E%3C/svg%3E");
    transform: rotate(45deg);
}

h1 {
    text-align: right;
    margin: 0;
    font-size: 32px;
    color: var(--text-secondary);
    font-weight: 500;
    flex-grow: 1;
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: -20px;
    padding: 15px 10px; /* Use compact mobile padding for all screens */
    background: linear-gradient(to right, #2c3e50, #3498db);
    border-bottom: none;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px; /* Use compact mobile gap for all screens */
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo {
    height: 40px; /* Use compact mobile height for all screens */
    display: flex;
    align-items: center;
    gap: 10px; /* Use compact mobile gap for all screens */
    text-decoration: none;
}

.logo img {
    height: 100%;
    width: auto;
}

.logo-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 20px; /* Reduced from 24px */
    font-weight: 500;
    letter-spacing: 0.5px;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.15);
    line-height: 1.1;
}

@media (max-width: 768px) {
    /* Reduce logo text further on mobile */
    .logo-text {
        font-size: 18px;
    }
    
    /* Hide the original text in mobile view */
    .logo-text span {
        display: none;
    }

    /* Add the wrapped text in mobile view */
    .logo-text::after {
        content: 'Kennix';
        white-space: pre;
        display: block;
    }
}

.user-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.user-icon:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.user-icon svg {
    width: 20px;
    height: 20px;
    opacity: 0.9;
}

/* Update dropdown styling to match the new header */
.dropdown-selected {
    padding: 8px 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    font-size: 14px;
    color: #ffffff;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s;
}

.dropdown-selected:hover {
    background: rgba(255, 255, 255, 0.15);
}

.dropdown-selected::after {
    content: "▼";
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    margin-left: 8px;
}

#status {
    text-align: center;
    margin-bottom: 20px;
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Tablet styles */
@media (max-width: 960px) {
    .stat-label {
        font-size: 22px;
    }
    
    .stat-now {
        font-size: 10px;
        height: 10px;
    }
    
    .stat-value {
        font-size: 22px;
        height: 24px;
        margin-bottom: 4px;
    }
    
    /* Tablet unit text styling */
    .unit-text {
        font-size: 18px;
    }
    
    .arrow-icon {
        width: 24px;
        height: 24px;
    }
    
    .stat-box {
        padding: 8px 10px 10px;
    }
    
    /* Set chart height for all tablet widths regardless of orientation */
    #chartContainer {
        height: 400px;
    }
    
    /* Stat detail chart tablet styles */
    #statDetailChart {
        height: 250px;
        padding: 15px;
    }
    
    #statDetailChart h3 {
        font-size: 16px;
    }
}

/* Tablet landscape - override specific styles for landscape only */
@media (max-width: 960px) and (orientation: landscape) {    
    /* Make stat cards more compact in landscape */
    .stat-box {
        height: 75px;
        padding: 6px 8px 8px;
    }
}

/* Mobile styles - should override both tablet and landscape when applicable */
@media (max-width: 768px) {
    .slider-tooltip {
        display: none; /* Hide tooltip in mobile view */
    }
    
    body {
        padding: 0;
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Chart title smaller on mobile */
    .chart-title {
        font-size: 20px;
    }
    
    /* Adjust chart checkboxes for better mobile interaction */
    .chart-checkbox {
        padding: 6px 10px; /* Slightly larger touch target */
        margin-bottom: 0; /* Remove bottom margin */
        font-size: 13px; /* Slightly smaller text */
    }
    
    .chart-controls {
        bottom: 8px;
        left: 20px;
    }
    
    /* Adjust stat boxes for mobile view */
    .stat-box {
        padding: 8px 10px 10px;
        height: 90px; /* Slightly shorter on mobile */
        display: flex;
        align-items: center;
    }
    
    .stat-label {
        font-size: 16px; /* Adjusted to be between tablet (12px) and current mobile (18px) */
        margin-top: 0;
        margin-bottom: 2px; /* Even tighter on mobile */
    }
    
    .stat-now {
        height: 12px; /* Smaller height on mobile */
        margin-bottom: 2px; /* Tighter on mobile */
        font-size: 12px; /* Smaller font size */
    }
    
    .stat-value {
        font-size: 16px; /* Further reduced for mobile */
        height: 20px; /* Further reduced from tablet's 26px */
        margin-top: 0;
        margin-bottom: 4px; /* Tighter bottom margin on mobile */
        line-height: 20px; /* Match height for proper vertical centering */
    }
    
    /* Mobile unit text styling */
    .unit-text {
        font-size: 12px;
    }
    
    /* Smaller arrows */
    .arrow-icon {
        width: 20px;
        height: 20px;
        vertical-align: middle;
        display: inline-block;
        margin-right: 3px;
    }
    
    .content-container {
        padding: 10px;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Fix chart container */
    #chartContainer {
        padding: 10px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        overflow: hidden;
        height: 360px; /* Height for mobile */
        touch-action: auto; /* Allow all touch actions */
    }
    
    /* Stat detail chart mobile styles */
    #statDetailChart {
        height: 220px;
        padding: 10px 10px 30px 10px;
        margin: 10px 0;
    }
    
    #statDetailChart h3 {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    canvas {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Mobile-specific slider container improvements */
    .slider-container {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
        min-height: 80px; /* Slightly taller for mobile due to stacked layout */
    }
    
    /* Make forecast info display inline in mobile */
    .forecast-info {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        min-width: auto;
        margin-bottom: 8px;
        width: 100%;
    }
    
    /* Adjust forecast label and time for inline display */
    .forecast-label {
        font-size: 12px; /* Slightly smaller */
        margin-right: 8px;
        white-space: nowrap;
        color: var(--text-secondary);
        font-weight: 500;
    }
    
    .forecast-time {
        font-size: 12px; /* Slightly smaller */
        text-align: right;
        white-space: nowrap;
    }
    
    /* Ensure the slider takes full width and fix alignment */
    input[type="range"] {
        width: 100%;
        margin: 8px 0; /* Balanced margin */
    }
    
    /* Equal spacing around comparison and current labels */
    .forecast-info:first-child {
        margin-bottom: 6px;
        padding-top: 0;
    }
    
    .forecast-info:last-child {
        margin-top: 6px;
        padding-bottom: 0;
    }
    
    /* Adjust padding for forecast selector in mobile */
    #forecastSelector {
        padding: 12px;
        margin: 10px 0;
    }
    
    .slider-label, .slider-value {
        min-width: auto;
    }
    
    /* Keep statsContainer as a row on mobile to show all stats side-by-side */
    #statsContainer {
        gap: 10px;
        width: 100%;
        max-width: 100%;
        margin: 15px 0;
    }
    
    .stat-box {
        min-width: auto;
    }
    
    /* Add extra bottom margin in mobile view for x-axis labels */
    canvas#forecastChart {
        margin-bottom: 20px;
    }
    
    .chart-controls {
        bottom: 8px;
        left: 20px;
    }
    
    /* Ensure header stays contained */
    .header-container {
        width: 100%;
        max-width: 100%;
        padding: 15px 10px;
        box-sizing: border-box;
    }
    
    /* Fix dropdown alignment */
    .dropdown, .dropdown-selected, .dropdown-list {
        max-width: 100%;
    }
}

/* Footer Styles */
.dashboard-footer {
    position: relative;
    background-color: #ffffff;
    padding: 1rem 2rem;
    border-top: 1px solid #e0e0e0;
    z-index: 100;
    margin: 0;
    margin-top: 2rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: none;
    margin: 0 auto;
    padding: 0 20px;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 0.875rem;
    color: #666;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.footer-link {
    color: #2196F3;
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-link:hover {
    color: #1976D2;
    text-decoration: underline;
}

.footer-separator {
    color: #e0e0e0;
}

/* Remove the fixed padding from content container since footer is no longer fixed */
.content-container {
    padding-bottom: 0;
}

/* Mobile adjustments for footer */
@media (max-width: 768px) {
    .dashboard-footer {
        padding: 1rem;
        margin-top: 1rem;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
        padding: 0;
    }
    
    .footer-links {
        justify-content: center;
    }
}

/* Alarm table styles */
#alarmContainer {
    margin: 20px 0;
    padding: 20px;
    background: var(--card-background);
    border-radius: var(--border-radius);
    width: 100%;
    box-sizing: border-box;
    box-shadow: var(--box-shadow);
}

.alarm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 10px;
}

.alarm-title {
    font-size: 20px;
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
}

.alarm-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 14px;
}

.alarm-table thead tr {
    background-color: var(--primary-light);
}

/* Even column distribution */
.alarm-table th:nth-child(1) { width: 12%; } /* Time */
.alarm-table th:nth-child(2) { width: 10%; } /* Resource */
.alarm-table th:nth-child(3) { width: 8%; }  /* Area */
.alarm-table th:nth-child(4) { width: 8%; }  /* Type */
.alarm-table th:nth-child(5) { width: 12%; } /* Period */
.alarm-table th:nth-child(6) { width: 14%; } /* Change */
.alarm-table th:nth-child(7) { width: 12%; } /* % Change */
.alarm-table th:nth-child(8) { width: 12%; } /* Current */
.alarm-table th:nth-child(9) { width: 12%; } /* Action */

/* Hide Previous column in all views */
.alarm-table th:nth-child(10),
.alarm-table td:nth-child(10) {
    display: none;
}

.alarm-table th {
    color: var(--text-secondary);
    font-weight: 500;
    text-align: left;
    padding: 10px;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
}

.alarm-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Mobile-specific table styling */
@media (max-width: 768px) {
    #alarmContainer {
        padding: 10px;
        overflow-x: hidden;
        width: 100%;
        margin: 15px 0;
    }

    .alarm-table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .alarm-table {
        width: 100%; /* Use full width */
        border-collapse: collapse;
        border-spacing: 0;
        margin: 0;
        font-size: 12px;
        table-layout: auto; /* Let browser calculate optimal widths */
    }

    /* Hide specific columns in mobile view */
    .alarm-table th:nth-child(7),  /* % Change */
    .alarm-table td:nth-child(7),
    .alarm-table th:nth-child(8),  /* Current */
    .alarm-table td:nth-child(8),
    .alarm-table th:nth-child(9),  /* Action */
    .alarm-table td:nth-child(9) {
        display: none;
    }

    /* Compact everything */
    .alarm-table th, 
    .alarm-table td {
        padding: 6px 4px;
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Specific widths to eliminate gaps */
    .alarm-table th:nth-child(1), 
    .alarm-table td:nth-child(1) { /* Time */
        width: 24%; 
        max-width: 90px;
    }
    
    .alarm-table th:nth-child(2),
    .alarm-table td:nth-child(2) { /* Resource */
        width: 22%;
        max-width: 85px;
    }
    
    .alarm-table th:nth-child(3),
    .alarm-table td:nth-child(3) { /* Area */
        width: 10%;
        max-width: 45px;
    }
    
    .alarm-table th:nth-child(4),
    .alarm-table td:nth-child(4) { /* Type */
        width: 20%;
        max-width: 70px;
        text-align: center;
    }
    
    .alarm-table th:nth-child(5),
    .alarm-table td:nth-child(5) { /* Period */
        width: 24%;
        max-width: 90px;
        text-align: center;
    }
}

.alarm-unacked {
    font-weight: 600;
    background-color: rgba(33, 150, 243, 0.1) !important;
}

.alarm-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.alarm-badge.low {
    background-color: #2196F3;
    color: white;
}

.alarm-badge.avg {
    background-color: #FF9800;
    color: white;
}

.alarm-badge.peak {
    background-color: #F44336;
    color: white;
}

.alarm-badge.tomorrow {
    background-color: rgba(33, 150, 243, 0.2);
    color: var(--text-primary);
}

.alarm-badge.sevendays {
    background-color: rgba(244, 67, 54, 0.2);
    color: var(--text-primary);
}

.alarm-ack-btn {
    padding: 4px 8px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.alarm-ack-btn:hover {
    background-color: #1976D2;
}

.alarm-ack-btn:disabled {
    background-color: #ccc;
    cursor: default;
}

.change-value {
    display: flex;
    align-items: center;
    gap: 5px;
}

.change-up {
    color: #47d775;
}

.change-down {
    color: #2196F3;
}

.alarm-arrow-icon {
    font-size: 16px;
}

@media (max-width: 768px) {
    .alarm-badge {
        padding: 2px 4px;
        font-size: 10px;
    }
}

/* Pressure Map Styles */
.main-layout {
    position: relative;
    width: 100%;
    max-width: none;
    margin: 0 auto;
    padding: 20px; /* Consistent padding on all sides */
}

.right-panel {
    position: fixed;
    top: 90px; /* Adjusted for compact header (70px) + main layout top padding (20px) */
    left: 15px; /* Match the 15px vertical spacing */
    width: 400px;
    z-index: 100;
}

#pressureMapContainer {
    width: 100%;
    height: 600px;
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 20px;
    box-sizing: border-box;
}

#pressureMapContainer h3 {
    margin: 0 0 15px 0;
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 500;
}

/* Ensure alarms container is visible */
#alarmContainer {
    margin-top: 20px;
}

/* Hub styles */
.hub {
    cursor: pointer;
    transition: all 0.2s ease;
}

.hub:hover {
    stroke-width: 3;
    opacity: 1;
}

.hub-label {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 12px;
    font-weight: 600;
    text-anchor: middle;
    dominant-baseline: central;
    fill: var(--text-primary);
    pointer-events: none;
}

.hub-value {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 10px;
    text-anchor: middle;
    dominant-baseline: central;
    fill: var(--text-secondary);
    pointer-events: none;
}

/* Stat card selection styles */
.stat-box {
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.stat-box.selected {
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 10px rgba(74, 144, 226, 0.3);
    transform: translateY(-2px);
}

.stat-box:hover {
    transform: translateY(-1px);
    box-shadow: var(--box-shadow), 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Responsive design for smaller screens */
@media (max-width: 1200px) {
    .main-layout {
        margin-left: 0; /* Remove left margin on smaller screens */
        padding: 20px 20px 0 20px; /* Maintain top padding */
        display: flex; /* Enable flexbox for reordering */
        flex-direction: column; /* Stack elements vertically */
        gap: 15px; /* Use flex gap for consistent spacing between all containers */
    }
    
    .right-panel {
        position: static;
        width: 100%;
        margin-top: 0; /* Reset margin, gap will handle spacing */
        order: 2; /* After forecast selector */
    }
    
    #pressureMapContainer {
        height: 500px;
    }
    
    /* Explicit ordering */
    #forecastSelector {
        order: 1;
    }
    
    #alarmContainer {
        order: 3; /* After pressure map */
    }
    
    /* Reset all container margins to 0 for consistent flex gap spacing */
    #chartContainer,
    #statsContainer,
    #statDetailChart,
    #forecastSelector,
    #alarmContainer,
    .right-panel {
        margin: 0; /* Reset all margins */
    }
}

@media (max-width: 768px) {
    .main-layout {
        padding: 20px 10px 0 10px; /* Maintain top padding on mobile */
        display: flex; /* Enable flexbox for reordering */
        flex-direction: column; /* Stack elements vertically */
        gap: 12px; /* Tighter spacing on mobile */
    }
    
    #pressureMapContainer {
        height: 400px;
        padding: 15px;
    }
    
    /* Reset all container margins to 0 for consistent flex gap spacing */
    #chartContainer,
    #statsContainer,
    #statDetailChart,
    #forecastSelector,
    #alarmContainer,
    .right-panel {
        margin: 0; /* Reset all margins */
    }
}

/* Add margin to main content to make room for fixed left panel on larger screens */
@media (min-width: 1200px) {
    .main-layout {
        margin-left: 430px; /* 400px panel + 15px left gap + 15px right gap = 430px */
        margin-right: 15px; /* Match the 15px vertical spacing */
        padding: 20px 0 20px 0; /* Remove horizontal padding since we have margins */
        max-width: calc(100vw - 445px); /* Full viewport width minus panel and all gaps (430 + 15) */
    }
}

/* Stat Detail Chart Styles */
#statDetailChart {
    margin: 0; /* Remove excessive top/bottom margins for consistent spacing */
    height: 300px;
    position: relative;
    width: 100%;
    max-width: none;
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 20px 20px 40px 20px;
    box-sizing: border-box;
}

#statDetailChart .chart-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 15px;
    gap: 20px;
}

#statDetailChart h3 {
    margin: 0;
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 500;
}

@media (min-width: 1200px) {
    #statDetailChart {
        max-width: 100%; /* Use full available width within constrained layout */
    }
}

/* Performance optimizations */
html {
    font-display: swap; /* Improve font loading */
}

/* Chart loading placeholder styles */
#chartLoadingPlaceholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 400px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    font-size: 18px;
    color: #6c757d;
    font-weight: 500;
    animation: pulse 2s ease-in-out infinite alternate;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Hide forecast chart initially */
#forecastChart.hidden {
    display: none;
}

/* Optimize canvas rendering */
canvas {
    will-change: transform; /* Hint for GPU acceleration */
}
