/* ========================================
   SCADA Components Shared Styles
   ======================================== */

/* Base Component Container */
.scada-component {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: inline-block;
    vertical-align: top;
}

.scada-component.no-border {
    border: none !important;
}

/* Component Header */
.scada-component-header {
    position: relative;
    user-select: none;
}

.scada-header-main {
    font-weight: 700;
}

.scada-header-columns {
    display: flex;
    background: rgba(0, 0, 0, 0.15);
    margin: 4px -16px -8px -16px;
    padding: 0;
}

.scada-header-col {
    flex: 1;
    text-align: center;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.scada-header-col:first-child {
    border-left: none;
}

/* Component Body */
.scada-component-body {
    min-height: 20px;
}

/* Features */
.scada-feature {
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
}

.scada-feature-label {
    min-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scada-feature-value {
    display: flex;
    align-items: center;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
}

/* Bit Indicator (LED style) */
.scada-bit-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    transition: all 0.2s ease;
}

.scada-bit-indicator.size-sm {
    width: 8px;
    height: 8px;
}

.scada-bit-indicator.size-lg {
    width: 16px;
    height: 16px;
}

.scada-bit-indicator.size-xl {
    width: 20px;
    height: 20px;
}

/* Table Layout */
.scada-table {
    width: 100%;
    border-collapse: collapse;
}

.scada-table td {
    border: none;
    padding: 0;
    vertical-align: middle;
}

.scada-table tr:not(:last-child) td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* ========================================
   Edit Mode Styles
   ======================================== */

.scada-component.edit-mode {
    position: relative;
}

.scada-component.edit-mode .scada-feature.editable {
    cursor: pointer;
}

.scada-component.edit-mode .scada-feature.editable:hover {
    filter: brightness(1.15);
}

.scada-component.edit-mode .scada-feature.selected {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* Drag handles for edit mode */
.scada-component.edit-mode::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    border: 2px dashed transparent;
    transition: border-color 0.15s;
}

.scada-component.edit-mode:hover::after {
    border-color: rgba(59, 130, 246, 0.5);
}

/* ========================================
   Size Variants
   ======================================== */

.scada-component.size-sm .scada-component-header {
    padding: 4px 8px;
    font-size: 11px;
}

.scada-component.size-sm .scada-feature {
    padding: 2px 4px;
    font-size: 10px;
    gap: 4px;
}

.scada-component.size-sm .scada-feature-label {
    min-width: 60px;
}

.scada-component.size-lg .scada-component-header {
    padding: 12px 20px;
    font-size: 16px;
}

.scada-component.size-lg .scada-feature {
    padding: 8px 12px;
    font-size: 14px;
}

.scada-component.size-lg .scada-feature-label {
    min-width: 100px;
}

/* ========================================
   Layout Variants
   ======================================== */

/* Grid Layout */
.scada-component.layout-grid .scada-component-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* Compact Layout */
.scada-component.layout-compact .scada-feature {
    padding: 1px 4px;
    gap: 4px;
}

.scada-component.layout-compact .scada-feature-label {
    min-width: 50px;
    font-size: 10px;
}

/* ========================================
   Themed Variants
   ======================================== */

/* Dark theme (default) */
.scada-theme-dark {
    --scada-bg: #1a1a2e;
    --scada-text: #fff;
    --scada-border: rgba(255, 255, 255, 0.1);
}

/* Light theme */
.scada-theme-light {
    --scada-bg: #f8fafc;
    --scada-text: #1e293b;
    --scada-border: rgba(0, 0, 0, 0.1);
}

/* ========================================
   Animation Classes
   ======================================== */

@keyframes scada-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes scada-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.scada-animate-pulse {
    animation: scada-pulse 2s ease-in-out infinite;
}

.scada-animate-blink {
    animation: scada-blink 1s step-start infinite;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 768px) {
    .scada-component-header {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .scada-feature {
        padding: 4px 6px;
        gap: 6px;
    }
    
    .scada-feature-label {
        min-width: 60px;
        font-size: 11px;
    }
    
    .scada-header-columns {
        flex-wrap: wrap;
    }
    
    .scada-header-col {
        min-width: 50px;
        font-size: 10px;
    }
}

/* ========================================
   Utility Classes
   ======================================== */

.scada-text-mono {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
}

.scada-shadow-glow {
    box-shadow: 0 0 10px currentColor;
}

.scada-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================
   Chart / Report Page Full Height Fix

   Layout chain: body > .wrapper > .main > nav + main.content > #mainContainer > Component
   Problem: .wrapper has no height, .main has min-height:100vh (AppStack),
   so percentage heights don't resolve and flex children overflow.
   Fix: force explicit height chain top-down.
   ======================================== */

body:has(.chart-fullheight) .wrapper {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body:has(.chart-fullheight) .main {
    height: 100%;
    min-height: 0 !important;  /* override AppStack min-height:100vh */
    overflow: hidden;
}

body:has(.chart-fullheight) main.content {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden;
}

body:has(.chart-fullheight) #mainContainer {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden;
}

/* Highcharts: prevent SVG from dictating container size */
body:has(.chart-fullheight) .highcharts-container {
    position: absolute !important;
    width: 100% !important;
    height: 100% !important;
}
body:has(.chart-fullheight) [id="chartContainer"] {
    position: relative;
}

/* ========================================
   Dashboard Viewer Full Height Fix

   Stessa catena di Chart/Report ma senza la regola highcharts-container:
   i mini-chart della dashboard hanno dimensioni assolute fisse, non devono
   essere forzati a width/height:100%.
   ======================================== */

body:has(.dashboard-fullheight) .wrapper {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body:has(.dashboard-fullheight) .main {
    height: 100%;
    min-height: 0 !important;
    overflow: hidden;
}

body:has(.dashboard-fullheight) main.content {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden;
}

body:has(.dashboard-fullheight) #mainContainer {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden;
}

/* ========================================
   Chart Datepicker Dark Mode Fix
   ======================================== */

/* AppStack dark themes */
body[data-theme="dark"] .chart-datepicker,
body[data-theme="default"] .chart-datepicker,
body[data-theme="colored"] .chart-datepicker,
[data-bs-theme="dark"] .chart-datepicker {
    color-scheme: dark;
}

/* AppStack light theme */
body[data-theme="light"] .chart-datepicker,
[data-bs-theme="light"] .chart-datepicker {
    color-scheme: light;
}
