/* ===== VARIABLES ===== */
:root {
    --bg-main: #07090c;
    --bg-sidebar: #0c1015;
    --bg-panel: #12161d;
    --bg-card: #171b23;
    --border-color: #2b303a;
    --text-primary: #f8fafc;
    --text-secondary: #eef4ff;
    --text-muted: #dce7f5;
    --accent: #f2c94c;
    --accent-hover: #f6d56b;
    --danger: #ff6b6b;
    --success: #34c97b;
    --warning: #f2c94c;
    --info: #77a9ff;
    --orange: #ff9f43;
    --sidebar-width: 240px;
    --topbar-height: 64px;
    --radius: 10px;
    --radius-sm: 6px;
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.65;
    font-size: 15px;
    overflow-x: hidden;
}

/* ===== LOGIN PAGE ===== */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #07090c 0%, #11151c 50%, #07090c 100%);
}

.login-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 40px;
    width: 400px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-card h3 {
    color: var(--text-primary);
    margin-bottom: 4px;
    font-weight: 700;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 14px;
}

.login-card .form-label {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: left;
    display: block;
}

.login-card .form-control {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}

.login-card .form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    outline: none;
}

/* ===== APP LAYOUT ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    padding: 24px 16px;
}

.sidebar-brand {
    text-align: center;
    margin-bottom: 8px;
}

.brand-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 4px;
}

.sidebar-brand h4 {
    font-weight: 700;
    font-size: 20px;
    color: var(--text-primary);
    margin: 0;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}

.sidebar-nav {
    list-style: none;
    flex: 1;
}

.sidebar-nav li {
    margin-bottom: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.sidebar-link:hover {
    background: rgba(242, 201, 76, 0.1);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: rgba(242, 201, 76, 0.16);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.logout-link:hover {
    background: rgba(239, 68, 68, 0.1) !important;
    color: var(--danger) !important;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* ===== TOP BAR ===== */
.top-bar {
    height: var(--topbar-height);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
    color: #ffffff;
}

.top-bar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }

    50% {
        box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
    }
}

