:root {
    --bg: #080b10;
    --bg-elev: #10151d;
    --bg-soft: #161d27;
    --line: rgba(232, 214, 180, 0.12);
    --text: #ece7dc;
    --muted: #9aa3b0;
    --accent: #d4a056;
    --accent-2: #3ecfb2;
    --danger: #e26d6d;
    --ok: #7dce9a;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --radius: 16px;
    --font: "Segoe UI", system-ui, sans-serif;
}

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

html, body { margin: 0; min-height: 100%; }

body {
    font-family: var(--font);
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(212, 160, 86, 0.12), transparent 50%),
        radial-gradient(900px 400px at 100% 0%, rgba(62, 207, 178, 0.08), transparent 45%),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: row;
    align-items: stretch;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.1rem 1rem 1.2rem;
    border-right: 1px solid var(--line);
    background: rgba(8, 11, 16, 0.92);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.mobile-bar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: rgba(8, 11, 16, 0.92);
    z-index: 20;
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
}

.nav-label {
    margin: 0.85rem 0 0.25rem;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.nav-label:first-child { margin-top: 0; }

.side-nav a {
    color: var(--muted);
    padding: 0.42rem 0.7rem;
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.92rem;
}

.side-nav a.is-active,
.side-nav a:hover {
    color: var(--text);
    background: var(--bg-soft);
    text-decoration: none;
}

.side-search {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.75rem 0.15rem 0.9rem;
    border-bottom: 1px solid var(--line);
}

.side-search-actions {
    display: flex;
    gap: 0.4rem;
}

.side-search-actions .btn {
    flex: 1;
    text-align: center;
}

.sidebar-user {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--line);
}

