/* ================================
   Base layout
   ================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: sans-serif;
    margin: 0;
    background-color: var(--bg-light);
    color: var(--text-dark);
}

.body-login {
    margin: 0;
    padding-top: 0;
    background: var(--bg-light);
}

/* ================================
   Topbar
   ================================ */
.topbar {
    width: 100%;
    background: var(--bg-dark);
    border-bottom: 3px solid var(--accent);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.topbar-inner {
    width: 100%;
    margin: 0 auto;
    padding: 10px 26px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.topbar .navbar {
    padding: 0;
    background: transparent !important;
}

.topbar .navbar-collapse {
    justify-content: flex-end;
    transition: height 0.2s ease;
}

.topbar .navbar-toggler {
    border: none;
}

.topbar .navbar-toggler:focus {
    box-shadow: none;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo span {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-light);
    letter-spacing: 0.5px;
}

.logo svg {
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.6));
}

/* ================================
   Page frame (section header)
   ================================ */
.page-frame {
    background-color: var(--bg-frame);
    border-left: 4px solid var(--accent);
    padding: 6px 14px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.18);
    margin: 20px 20px 25px 20px;
}

.page-frame h2 {
    margin: 0;
    line-height: 1.2;
}

.section-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-dark);
}

/* ================================
   Login page
   ================================ */
.login-wrapper {
    min-height: 100vh;
    min-height: 100svh; /* mobile moderni */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    background: var(--bg-light);
}

.login-box {
    background: #fff;
    width: 100%;
    max-width: 320px;
    padding: 24px 28px;
    border-radius: 8px;
    border-left: 4px solid var(--accent);
    box-shadow: 0 4px 14px var(--shadow-soft);
}

.login-box-header {
    background: var(--bg-dark);
    padding: 10px 14px;
    margin: -24px -28px 16px -28px; /* stacca dal box e abbraccia i bordi */
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.login-box-header span {
    color: var(--text-light);
    font-weight: 600;
    font-size: 1rem;
}

.login-box h2 {
    margin: 0 0 16px;
    font-size: 1.2rem;
    color: var(--text-dark);
}

.login-box .form-control {
    background: var(--bg-light);
}

/*GRGR*/
.placeholder-italic::placeholder {
    font-style: italic;
}

/* ================================
   Griglia tile
   ================================ */
.tiles {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

/* Tile stile pfSense-like come login-box */
.tile {
    background: #fff;
    border: 1px solid var(--border-light);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 3px 6px var(--shadow-soft);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    will-change: transform;
    color: var(--text-dark);
    --icon-color: var(--accent);
}

.tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px var(--shadow-strong);
    border-color: var(--accent-hover);
    --icon-color: var(--accent-hover);
}

.tile h3 {
    margin: 8px 0 4px 0;
    font-size: 1.05rem;
}

.tile p {
    margin: 0;
    color: #333;
    font-size: 0.9rem;
}

/* Icone tile */
.tile-icon {
    font-size: 28px;
    margin-bottom: 4px;
    color: var(--icon-color);
}

.tile-icon i {
    color: inherit;
}

/* ================================
    Buttons
   ================================ */
.btn {
    font-weight: 600;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    border: none;
    padding: 6px 14px;
    font-size: 0.95rem;
    line-height: 1.2;
    vertical-align: middle;
    --icon-color: currentColor;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    filter: brightness(0.96);
}

.btn-primary.active,
.btn-primary:active {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: inset 0 2px 2px rgba(0,0,0,0.15);
    filter: brightness(0.9);
}


.btn-primary.btn-login {
    width: 100%;
    padding: 8px 0;
    box-shadow: none;
}

.btn-primary.btn-login:hover,
.btn-primary.btn-login:focus,
.btn-primary.btn-login:active {
    box-shadow: none;
}

.btn-primary.btn-login:disabled {
    opacity: .65;
    box-shadow: none;
    filter: none;
}

.btn-outline-primary {
    color: var(--accent);
    border-color: var(--accent);
    background-color: transparent;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    color: #fff;
    background-color: var(--accent);
    border-color: var(--accent);
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
    color: #ffe5e8;
    background-color: #dc3545;
    border-color: #dc3545;
}

/* ================================
   Form controls
   ================================ */
.form-control,
.form-select {
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.85rem;
    height: auto;
    line-height: 1.1;
}

.form-label,
.form-check-label,
.form-check-input {
    font-size: 0.80rem;          /* più piccina */
    margin-bottom: 2px;          /* Bootstrap usa 8px; lo riduciamo */
    cursor: pointer;
}

/* ================================
   Focus globale per controlli form
   ================================ */
input.form-control:focus,
textarea.form-control:focus,
select.form-select:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
    outline: none;
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    box-shadow: none;
    border-color: #dc3545; /* rosso Bootstrap */
}

