/* WhatsApp-PLC Monitor - Custom Styles */

/* ===== SIDEBAR LAYOUT ===== */
.app-container {
    display: flex;
    min-height: calc(100vh - 60px);
}

.app-sidebar {
    width: 260px;
    min-width: 260px;
    background: linear-gradient(180deg, #1e3a5f 0%, #152a45 100%);
    color: #fff;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.app-sidebar.collapsed {
    width: 60px;
    min-width: 60px;
}

.app-sidebar.collapsed .group-title,
.app-sidebar.collapsed .item-title,
.app-sidebar.collapsed .status-text,
.app-sidebar.collapsed .nav-item span:last-child {
    display: none;
}

.app-sidebar.collapsed .nav-group-header {
    justify-content: center;
    padding: 12px 0;
}

.app-sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
}

.app-sidebar.collapsed .group-arrow {
    display: none;
}

.app-sidebar.collapsed .sidebar-status {
    flex-direction: column;
    padding: 10px 5px;
}

.app-sidebar.collapsed .status-badge {
    padding: 5px;
    margin: 2px 0;
    justify-content: center;
}

.sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 20px;
    width: 24px;
    height: 24px;
    background: #1e88e5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: #1976d2;
    transform: scale(1.1);
}

.sidebar-toggle span {
    color: white;
    font-size: 12px;
}

.sidebar-status {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 15px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
}

.status-badge span:first-child {
    font-size: 12px;
}

.status-badge.status-connected {
    background-color: #4caf50 !important;
    color: white !important;
}

.status-badge.status-disconnected {
    background-color: #f44336 !important;
    color: white !important;
}

.status-badge.status-ok {
    background-color: #4caf50 !important;
    color: white !important;
}

.status-badge.bg-gray {
    background-color: #9e9e9e !important;
    color: white !important;
}

.status-badge.bg-purple {
    background-color: #9c27b0 !important;
}

.status-badge.bg-orange {
    background-color: #ff9800 !important;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 10px 0;
    overflow-y: auto;
}

.nav-group {
    margin-bottom: 5px;
}

.nav-group-header {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    transition: background 0.2s;
    gap: 10px;
}

.nav-group-header:hover {
    background: rgba(255,255,255,0.1);
}

