/* Tema dell'interfaccia (palette "Stormy morning": #384959 #6A89A7 #88BDF2 #BDDDFC), giorno e notte.
   La newsletter in anteprima non cambia: resta com'è nell'email. */
:root {
    color-scheme: light;
    --slate: #384959;
    --steel: #6A89A7;
    --sky: #88BDF2;
    --mist: #BDDDFC;

    --bg: #eef3f8;
    --surface: #ffffff;
    --surface-2: #f6f9fc;
    --surface-3: #e7eef6;
    --border: #d7e1eb;
    --border-strong: #b9c9d8;
    --text: #22303d;
    --text-2: #445668;
    --muted: #5d7891;

    --primary: #384959;
    --primary-hover: #2a3744;
    --on-primary: #ffffff;
    --accent: #88BDF2;
    --accent-strong: #2f6cab;
    --accent-soft: #e4f0fd;
    --on-accent: #10233a;

    --header-bg: #384959;
    --header-text: #ffffff;
    --header-muted: #BDDDFC;
    --header-btn: rgba(255, 255, 255, 0.10);
    --header-btn-hover: rgba(255, 255, 255, 0.18);
    --header-btn-border: rgba(255, 255, 255, 0.18);

    --success: #2e9867;
    --danger: #c64545;
    --danger-soft: #fbecec;
    --warning-soft: #fff5d9;
    --warning-border: #ecd28e;
    --warning-text: #775600;

    --radius: 10px;
    --radius-sm: 7px;
    --shadow-sm: 0 1px 2px rgba(34, 48, 61, 0.06), 0 1px 3px rgba(34, 48, 61, 0.08);
    --shadow-md: 0 8px 24px rgba(34, 48, 61, 0.14);
    --shadow-lg: 0 20px 50px rgba(20, 30, 40, 0.28);
    --focus: 0 0 0 3px rgba(136, 189, 242, 0.6);
    --overlay: rgba(25, 35, 45, 0.45);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #12181f;
    --surface: #1b242e;
    --surface-2: #212c37;
    --surface-3: #2a3644;
    --border: #2e3b49;
    --border-strong: #42546a;
    --text: #e3ecf5;
    --text-2: #b6c6d6;
    --muted: #8ea8c1;

    --primary: #88BDF2;
    --primary-hover: #a6cff7;
    --on-primary: #0f2134;
    --accent: #88BDF2;
    --accent-strong: #9fcbf5;
    --accent-soft: rgba(136, 189, 242, 0.14);
    --on-accent: #0f2134;

    --header-bg: #0e141a;
    --header-text: #e3ecf5;
    --header-muted: #8ea8c1;
    --header-btn: rgba(255, 255, 255, 0.06);
    --header-btn-hover: rgba(255, 255, 255, 0.12);
    --header-btn-border: rgba(255, 255, 255, 0.12);

    --success: #4cc28c;
    --danger: #ef7474;
    --danger-soft: rgba(239, 116, 116, 0.13);
    --warning-soft: rgba(242, 200, 100, 0.12);
    --warning-border: rgba(242, 200, 100, 0.35);
    --warning-text: #f0d080;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);
    --overlay: rgba(0, 0, 0, 0.6);
}

/* Base */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}
h3 { color: var(--text); font-weight: 650; letter-spacing: -0.01em; }
input, select, textarea, button { font-family: inherit; }
input, select, textarea {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
label { color: var(--text-2); font-weight: 600; }
:focus-visible { outline: none; box-shadow: var(--focus); }
::placeholder { color: var(--muted); opacity: 0.8; }
.hint { font-size: 11px; color: var(--muted); }

/* Icone SVG (sprite in editor.php) */
.ic { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-lg { width: 20px; height: 20px; }
.ic-xl { width: 44px; height: 44px; stroke-width: 1.5; }

/* Pulsanti: base = secondario; varianti primario / successo / pericolo / fantasma */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary, .btn-success { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover, .btn-success:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); filter: brightness(1.08); }
:root[data-theme="dark"] .btn-danger { color: #2a0d0d; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 28px; padding: 0 10px; font-size: 12px; }

/* Pulsante solo icona */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0;
    border: none; border-radius: var(--radius-sm);
    background: transparent; color: var(--muted);
    cursor: pointer; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }

/* Intestazione */
.header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 0 18px;
    height: 60px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 4px 16px rgba(0, 0, 0, 0.08);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 9px;
    background: linear-gradient(135deg, var(--sky), var(--steel));
    color: #10233a;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--header-muted); min-width: 0; }
.crumbs .crumb-sep { opacity: 0.5; }
.crumbs .crumb-project { color: var(--header-text); font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header .btn { background: var(--header-btn); border-color: var(--header-btn-border); color: var(--header-text); box-shadow: none; }
.header .btn:hover { background: var(--header-btn-hover); }
.header .btn-primary { background: var(--sky); border-color: var(--sky); color: #10233a; }
.header .btn-primary:hover { background: var(--mist); border-color: var(--mist); }
.header .icon-btn { color: var(--header-muted); width: 34px; height: 34px; }
.header .icon-btn:hover { background: var(--header-btn-hover); color: var(--header-text); }
.header-sep { width: 1px; height: 24px; background: var(--header-btn-border); margin: 0 4px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--header-muted); }
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--steel); color: #fff; font-size: 12px; font-weight: 700;
}

