:root {
    --bg: #0f1216;
    --panel: #171b21;
    --border: #262c35;
    --text: #e6e9ee;
    --muted: #8a93a2;
    --accent: #4f9dff;
    --ok: #3ecf8e;
    --danger: #e5534b;
    --warn: #e5b93e;
}
* { box-sizing: border-box; }
body {
    margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg); color: var(--text); padding: 20px;
}
.wrap { max-width: 1000px; margin: 0 auto; }
h1 { font-size: 22px; }
.sub { color: var(--muted); font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.card h2 { font-size: 14px; margin: 0 0 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="number"], select, textarea {
    width: 100%; background: #0d1014; border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 10px; color: var(--text); font-size: 14px; font-family: inherit;
}
.row { display: flex; gap: 12px; margin-bottom: 12px; }
.row > div { flex: 1; }
button {
    background: var(--accent); color: #fff; border: none; border-radius: 6px;
    padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--border); }
.badge.on { background: rgba(62,207,142,.15); color: var(--ok); }
.badge.off { background: rgba(90,97,110,.2); color: var(--muted); }

/* Riga "a pillola" per elenchi principali (Azioni, ecc.): bordo arrotondato,
   sfondo leggermente diverso quando aperta/attiva, badge di stato pieni. */
.pill-row-summary {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    flex-wrap: wrap; cursor: pointer; list-style: none; padding: 12px 16px;
    border-radius: 999px; background: #12161c; border: 1px solid var(--border);
    transition: background .15s, border-color .15s;
}
.pill-row-summary:hover { border-color: var(--accent); }
details[open] > .pill-row-summary {
    background: rgba(79,157,255,.12); border-color: var(--accent);
}
.pill-badge {
    display: inline-block; padding: 4px 14px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.pill-badge.on { background: var(--ok); color: #06301f; }
.pill-badge.off { background: #3a4150; color: var(--muted); }
.search-pill {
    width: 100%; background: #0d1014; border: 1px solid var(--border); border-radius: 999px;
    padding: 11px 18px; color: var(--text); font-size: 14px; font-family: inherit;
}
.search-pill:focus { outline: none; border-color: var(--accent); }
.chip { display: inline-block; background: var(--border); border-radius: 6px; padding: 2px 8px; font-size: 12px; margin: 2px 4px 2px 0; }
.hidden { display: none; }
.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--panel); border: 1px solid var(--border); color: var(--text);
    padding: 10px 18px; border-radius: 8px; font-size: 13px;
    opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.err { border-color: var(--danger); color: var(--danger); }
.login-box { text-align: center; padding: 60px 20px; }
.login-box .google-btn {
    display: inline-block; background: #fff; color: #222; padding: 12px 24px; border-radius: 30px;
    font-weight: 600; text-decoration: none; border: none; cursor: pointer;
}
.login-box .google-btn:hover { background: #e6e6e6; }
.tab-btn { padding: 8px 16px; background: transparent; border: none; color: var(--muted); cursor: pointer; font-weight: 600; }
.tab-btn.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.panel { display: none; }
.panel.active { display: block; }
.mono { font-family: ui-monospace, monospace; }
code { background: #0d1014; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.count { background: var(--border); border-radius: 999px; padding: 1px 8px; font-size: 11px; margin-left: 4px; }

/* MENU */
.menu-container {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
}
.menu-group { position: relative; }
.menu-toggle {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}
.menu-toggle:hover { background: var(--border); color: var(--text); }
.menu-toggle.active { background: var(--accent); color: #fff; }
.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 0;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.menu-dropdown.open { display: block; }
.menu-item {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 8px 16px;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}
.menu-item:hover { background: var(--border); }
.menu-item.active { background: var(--accent); color: #fff; }
.menu-item.disabled { opacity: 0.4; pointer-events: none; }

/* BARRA LATERALE: quando .menu-container ha id="sidebar", si comporta come
   colonna fissa a sinistra invece che riga orizzontale in alto — stesse
   identiche classi (.menu-group/.menu-toggle/.menu-dropdown/.menu-item) di
   sopra, menu.js non sa (né deve sapere) che il layout è cambiato. */
.app-shell { display: flex; align-items: flex-start; gap: 20px; }
#sidebar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    width: 230px;
    flex-shrink: 0;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    transition: width .18s ease;
}
#sidebar.collapsed { width: 56px; overflow: visible; }
.sidebar-collapse-btn {
    background: transparent; border: none; color: var(--muted); cursor: pointer;
    font-size: 18px; padding: 6px 10px; text-align: left; border-radius: 6px; margin-bottom: 6px;
}
.sidebar-collapse-btn:hover { background: var(--border); color: var(--text); }
#sidebar .menu-group { width: 100%; }
#sidebar .menu-toggle { width: 100%; text-align: left; white-space: nowrap; overflow: hidden; }
#sidebar.collapsed .menu-toggle { text-overflow: clip; }
/* Dentro la sidebar il "dropdown" non è più un overlay assoluto: si espande
   inline sotto la voce, a fisarmoica verticale. */
#sidebar .menu-dropdown {
    position: static; box-shadow: none; min-width: 0; width: 100%;
    padding-left: 8px; margin-top: 2px;
}
#sidebar .menu-item { padding-left: 22px; white-space: nowrap; overflow: hidden; }
/* Compressa: la colonna si restringe, il testo viene tagliato dall'overflow
   (l'emoji iniziale di ogni voce resta visibile anche così) — il dropdown
   resta comunque accessibile al click, si apre come overlay a fianco. */
#sidebar.collapsed .menu-dropdown { min-width: 200px; position: absolute; left: 100%; top: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); padding: 6px 0; }
.main-area { flex: 1; min-width: 0; }
.panels-container .panel { display: none; }
.panels-container .panel.active { display: block; }