/* ===== CONTENT SECTIONS ===== */
.content-section {
    display: none;
    padding: 32px 36px;
    animation: fadeIn 0.3s ease;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== STAT CARDS (DEFINITIVE) ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 28px;
    align-items: stretch;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
    transition: box-shadow 0.2s, border-color 0.2s;
    min-height: 110px;
    will-change: transform;
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-icon .material-symbols-outlined {
    font-size: 28px !important;
    line-height: 1;
}

.stat-info {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex: 1;
}

.stat-number {
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
    color: #ffffff;
}

.stat-label {
    font-size: 14px;
    line-height: 1.2;
    color: #ffffff;
    margin-top: 4px;
}

.stat-card:hover {
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
    border-color: rgba(242, 201, 76, 0.3);
}

/* ===== PANELS (Cards generiche) ===== */
.dashboard-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h5 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.panel-header .panel-count {
    color: var(--text-primary);
}

.panel-link {
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.panel-link:hover {
    color: var(--accent-hover);
}

.panel-count {
    font-size: 12px;
    color: var(--text-primary);
}

.panel-body {
    padding: 22px;
}

/* ===== PIE CHART ===== */
.chart-area {
    display: flex;
    align-items: center;
    gap: 24px;
}

.pie-chart {
    width: 190px;
    height: 190px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ===== MINI INCIDENT LIST (Dashboard) ===== */
.mini-incident-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mini-incident {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border-left: 4px solid var(--border-color);
    transition: background 0.2s, transform 0.2s;
}

.mini-incident:hover {
    background: rgba(242, 201, 76, 0.08);
    transform: translateX(2px);
}

.mini-incident.critical {
    border-left-color: var(--danger);
}

.mini-incident.high {
    border-left-color: var(--warning);
}

.mini-incident.medium {
    border-left-color: var(--info);
}

.mini-incident.low {
    border-left-color: var(--text-muted);
}

.mini-incident-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mini-id {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.mini-type {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== BADGES ===== */
.badge-pill,
.mini-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.badge-critical {
    background: rgba(255, 107, 107, 0.16);
    color: #ff8e8e;
}

.badge-high {
    background: rgba(242, 201, 76, 0.16);
    color: #f7d56b;
}

.badge-medium {
    background: rgba(119, 169, 255, 0.16);
    color: #9dc0ff;
}

.badge-low {
    background: rgba(124, 135, 157, 0.16);
    color: #bac4d3;
}

.badge-blocked {
    background: rgba(52, 201, 123, 0.16);
    color: #72d69e;
}

.badge-detected {
    background: rgba(255, 107, 107, 0.16);
    color: #ff8e8e;
}

.badge-isolated {
    background: rgba(255, 159, 67, 0.16);
    color: #ffbb76;
}

.badge-monitored {
    background: rgba(119, 169, 255, 0.16);
    color: #9dc0ff;
}

/* ===== INCIDENT TABLE ===== */
.incident-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 6px;
}

.incident-table thead th {
    padding: 10px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
    border: none;
}

.incident-table tbody tr {
    background: rgba(255, 255, 255, 0.025);
    cursor: pointer;
    transition: all 0.2s ease;
}

.incident-table tbody tr:hover {
    background: rgba(242, 201, 76, 0.1);
    transform: translateX(2px);
}

.incident-table td {
    padding: 12px 14px;
    border: none;
    font-size: 14px;
    vertical-align: middle;
    color: var(--text-primary);
}

.incident-table td:first-child {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.incident-table td:last-child {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.cell-id {
    font-weight: 600;
    color: var(--accent);
}

.cell-date {
    font-size: 13px;
    color: var(--text-primary);
}

code {
    background: rgba(242, 201, 76, 0.12);
    color: var(--accent-hover);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
}

.btn-action {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    background: rgba(242, 201, 76, 0.12);
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
    transition: all 0.2s;
}

.btn-action:hover {
    background: rgba(242, 201, 76, 0.2);
    color: var(--accent-hover);
}

/* Critical row pulsing */
@keyframes pulse-red {

    0%,
    100% {
        box-shadow: inset 3px 0 0 var(--danger);
    }

    50% {
        box-shadow: inset 3px 0 0 var(--danger), 0 0 12px rgba(239, 68, 68, 0.2);
        background: rgba(239, 68, 68, 0.06) !important;
    }
}

.incident-row.critical {
    animation: pulse-red 2s infinite ease-in-out;
}

/* ===== AI CONSULTANT SECTION ===== */
.ai-description {
    color: var(--text-primary);
    font-size: 15px;
    margin-bottom: 20px;
}

.ai-input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.ai-input {
    flex: 1;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(242, 201, 76, 0.16);
}

.btn-accent {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #11151a;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-accent:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(242, 201, 76, 0.16);
}

.ai-response-box {
    background: #f5f2e8;
    border: 1px solid #d8cfac;
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    font-size: 14px;
    line-height: 1.7;
    color: #111111 !important;
    margin-top: 12px;
    white-space: pre-wrap;
}

.ai-response-box *,
.modal-custom,
.modal-custom .modal-body,
.modal-custom .modal-body * {
    color: #111111 !important;
}

/* ===== ADVICE GRID ===== */
.advice-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.advice-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 20px;
    text-align: center;
    transition: transform 0.2s, border-color 0.2s;
}

.advice-card:hover {
    transform: translateY(-2px);
    border-color: rgba(242, 201, 76, 0.4);
}

.advice-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.advice-card h6 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.advice-card p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

/* ===== MODAL ===== */
.modal-custom {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
}

.modal-custom .modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
}

.modal-custom .modal-body {
    padding: 20px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-panels {
        grid-template-columns: 1fr;
    }

    .advice-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        padding: 12px 8px;
    }

    .sidebar-brand h4,
    .brand-sub,
    .sidebar-link span:not(.nav-icon),
    .sidebar-footer span:not(.nav-icon) {
        display: none;
    }

    .main-content {
        margin-left: 60px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .content-section {
        padding: 16px;
    }

    .ai-input-group {
        flex-direction: column;
    }

    .stat-card-2 {
        padding-top: 12px;
    }
}