.group-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.group-title {
    flex: 1;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.group-arrow {
    font-size: 12px;
    transition: transform 0.2s;
}

.nav-group-items {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-group-items.collapsed {
    max-height: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 15px 10px 45px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s;
    gap: 10px;
    font-size: 13px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.nav-item.active {
    background: rgba(30,136,229,0.3);
    color: #fff;
    border-left: 3px solid #1e88e5;
}

.nav-item span:first-child {
    font-size: 14px;
    width: 20px;
    text-align: center;
}

.nav-item-single {
    padding-left: 15px !important;
}

.nav-item-single .item-title {
    flex: 1;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main Content */
.app-content {
    flex: 1;
    background: #f5f7fa;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.app-content.expanded {
    margin-left: 0;
}

.content-wrapper {
    padding: 20px;
    max-width: 100%;
}

/* Tab Sections */
.tab-section {
    display: none;
}

.tab-section.active {
    display: block;
}

/* FORCE OVERFLOW VISIBLE AND AUTO HEIGHT EVERYWHERE */
html, body {
    overflow-x: auto !important;
    overflow-y: auto !important;
    width: 100% !important;
    height: auto !important;
}

.container-fluid {
    overflow: visible !important;
    max-width: 100% !important;
    padding-right: 30px !important;
    height: auto !important;
}

/* Tab section frames */
.tab-section {
    border: 3px solid #1e88e5 !important;
    border-radius: 8px !important;
    padding: 20px 20px 30px 20px !important;
    margin: 0 0 20px 0 !important;
    background: #fff !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
}

/* Remove all height limits from Metro UI tabs */
[data-role="tabs"] + div,
.tabs + div,
.border.bd-default {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* Tab content frame - ora gestito da .tab-section */

/* Assicura che le tab abbiano spazio e altezza automatica */
.tabs-content {
    overflow: visible !important;
    padding-right: 20px !important;
    height: auto !important;
    max-height: none !important;
}

/* Rimuovi limiti altezza da Metro 4 */
.tabs-content > div {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* Only log container should scroll */
.log-container {
    overflow-y: auto !important;
}

/* Header */
.app-bar-custom {
    background-color: #1e88e5 !important;
}

.app-bar-custom .brand {
    color: white !important;
    font-weight: bold;
}

/* Pulsanti header ben visibili */
.app-bar-custom .button {
    font-weight: bold !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    font-size: 14px !important;
}

.app-bar-custom .button.light {
    background-color: #fff !important;
    color: #1e88e5 !important;
}

.app-bar-custom .button.info {
    background-color: #00bcd4 !important;
    color: white !important;
}

.app-bar-custom .button.alert {
    background-color: #f44336 !important;
    color: white !important;
}

.app-bar-custom .button:hover {
    opacity: 0.9 !important;
    transform: scale(1.02);
}

/* Tables - auto layout per adattarsi al contenuto */
.table {
    width: 100% !important;
    table-layout: auto !important;
    margin-bottom: 15px !important;
}

.table tbody tr:last-child td {
    padding-bottom: 15px !important;
}

.table th, .table td {
    padding: 12px 8px !important;
    vertical-align: middle !important;
    line-height: 1.5 !important;
    height: auto !important;
    min-height: 50px !important;
}

/* Action column - give it enough space */
.table th:last-child,
.table td:last-child {
    width: 220px !important;
    min-width: 220px !important;
    text-align: center;
}

/* Badges - forza posizione normale */
.badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    display: inline-block !important;
    position: static !important;
    float: none !important;
    right: auto !important;
    top: auto !important;
    left: auto !important;
    bottom: auto !important;
}

/* Badge dentro celle tabella */
.table td .badge {
    position: static !important;
    display: block !important;
    margin: 0 auto 4px auto !important;
    width: fit-content !important;
}

/* Colori badge PLC e OPC UA */
.badge.bg-blue {
    background-color: #2196F3 !important;
    color: white !important;
}

.badge.bg-purple {
    background-color: #9C27B0 !important;
    color: white !important;
}

/* Status badges - forza posizione statica */
.status-connected,
.status-disconnected,
.status-connecting,
.status-warning,
.status-ok {
    position: static !important;
    display: inline-block !important;
    float: none !important;
}

.status-connected {
    background-color: #4caf50 !important;
    color: white !important;
}

.status-disconnected {
    background-color: #f44336 !important;
    color: white !important;
}

.status-connecting, .status-warning {
    background-color: #ff9800 !important;
    color: white !important;
}

.status-ok {
    background-color: #4caf50 !important;
    color: white !important;
}

/* Action buttons */
.action-buttons {
    white-space: nowrap !important;
    padding: 10px 5px !important;
}

.action-buttons .button {
    padding: 8px 12px !important;
    margin: 3px !important;
    min-width: 40px !important;
    min-height: 36px !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

.action-buttons .button span {
    margin: 0 !important;
}

/* Assicura che le righe della tabella abbiano altezza sufficiente */
.table tbody tr {
    height: auto !important;
    min-height: 60px !important;
}

/* Log Container - exception to overflow rule */
.log-container {
    background-color: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    padding: 15px;
    border-radius: 4px;
    height: 500px;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.log-container .log-entry {
    margin: 2px 0;
    padding: 2px 0;
    border-bottom: 1px solid #333;
}

.log-container .log-timestamp {
    color: #6a9955;
}

.log-container .log-info {
    color: #4fc3f7;
}

.log-container .log-warning {
    color: #ff9800;
}

.log-container .log-error {
    color: #f44336;
}

.log-container .log-success {
    color: #4caf50;
}

/* Cards */
.card {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 15px;
}

.card-header {
    background-color: #f5f5f5;
    font-weight: 600;
    padding: 10px 15px;
}

/* Info boxes */
.more-info-box {
    border-radius: 4px;
    margin-bottom: 15px;
}

.more-info-box .content {
    padding: 15px;
}

.more-info-box .content h2 {
    font-size: 2rem;
    font-weight: bold;
    margin: 0;
}

.more-info-box .icon {
    font-size: 48px;
    opacity: 0.3;
}

/* Dialogs */
.dialog {
    border-radius: 8px;
}

.dialog-title {
    background-color: #1e88e5;
    color: white;
    font-weight: bold;
    padding: 15px 20px;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

/* Buttons with icons */
.button span[class^="mif-"] {
    margin-right: 5px;
}

/* Switch styling */
.switch {
    margin-top: 5px;
}

/* QR Code */
#qrCodeContainer {
    background: white;
    padding: 20px;
    border-radius: 8px;
    display: inline-block;
}

#qrCodeImage {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
}

/* Padding for header */
.pt-8 {
    padding-top: 60px !important;
}

/* Enabled/Disabled indicator */
.enabled-yes {
    color: #4caf50;
    font-weight: bold;
}

.enabled-no {
    color: #9e9e9e;
}

/* Hover effects */
.table.row-hover tbody tr:hover {
    background-color: #e3f2fd !important;
}

/* Menu toggle button in header */
.menu-toggle-btn {
    display: none;
    margin-right: 15px;
    padding: 10px 14px !important;
    background: #1e88e5 !important;
    border: none !important;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.menu-toggle-btn:hover {
    background: #1565c0 !important;
}

.menu-toggle-btn span {
    color: white !important;
    font-size: 22px;
}

/* Responsive */
@media (max-width: 1200px) {
    /* Mostra pulsante hamburger */
    .menu-toggle-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    .app-sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        bottom: 0;
        z-index: 1000;
        transform: translateX(0);
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }

    .app-sidebar.collapsed {
        transform: translateX(-100%);
    }

    /* Nascondi toggle interno quando c'è hamburger */
    .app-sidebar .sidebar-toggle {
        display: none;
    }

    .app-content {
        margin-left: 0 !important;
        width: 100%;
    }

    /* Overlay quando sidebar è aperta */
    .app-sidebar:not(.collapsed)::after {
        content: '';
        position: fixed;
        top: 0;
        left: 260px;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: -1;
    }

    /* === Tablet styles per contenuti === */
    .tab-section {
        padding: 15px !important;
        overflow-x: auto;
    }

    /* Tabelle responsive con scroll orizzontale */
    .table-container, .tab-section > .row, .tab-section > div:has(table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 600px;
    }

    /* Form layout su tablet */
    .tab-section .row {
        flex-wrap: wrap !important;
    }

    .tab-section .row > [class*="cell-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 10px;
    }

    .tab-section .row > .cell-6,
    .tab-section .row > .cell-4,
    .tab-section .row > .cell-3 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    /* Input e select a larghezza piena */
    .tab-section input[type="text"],
    .tab-section input[type="number"],
    .tab-section input[type="password"],
    .tab-section input[type="email"],
    .tab-section select,
    .tab-section textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Pulsanti più compatti */
    .tab-section .button {
        padding: 8px 12px !important;
        font-size: 13px;
    }

    /* Card dashboard */
    .tab-section .card {
        margin-bottom: 15px;
    }

    /* Form inline diventa verticale */
    .form-inline {
        flex-direction: column;
        align-items: stretch !important;
    }

    .form-inline > * {
        margin-bottom: 10px;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .app-sidebar {
        width: 280px;
        min-width: 280px;
    }

    .brand-text {
        display: none;
    }

    .app-bar-custom .button:not(.menu-toggle-btn) span:last-child {
        display: none;
    }

    .content-wrapper {
        padding: 10px;
    }

    .tab-section {
        padding: 12px !important;
        margin: 0 0 15px 0 !important;
    }

    /* Titoli sezione su mobile */
    .tab-section .d-flex.flex-justify-between {
        flex-direction: column !important;
        gap: 10px;
    }

    .tab-section .d-flex.flex-justify-between > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
    }

    /* Tutte le colonne a larghezza piena su mobile */
    .tab-section .row > [class*="cell-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    .log-container {
        height: 300px;
        font-size: 11px;
    }

    .more-info-box .content h2 {
        font-size: 1.5rem;
    }

    .action-buttons .button {
        padding: 3px 6px !important;
        font-size: 11px;
    }

    /* Tabelle responsive su mobile */
    .table {
        font-size: 12px;
        min-width: 500px;
    }

    .table th, .table td {
        padding: 6px 4px !important;
    }

    .badge {
        font-size: 10px;
        padding: 2px 6px;
    }
}

@media (max-width: 576px) {
    .app-sidebar {
        width: 100%;
        min-width: 100%;
    }

    .app-sidebar:not(.collapsed)::after {
        display: none;
    }
}

/* Tabelle */
#tablePLC, #tableOPCUA, #tableVariables, #tableRecipients,
#tableQueries, #tableMaintenance, #tableHistory {
    width: 100% !important;
}

/* Contenitore tabelle responsive */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 15px;
}

.table-responsive > .table {
    margin-bottom: 0;
}

/* ========================================
   NUOVE SEZIONI: Dashboard, History, Settings
   ======================================== */

/* Tab frame - ora gestito da .tab-section */

/* ===== DASHBOARD ===== */
#tab-dashboard .card {
    transition: transform 0.2s, box-shadow 0.2s;
    border-radius: 8px;
    overflow: hidden;
}

#tab-dashboard .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

#tab-dashboard .card-header {
    background: linear-gradient(135deg, #1e88e5 0%, #1565c0 100%);
    color: white;
    font-weight: 600;
    padding: 12px 15px;
}

#tab-dashboard .card-header span[class^="mif-"] {
    margin-right: 8px;
}

/* Dashboard status icons */
.dash-status-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.dash-status-ok { color: #4caf50; }
.dash-status-warning { color: #ff9800; }
.dash-status-error { color: #f44336; }
.dash-status-offline { color: #9e9e9e; }

/* Dashboard stat cards */
.dash-stat-card {
    text-align: center;
    padding: 15px;
}

.dash-stat-card h3 {
    font-size: 2.5rem;
    font-weight: bold;
    margin: 0;
    line-height: 1;
}

.dash-stat-card small {
    color: #666;
    font-size: 0.9rem;
}

/* Dashboard badges */
#tab-dashboard .badge {
    font-size: 1.3em;
    padding: 8px 16px;
    border-radius: 6px;
}

/* Recent notifications list */
.items-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.items-list li {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
}

.items-list li:last-child {
    border-bottom: none;
}

.items-list li:hover {
    background-color: #f5f5f5;
}

/* Silence indicator */
#dashSilenceIndicator .remark {
    margin: 10px 0;
    padding: 10px 15px;
    border-radius: 6px;
}

/* ===== HISTORY (Storico) ===== */
#tab-history .metro-input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
}

#tab-history select.metro-input {
    background: white;
}

#historyStats {
    padding: 10px 0;
}

#historyStats .badge {
    font-size: 0.85em;
    padding: 6px 12px;
    margin-bottom: 5px;
}