.form-control.is-valid:focus,
.form-select.is-valid:focus {
    box-shadow: none;
    border-color: #198754; /* verde Bootstrap */
}

/* ================================
   Icons
   ================================ */
.icon,
i.bi {
    color: var(--icon-color, currentColor);
    vertical-align: middle;
}

.icon-static {
    --icon-color-hover: var(--icon-color);
    pointer-events: none;
    margin-right: 6px;
}

.icon-action {
    cursor: pointer;
}

.icon-action:hover {
    color: var(--icon-color-hover);
}

.icon-placeholder {
    opacity: 0;
    pointer-events: none;
}

/* ================================
   Table
   ================================ */
.table-responsive {
    position: relative;
    margin: 20px;
    max-height: calc(100vh - 174px);
    overflow: auto;
    border-radius: 10px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.18);
    background-color: #fff;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-light);
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.table {
    width: 100%;             /* desktop full width */
    min-width: max-content;  /* mobile -> scroll */
    margin: 0;
    table-layout: auto;
    border-color: var(--border-light);
    border-style: hidden;
}

.table th,
.table td {
    vertical-align: middle;
    border-color: var(--border-light);
    white-space: nowrap;   /* niente wrap */
}

.table thead th {
    background-color: #eee;
    background-clip: padding-box;
    font-weight: 700;
    cursor: default;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 2;
}

.table thead th:hover::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--accent);
}

.table thead th[data-sortable="true"] {
    cursor: pointer;
}

.table-group-header td {
    background-color: #f5f5f5;
    font-weight: 600;
    border-top: 2px solid var(--accent);
    border-bottom: 1px solid var(--border-light);
    text-transform: uppercase;
    font-size: 0.85rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
}

.modal-table-scroll {
    max-height: 250px;
    overflow-y: auto;
}

.backup-icon-column {
    width: 40px;
}

.backup-actions-column {
    width: 130px;
}

/* Sort arrows */
.sort-arrow {
    display: inline-block;
    width: 1em;
    text-align: center;
    margin-left: .25rem;
    color: var(--text-dark);
}

.sort-arrow.asc::after {
    content: "▲";
}

.sort-arrow.desc::after {
    content: "▼";
}

/* ================================
   Backup Table
================================ */

.table tbody#backupList tr > td {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.table tbody#backupList tr:hover > td {
    background-color: var(--bg-hover);
}

.table tbody#backupList tr.table-active > td {
    background-color: var(--bg-selected);
    border-color: var(--border-selected);
}

.table tbody#backupList tr.table-active:hover > td {
    background-color: rgba(var(--accent-rgb), 0.25);
}

/* ================================
   Actions column
   ================================ */
td.actions {
    white-space: nowrap;
    text-align: left;
}

.actions span {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
    margin-right: 8px;
}

/* ================================
   Toast
   ================================ */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 12px 18px;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    font-size: 14px;
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    pointer-events: auto;
}

/* ================================
    Modal
   ================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    inset: 0;
    background: rgba(0,0,0,0.45);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #f4f4f4;
    padding: 20px 24px;
    border-left: 4px solid var(--accent);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.modal-content-sm {
    width: 320px;
}

.modal-content-md {
    width: 500px;
}

.modal-content-lg {
    width: 800px;
}

.modal-content-xl {
    width: 95vw;
    max-width: 1200px;
}

.modal-content h3 {
    margin: 0 0 14px 0;
    font-size: 1.2rem;
    color: var(--text-dark);
}

.modal-content label {
    display: block;
    margin-top: 10px;
    font-weight: 600;
    color: #333;
}

.modal-content input[type="text"] {
    width: 100%;
    padding: 6px;
    margin-top: 4px;
    border: 1px solid #bbb;
    border-radius: 4px;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.modal-backdrop {
    z-index: 1990;
}

/* ================================
   Modal "Add Host"
================================ */
.addhost-modal {
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-strong);
}