/* Barra laterale progetti */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); }
.sidebar-section { border-bottom: 1px solid var(--border); }
.sidebar-title { color: var(--muted); letter-spacing: 0.06em; font-size: 11px; }
.proj-view-tabs { border: none; background: var(--surface-3); padding: 3px; border-radius: var(--radius-sm); gap: 3px; }
.proj-view-tabs button { border-radius: 5px; background: transparent; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.proj-view-tabs button + button { border-left: none; }
.proj-view-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.search-field { position: relative; }
.search-field .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 32px; }
.folder-head { color: var(--text-2); }
.folder-head .caret { width: 14px; display: inline-flex; color: var(--muted); }
.folder-head .caret .ic { width: 14px; height: 14px; transition: transform 0.15s; }
.folder-group.collapsed .folder-head .caret .ic { transform: rotate(-90deg); }
.folder-head .folder-ic { color: var(--steel); display: inline-flex; }
.project-item {
    background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 8px 8px 8px 10px; position: relative;
}
.project-item:hover { background: var(--surface-2); border-color: var(--border); }
.project-item.active { background: var(--accent-soft); border-color: transparent; }
.project-item.active::before {
    content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent);
}
.project-item .proj-title { color: var(--text); font-weight: 600; }
.menu-btn { color: var(--muted); display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; }
.menu-btn:hover, .menu-btn[aria-expanded="true"] { background: var(--surface-3); color: var(--text); }

/* Menu contestuale */
.project-menu { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-md); border-radius: var(--radius); padding: 5px; }
.project-menu button { display: flex; align-items: center; gap: 9px; border-radius: 6px; color: var(--text); padding: 7px 10px; }
.project-menu button .ic { color: var(--muted); }
.project-menu button:hover { background: var(--surface-3); }
.project-menu button.current, .project-menu button.current .ic { color: var(--accent-strong); }
.project-menu button.danger, .project-menu button.danger .ic { color: var(--danger); }
.project-menu button.danger:hover { background: var(--danger-soft); }
.project-menu .menu-label { padding: 8px 10px 3px; letter-spacing: 0.05em; }

/* Colonna centrale e schede */
.editor-section { background: var(--surface); }
.editor-tabs { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 12px; gap: 2px; }
.tab-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 14px 12px 12px; color: var(--muted); font-weight: 600; font-size: 13px;
    border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-btn.active .ic { color: var(--accent-strong); }
.editor-content { background: var(--surface); }
.no-project-state { color: var(--muted); }
.no-project-state .ic-xl { color: var(--steel); margin-bottom: 4px; }
.no-project-state h3 { font-size: 18px; }
.archived-banner { background: var(--warning-soft); border-bottom-color: var(--warning-border); color: var(--warning-text); }
.archived-banner .btn { background: var(--surface); border-color: var(--warning-border); color: var(--text); }