.topbar {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.02em;
    text-decoration: none;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background:
        linear-gradient(135deg, var(--accent), #f0d09a 45%, var(--accent-2));
    box-shadow: 0 0 0 3px rgba(212, 160, 86, 0.15);
}

.nav { display: none; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.user-pill {
    font-size: 0.85rem;
    color: var(--muted);
    padding: 0.25rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 999px;
}

.nav-toggle {
    display: none;
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.35rem 0.6rem;
}

.page {
    width: min(1080px, calc(100% - 2rem));
    margin: 1.5rem auto 3rem;
    flex: 1;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

h1 { font-size: 1.75rem; margin: 0 0 0.2rem; letter-spacing: -0.03em; }
h2 { font-size: 1.05rem; margin: 0 0 0.85rem; }
.lede { margin: 0; color: var(--muted); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.55rem 0.95rem;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    background: var(--bg-soft);
}

.btn:hover { text-decoration: none; filter: brightness(1.08); }

.btn-primary {
    background: linear-gradient(180deg, #e2b56b, var(--accent));
    color: #1a1208;
    font-weight: 700;
}

.btn-secondary {
    background: rgba(62, 207, 178, 0.16);
    border-color: rgba(62, 207, 178, 0.35);
    color: #d7fff6;
}

.btn-ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--muted);
}

.btn-danger {
    background: rgba(226, 109, 109, 0.12);
    border-color: rgba(226, 109, 109, 0.35);
    color: #ffd4d4;
}

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.field-grow { flex: 1; min-width: 180px; }
.field-full { grid-column: 1 / -1; }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: #0c1118;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(212, 160, 86, 0.45);
    outline-offset: 1px;
}

.filters, .form-card, .panel, .entry-card, .stat-card, .empty-state, .login-panel {
    background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%), var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.search-stack { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }

.search-bar {
    display: flex;
    gap: 0.6rem;
    align-items: stretch;
    padding: 0.85rem 1rem;
    background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%), var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.search-bar input[type="search"] {
    flex: 1;
    min-width: 0;
    font-size: 1.05rem;
    padding: 0.7rem 0.9rem;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem;
    align-items: flex-end;
}

.filter-actions { display: flex; gap: 0.5rem; }

.result-meta { color: var(--muted); font-size: 0.9rem; }

.entry-list { display: flex; flex-direction: column; gap: 0.85rem; }

.entry-card {
    display: grid;
    grid-template-columns: 180px 1fr auto;
    gap: 1rem;
    padding: 1rem 1.1rem;
}

.entry-when {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.92rem;
}

.entry-body h2 { margin: 0 0 0.35rem; font-size: 1.12rem; }
.entry-body h2 a { color: var(--text); }
.entry-body p { margin: 0 0 0.7rem; color: #c9c3b6; }

.entry-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.entry-actions { display: flex; flex-direction: column; gap: 0.4rem; align-items: stretch; }

.badge, .pill, .tag, .ticket {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.12rem 0.55rem;
    font-size: 0.75rem;
}

.badge-server {
    background: rgba(62, 207, 178, 0.12);
    color: #9cf0de;
    width: fit-content;
}

.pill { border: 1px solid var(--line); }
.pill-cat { background: rgba(255,255,255,0.04); }
.cat-aggiornamento { color: #8ecbff; }
.cat-config { color: #d2c4ff; }
.cat-installazione { color: #9cf0de; }
.cat-fix { color: #ffd18c; }
.cat-backup { color: #b7d4ff; }
.cat-sicurezza { color: #ffb3c0; }
.cat-altro { color: var(--muted); }

.st-completato { background: rgba(125, 206, 154, 0.15); color: #b6f0c8; }
.st-in_corso { background: rgba(212, 160, 86, 0.16); color: #f3d19a; }
.st-da_verificare { background: rgba(142, 203, 255, 0.14); color: #c5e3ff; }
.st-rollback { background: rgba(226, 109, 109, 0.16); color: #ffc4c4; }

.tag { background: #0c1118; color: var(--muted); border: 1px solid var(--line); }
.ticket { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }

.empty-state, .form-card { padding: 1.4rem; }
.empty-state { text-align: center; }
.empty-state p { color: var(--muted); }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1.2rem;
    flex-wrap: wrap;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--line);
}
.flash-ok { background: rgba(125, 206, 154, 0.12); color: #c8f5d6; }
.flash-error { background: rgba(226, 109, 109, 0.12); color: #ffd0d0; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.stat-card { padding: 1rem 1.1rem; }
.stat-card strong { display: block; font-size: 1.8rem; letter-spacing: -0.04em; }
.stat-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-card em { display: block; color: var(--muted); font-style: normal; font-size: 0.8rem; }
.stat-warn strong { color: #ffb4b4; }

.dash-cols {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1.2fr;
    gap: 0.85rem;
    margin-bottom: 0.85rem;
}

.panel { padding: 1.1rem; }

.legend-list, .bar-list, .recent-list { list-style: none; margin: 0; padding: 0; }
.legend-list li, .recent-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--line);
}
.recent-list li { justify-content: flex-start; flex-wrap: wrap; }
.recent-list time { color: var(--muted); width: 140px; font-size: 0.85rem; }
.recent-list a { color: var(--text); flex: 1; }

.bar-list li { padding: 0.45rem 0; }
.bar-head { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 0.25rem; }
.bar {
    height: 7px;
    background: #0c1118;
    border-radius: 99px;
    overflow: hidden;
}
.bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.export-strip {
    margin-top: 1.4rem;
    display: flex;
    gap: 0.8rem;
    align-items: center;
    color: var(--muted);
}

.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
    padding: 1rem;
    border-top: 1px solid var(--line);
}

.muted { color: var(--muted); }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 20% 20%, rgba(212,160,86,0.16), transparent 28%),
        radial-gradient(circle at 80% 80%, rgba(62,207,178,0.12), transparent 30%),
        var(--bg);
}

.login-wrap { width: min(420px, calc(100% - 2rem)); }
.login-panel { padding: 1.6rem; }
.login-brand { margin-bottom: 1.2rem; }
.login-brand h1 { margin: 0.7rem 0 0.2rem; }
.login-brand p { margin: 0; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }

.check-inline {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    grid-column: 1 / -1;
    color: var(--muted);
}

.dropzone {
    border: 1px dashed rgba(232, 214, 180, 0.28);
    border-radius: 12px;
    padding: 0.9rem;
    background: #0c1118;
    outline: none;
}

.dropzone.is-hot {
    border-color: var(--accent-2);
    background: rgba(62, 207, 178, 0.08);
}

.dropzone p { margin: 0 0 0.45rem; }

.attach-existing, .attach-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    list-style: none;
    margin: 0.6rem 0 0;
    padding: 0;
}

.attach-item, .attach-preview li {
    width: 140px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.attach-item img, .attach-preview img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
}

.attach-file { font-size: 0.8rem; word-break: break-all; }

.server-table-wrap { margin-top: 1rem; overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.data-table th, .data-table td {
    text-align: left;
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.data-table .is-inactive td { color: var(--muted); }

.form-grid.compact {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.comment-list {
    list-style: none;
    margin: 0 0 1.2rem;
    padding: 0;
}

.comment-list li {
    border-bottom: 1px solid var(--line);
    padding: 0.8rem 0;
}

.comment-list header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.comment-list p { margin: 0.4rem 0 0; white-space: pre-wrap; }

.comments-panel { margin-top: 1rem; }

@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .mobile-bar { display: flex; }
    .nav-toggle { display: inline-flex; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.is-open { transform: translateX(0); }
    .entry-card, .form-grid, .stat-grid, .dash-cols, .form-grid.compact {
        grid-template-columns: 1fr;
    }
    .entry-actions { flex-direction: row; }
}