/* History table styling */
#tableHistory {
    font-size: 13px;
}

#tableHistory th {
    background: #f8f9fa;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
}

#tableHistory .text-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    list-style: none;
    padding: 0;
    margin: 15px 0;
    flex-wrap: wrap;
}

.pagination .page-item {
    margin: 2px;
}

.pagination .page-link {
    display: block;
    padding: 8px 14px;
    text-decoration: none;
    color: #1e88e5;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    transition: all 0.2s;
}

.pagination .page-item.active .page-link {
    background: #1e88e5;
    color: white;
    border-color: #1e88e5;
}

.pagination .page-item.disabled .page-link {
    color: #999;
    pointer-events: none;
    background: #f5f5f5;
}

.pagination .page-link:hover:not(.disabled) {
    background: #e3f2fd;
    border-color: #1e88e5;
}

/* ===== SETTINGS (Impostazioni) ===== */
#tab-settings .card {
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
}

#tab-settings .card-header {
    background: linear-gradient(135deg, #607d8b 0%, #455a64 100%);
    color: white;
    font-weight: 600;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#tab-settings .card-header span[class^="mif-"] {
    margin-right: 8px;
}

/* Silence ranges table */
#silenceRangesList table {
    margin-top: 10px;
}

#silenceRangesList th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
}