/* Righe */
.rows-list { gap: 8px; }
.row-item {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 10px 10px 6px; box-shadow: var(--shadow-sm);
}
.row-item:hover { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.row-item.active { background: var(--accent-soft); border-color: var(--accent); }
.row-thumb { width: 104px; height: 58px; border-color: var(--border); border-radius: var(--radius-sm); background: var(--surface-3); }
.row-thumb-text { color: var(--muted); }
.row-thumb-text .ic { width: 22px; height: 22px; }
.row-label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.row-label .ic { width: 13px; height: 13px; }
.row-content { color: var(--text); font-weight: 500; font-size: 13px; margin-top: 2px; }
.row-actions { gap: 2px; opacity: 0.75; transition: opacity 0.15s; }
.row-item:hover .row-actions, .row-item.active .row-actions { opacity: 1; }
.drag-handle { color: var(--border-strong); margin-right: 4px; display: inline-flex; cursor: grab; }
.row-item:hover .drag-handle { color: var(--muted); }
.vis-badge { background: var(--accent-soft); color: var(--accent-strong); text-transform: none; letter-spacing: 0; display: inline-flex; align-items: center; gap: 3px; }
.vis-badge .ic { width: 11px; height: 11px; }

/* Pulsanti piccoli dell'editor (stili, colonne, modalità) */
.style-btn { background: var(--surface); color: var(--text-2); border-color: var(--border); border-radius: var(--radius-sm); display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.style-btn:hover { background: var(--surface-3); }
.style-btn.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* Selettore dispositivo (segmentato) */
.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: var(--radius-sm); background: var(--surface-3); }
.seg .btn { min-height: 28px; padding: 0 10px; border: none; box-shadow: none; background: transparent; color: var(--text-2); }
.seg .btn:hover { background: var(--surface); }
.seg .btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.device-btn.active { background: var(--surface); color: var(--text); }
.device-tag { color: var(--accent-strong); }

/* Anteprima */
.preview-section { background: var(--bg); border-left: none; }
.preview-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
    font-weight: 650; font-size: 14px; color: var(--text);
}
.preview-head .title { display: flex; align-items: center; gap: 8px; }
.preview-head .title .ic { color: var(--steel); }
.preview-head .tools { display: flex; align-items: center; gap: 8px; }
#previewFrame { border-radius: 4px; box-shadow: var(--shadow-md) !important; }
.pane-splitter { background: var(--border); width: 5px; }
.pane-splitter:hover, body.resizing-panes .pane-splitter { background: var(--accent); }

/* Popup */
.modal-overlay { background: var(--overlay); backdrop-filter: blur(2px); }
.modal { background: var(--surface); color: var(--text); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal-header, .modal-footer { border-color: var(--border); padding: 14px 20px; }
.modal-header h3 { display: flex; align-items: center; gap: 9px; font-size: 16px; }
.modal-header h3 .ic { color: var(--steel); }
.modal-close { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); color: var(--muted); }
.modal-close:hover { background: var(--surface-3); color: var(--text); }
.modal-footer { background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* Aree di rilascio, libreria, colonne, PDF */
.drop-zone { border-color: var(--border-strong); background: var(--surface-2); border-radius: var(--radius); }
.drop-zone .ic-lg { color: var(--steel); }
.drop-zone.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.lib-item { border-color: var(--border); background: var(--surface); border-radius: var(--radius); }
.lib-item .lib-meta { color: var(--text-2); }
.lib-item.selectable:hover { border-color: var(--accent); }
.col-bar { border-color: var(--border-strong); border-radius: var(--radius-sm); }
.col-seg { background: var(--surface-2); border-right-color: var(--border-strong); color: var(--text-2); }
.col-seg.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.col-divider::after { background: var(--accent); }
.column-edit-head { border-top-color: var(--accent); }
.pdf-side { border-left-color: var(--border); }
.color-swatch { box-shadow: 0 0 0 1px var(--border-strong); border-color: var(--surface); }
.color-swatch.active { box-shadow: 0 0 0 2px var(--accent-strong); }

/* Gestione utenti (super admin) */
.users-btn { position: relative; }
.count-badge {
    position: absolute; top: 1px; right: 0;
    min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
    background: #e5484d; color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
    box-shadow: 0 0 0 2px var(--header-bg);
}
.count-badge[hidden] { display: none; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.users-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr.is-pending td { background: var(--accent-soft); }
.users-table .u-name { font-weight: 600; color: var(--text); }
.users-table .u-email, .users-table .u-date { color: var(--muted); font-size: 12px; }
.users-table .u-actions { text-align: right; white-space: nowrap; }
.users-table .u-actions .btn + .btn { margin-left: 6px; }
.status-pill { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.status-pending { background: var(--warning-soft); color: var(--warning-text); border: 1px solid var(--warning-border); }
.status-active { background: var(--accent-soft); color: var(--accent-strong); }
.status-disabled { background: var(--surface-3); color: var(--muted); }
.btn-danger-soft { color: var(--danger); }
.btn-danger-soft:hover { background: var(--danger-soft); border-color: var(--danger); }

/* Pulsante giorno/notte: mostra l'icona del tema che si attiva */
.theme-toggle .ic-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ic-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .ic-moon { display: none; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