.addhost-header {
    background: var(--bg-dark);
    color: var(--text-light);
    border-bottom: none;               /* più pulita */
    padding: 10px 14px;
}

.addhost-header .modal-title {
    font-weight: 600;
    font-size: 1rem;                   /* compatto */
}

.addhost-header .btn-close {
    filter: invert(1);                 /* icona chiara su bg scuro */
    opacity: .85;
}

.addhost-header .btn-close:hover {
    opacity: 1;
}

/* Body & footer compatti come il resto dell'app */
.addhost-modal .modal-body {
    padding: 14px 16px;
}

.addhost-modal .modal-footer {
    border-top: none;
    padding: 10px 14px 14px;
}

/* Label & inputs: usano già i tuoi override globali (form-control compatto) */
.addhost-modal .form-label {
    font-size: 0.80rem;
    margin-bottom: 2px;
}

/* Title icon coerente con l'header */
.addhost-header .title-icon {
    font-size: 1.2em;
    line-height: 1;
    display: inline-flex;
    transform: translateY(-1px);
}

/* ================================
   Spin
   ================================ */
.spin {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ================================
   Log Viewer
   ================================ */
.log-viewer {
    position: relative;
    margin: 20px;
    height: calc(100vh - 174px);
    overflow: auto;
    box-shadow: 0 3px 6px rgba(0,0,0,0.18);
    border: 1px solid var(--border-light);
    border-radius: .375rem;
    background: #111;
    color: #ddd;
    font-family: monospace;
    font-size: 0.85rem;
    scrollbar-width: thin;
    scrollbar-color: #9cdcfe transparent;
    -webkit-overflow-scrolling: touch;
}

.log-row {
    display: grid;
    grid-template-columns: 180px 50px 150px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    cursor: pointer;
    transition: background-color .15s ease;
    user-select: none;
    -webkit-user-select: none;
}

.log-row:hover {
    background-color: rgba(255,255,255,.05);
}

.log-row.selected {
    background-color: rgba(156, 220, 254, 0.15);
    border-left: 3px solid #9cdcfe;
}

.log-date,
.log-level,
.log-source {
    white-space: nowrap;
}

.log-message {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* log levels */
.log-info  { color: #9cdcfe; }
.log-warn  { color: #f9e79f; }
.log-error { color: #ff6b6b; }

/* ================================
   Responsive
   ================================ */
@media (max-width: 768px) {

    .topbar-inner {
        flex-wrap: nowrap;
    }

    .topbar .navbar {
        padding-left: 0;
        padding-right: 0;
    }

    .logo span {
        font-size: 1.3rem;
        white-space: nowrap;
    }

    .page-frame {
        margin: 10px 10px 15px 10px;
    }

    .section-title {
        font-size: 1.1rem;
    }

    .table-responsive {
        margin: 10px;
        max-height: calc(100dvh - 8.5rem);
    }

    .table {
        font-size: 0.85rem;
    }

    .table th,
    .table td {
        padding: 0.45rem;
    }

    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 34px;
        min-height: 32px;
        padding: 0.30rem 0.55rem;
        font-size: 0.95rem;
        line-height: 1;
    }

    .btn .icon,
    .btn .bi {
        margin-right: 0;
    }

    .log-viewer {
        margin: 10px;
        height: calc(100dvh - 9rem);
        font-size: 0.65rem;
    }

    .log-row {
        grid-template-columns: 150px 1fr;
    }

    .log-level,
    .log-source {
        display: none;
    }
}

/* ======================================
   Bootstrap compatibility
   ====================================== */
a.tile,
a.tile:hover {
    text-decoration: none;
    color: inherit;
}