#silenceRangesList td {
    vertical-align: middle;
}

/* Switch styling for settings */
#tab-settings [data-role="switch"] {
    margin: 10px 0;
}

/* Backup/restore buttons */
#tab-settings .button {
    padding: 10px 20px;
    font-weight: 500;
}

#tab-settings .button span[class^="mif-"] {
    margin-right: 6px;
}

/* Remark boxes */
.remark {
    padding: 12px 15px;
    border-radius: 6px;
    margin: 10px 0;
}

.remark.warning {
    background: #fff3e0;
    border-left: 4px solid #ff9800;
}

.remark.info {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.remark.success {
    background: #e8f5e9;
    border-left: 4px solid #4caf50;
}

.remark.alert {
    background: #ffebee;
    border-left: 4px solid #f44336;
}

/* ===== CALENDAR ===== */
#tab-calendar h4, #tab-calendar h5 {
    color: #333;
    margin-bottom: 15px;
}

#tab-calendar h4 span, #tab-calendar h5 span {
    margin-right: 8px;
    color: #1e88e5;
}

#calendarDayDetails {
    min-height: 200px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
}

/* ===== UTILITY CLASSES ===== */
.text-center { text-align: center; }
.text-muted { color: #999; }
.mt-1 { margin-top: 5px; }
.mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 15px; }
.mb-1 { margin-bottom: 5px; }
.mb-2 { margin-bottom: 10px; }
.mb-3 { margin-bottom: 15px; }
.mr-1 { margin-right: 5px; }
.mr-2 { margin-right: 10px; }
.ml-2 { margin-left: 10px; }
.p-2 { padding: 10px; }
.p-3 { padding: 15px; }
.p-4 { padding: 20px; }

/* Colors */
.fg-green { color: #4caf50 !important; }
.fg-red { color: #f44336 !important; }
.fg-orange { color: #ff9800 !important; }
.fg-blue { color: #2196f3 !important; }
.fg-cyan { color: #00bcd4 !important; }
.fg-indigo { color: #3f51b5 !important; }
.fg-purple { color: #9c27b0 !important; }
.fg-gray { color: #9e9e9e !important; }
.fg-white { color: white !important; }

.bg-green { background-color: #4caf50 !important; }
.bg-red { background-color: #f44336 !important; }
.bg-orange { background-color: #ff9800 !important; }
.bg-blue { background-color: #2196f3 !important; }
.bg-cyan { background-color: #00bcd4 !important; }
.bg-indigo { background-color: #3f51b5 !important; }
.bg-gray { background-color: #9e9e9e !important; }

/* ===== ANIMATIONS ===== */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.pulse {
    animation: pulse 2s infinite;
}

/* Loading state */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #1e88e5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

