:root {
    /* Light theme colors - Material Design 3 */
    --md-primary: #2D3748;
    --md-on-primary: #FFFFFF;
    --md-primary-container: #D1E4FF;
    --md-on-primary-container: #001D35;
    --md-surface: #FFFFFF;
    --md-surface-rgb: 255, 255, 255;
    --md-surface-variant: #E7E0EC;
    --md-on-surface: #1E1F22;
    --md-on-surface-variant: #49454F;
    --md-background: #F2F4F7;
    --md-scaffold-background: #F2F4F7;
    --md-outline: #79747E;
    --md-outline-variant: #CAC4D0;
    
    /* Dark theme colors */
    --md-dark-primary: #9BB5D1;
    --md-dark-on-primary: #1A2332;
    --md-dark-primary-container: #3A4A5F;
    --md-dark-on-primary-container: #D1E4FF;
    --md-dark-surface: #23252B;
    --md-dark-surface-variant: #49454F;
    --md-dark-on-surface: #E6E1E5;
    --md-dark-on-surface-variant: #CAC4D0;
    --md-dark-background: #1E1F22;
    --md-dark-scaffold-background: #1E1F22;
    --md-dark-outline: #938F99;
    --md-dark-outline-variant: #49454F;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--md-scaffold-background);
    color: var(--md-on-surface);
    height: 100vh;
    overflow: hidden;
}

body.login-page,
body.upgrade-page {
    overflow: auto;
}

body.theme-dark {
    --md-primary: var(--md-dark-primary);
    --md-on-primary: var(--md-dark-on-primary);
    --md-primary-container: var(--md-dark-primary-container);
    --md-on-primary-container: var(--md-dark-on-primary-container);
    --md-surface: var(--md-dark-surface);
    --md-surface-rgb: 28, 27, 31;
    --md-surface-variant: var(--md-dark-surface-variant);
    --md-on-surface: var(--md-dark-on-surface);
    --md-on-surface-variant: var(--md-dark-on-surface-variant);
    --md-background: var(--md-dark-background);
    --md-scaffold-background: var(--md-dark-scaffold-background);
    --md-outline: var(--md-dark-outline);
    --md-outline-variant: var(--md-dark-outline-variant);
}

body.theme-dark .toolbar,
body.theme-dark .binder-pane,
body.theme-dark .inspector-pane,
body.theme-dark .editor-header,
body.theme-dark .footer {
    border-color: rgba(255, 255, 255, 0.1);
}

body.theme-dark .toolbar-button:hover,
body.theme-dark .icon-button:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

body.theme-dark .binder-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Context Menu */
.context-menu {
    position: fixed;
    z-index: 1000;
}

.context-menu-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--md-on-surface);
    font-size: 14px;
}

.context-menu-item .material-icons {
    font-size: 18px;
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    width: 18px;
    height: 18px;
    vertical-align: middle;
    flex-shrink: 0;
    font-feature-settings: 'liga' off;
}

.context-menu-item:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

body.theme-dark .context-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.context-menu-separator {
    height: 1px;
    background-color: var(--md-outline-variant);
    margin: 4px 0;
}

.context-menu-item-danger {
    color: #B3261E;
}

body.theme-dark .context-menu-item-danger {
    color: #F2B8B5;
}

.context-menu-item-danger:hover {
    background-color: rgba(179, 38, 30, 0.08);
}

body.theme-dark .context-menu-item-danger:hover {
    background-color: rgba(242, 184, 181, 0.12);
}

/* Icon Picker */
.icon-picker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.settings-dialog {
    background-color: var(--md-surface);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.icon-picker-dialog {
    background-color: var(--md-surface);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.icon-picker-button {
    width: 48px;
    height: 48px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 12px;
    background-color: var(--md-surface-variant);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    position: relative;
}

.icon-picker-button:hover {
    background-color: var(--md-primary-container);
    border-color: var(--md-primary);
}

.icon-picker-button .material-icons {
    font-size: 22px;
    color: var(--md-on-surface-variant);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    width: 22px;
    height: 22px;
    text-align: center;
    vertical-align: middle;
    font-feature-settings: 'liga' off;
}

.icon-picker-button:hover .material-icons {
    color: var(--md-primary);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Toolbar */
.toolbar {
    height: 65px;
    background-color: var(--md-surface);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    position: relative;
    z-index: 100;
}

/* Toolbar in modalità focus: fixed e sovrapposta */
.app-container.focus-mode .toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Toolbar nascosta in modalità focus: non occupa spazio */
.app-container.focus-mode .toolbar.toolbar-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

/* Compensa lo spazio della toolbar quando è nascosta in modalità focus */
.app-container.focus-mode .main-content {
    margin-top: 0;
}

.toolbar-logo {
    height: 50px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
    margin-left: 8px;
}

.toolbar-title {
    flex: 1;
    font-size: 20px;
    font-weight: 600;
    color: var(--md-on-surface);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.toolbar-title:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.toolbar-title.editing {
    background-color: transparent;
}

.toolbar-title input {
    border: none;
    outline: none;
    background: transparent;
    font-size: 20px;
    font-weight: 600;
    color: var(--md-on-surface);
    width: 300px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.toolbar-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--md-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

body.theme-dark .toolbar-button {
    color: var(--md-on-surface-variant);
}

.toolbar-button:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.avatar-container {
    position: relative;
}

.sidebar-avatar-container {
    display: none;
    position: relative;
    padding: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    margin-top: auto;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--md-primary-container);
    color: var(--md-on-primary-container);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.avatar:hover {
    transform: scale(1.05);
}

.avatar-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    display: none;
    flex-direction: column;
    z-index: 1000;
    animation: slideDown 0.2s ease;
    overflow: hidden;
}

.avatar-menu.show {
    display: flex;
}

.avatar-menu-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--md-outline-variant);
}

.avatar-menu-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--md-on-surface);
    margin-bottom: 4px;
}

.avatar-menu-email {
    font-size: 12px;
    color: var(--md-on-surface-variant);
}

.avatar-menu-divider {
    height: 1px;
    background-color: var(--md-outline-variant);
    margin: 4px 0;
}

.avatar-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--md-on-surface);
    font-size: 14px;
    text-align: left;
    transition: background-color 0.2s;
    width: 100%;
}

.avatar-menu-item:hover {
    background-color: var(--md-surface-variant);
}

.avatar-menu-item .material-icons {
    font-size: 20px;
    color: var(--md-on-surface-variant);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Binder Pane */
.binder-pane {
    width: 260px;
    flex: 0 0 260px;
    background-color: var(--md-surface);
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.binder-header {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.binder-header .material-icons {
    font-size: 16px;
    color: var(--md-primary);
}

.binder-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.1px;
    color: var(--md-on-surface);
    cursor: text;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
    outline: none;
    min-width: 0;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
    max-height: 60px;
    overflow-y: auto;
}

.binder-title:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.binder-title:focus {
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    max-height: none;
    overflow-y: visible;
}

.binder-actions-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 8px;
    flex-shrink: 0;
    gap: 8px;
    /*border: 1px solid var(--md-outline-variant);*/
    /*border-radius: 8px;*/
    /*margin: 8px 12px;*/
    background-color: var(--md-surface);
}

.sidebar-toolbar-actions {
    display: none;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
}

.sidebar-toolbar-actions .view-button {
    background-color: var(--md-on-primary);
    color: var(--md-primary);
    border: none;
    border-radius: 8px;
    padding: 6px;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.sidebar-toolbar-actions .view-button:hover {
    background-color: var(--md-primary-container);
    opacity: 0.9;
}

.sidebar-toolbar-actions .view-button .material-icons {
    font-size: 18px;
}

.binder-actions {
    display: flex;
    justify-content: center;
    flex: 1;
}

.binder-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    /*padding: 8px 0;*/
    width: 100%;
}

.binder-list > * {
    width: 100%;
    display: block;
}

.binder-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    padding-left: calc(8px + var(--depth, 0) * 14px);
    cursor: pointer;
    transition: background-color 0.2s, border-left 0.2s;
    position: relative;
    min-height: 32px;
    width: 100%;
    box-sizing: border-box;
    border-left: 3px solid transparent;
}

.binder-item.dragging {
    opacity: 0.4;
}

.binder-item:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.binder-item.selected {
    background-color: rgba(45, 55, 72, 0.12);
}

.binder-item.selected:hover {
    background-color: rgba(45, 55, 72, 0.16);
}

.binder-item .material-icons:first-of-type {
    font-size: 16px;
    color: var(--md-on-surface-variant);
    margin-right: 6px;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    vertical-align: middle;
    font-feature-settings: 'liga' off;
}

.binder-item.selected .material-icons:first-of-type {
    color: var(--md-primary);
}

.binder-item-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--md-on-surface);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    display: block;
}

.binder-item.folder .binder-item-title {
    font-weight: 600;
}

/* Il testo del cestino non è selezionabile */
.binder-item[data-entry-id="trash"] .binder-item-title {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Badge contatore per il cestino */
.binder-item-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    line-height: 1;
}

.binder-item .expand-button {
    flex-shrink: 0;
    margin-left: 4px;
    margin-right: 4px;
    width: 28px;
    height: 28px;
}

.binder-item-children {
    width: 100%;
    display: block;
}

.binder-item-actions {
    display: flex;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s;
    margin-left: auto;
}

.binder-item:hover .binder-item-actions {
    opacity: 1;
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    width: 28px;
    height: 28px;
}

.icon-button:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.icon-button:disabled:hover {
    background-color: transparent;
}

.icon-button.active {
    background-color: var(--md-primary-container);
    color: var(--md-primary);
}

.icon-button.active:hover {
    background-color: var(--md-primary-container);
    opacity: 0.9;
}

.expand-button {
    width: 28px;
    height: 28px;
    padding: 0;
}

.expand-icon {
    transition: transform 0.16s;
}

.expand-icon.expanded {
    transform: rotate(90deg);
}

/* Editor Area */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: flex 0.2s;
}

/* Pulsanti discreti per sidebar e inspector */
.sidebar-toggle-btn,
.inspector-toggle-btn {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background-color: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover,
.inspector-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

body.theme-dark .sidebar-toggle-btn:hover,
body.theme-dark .inspector-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.sidebar-toggle-btn .material-icons,
.inspector-toggle-btn .material-icons {
    font-size: 18px;
    color: var(--md-on-surface-variant);
    transition: color 0.2s;
}

.sidebar-toggle-btn:hover .material-icons,
.inspector-toggle-btn:hover .material-icons {
    color: var(--md-on-surface);
}

/* Stato attivo per i pulsanti */
.sidebar-toggle-btn.active,
.inspector-toggle-btn.active {
    background-color: var(--md-primary-container);
}

.sidebar-toggle-btn.active .material-icons,
.inspector-toggle-btn.active .material-icons {
    color: var(--md-primary);
}

/* Nascondi pulsanti in modalità focus */
.app-container.focus-mode .sidebar-toggle-btn,
.app-container.focus-mode .inspector-toggle-btn {
    display: none;
}

/* Quando il secondo editor o il browser è visibile, il primo editor occupa il 50% dello spazio rimanente */
.main-content.has-split-editor .editor-area,
.main-content.has-browser .editor-area {
    flex: 0 0 calc((100% - 260px - 280px) / 2);
    min-width: 0;
}

/* Quando l'inspector è nascosto, gli editor si espandono */
.main-content.inspector-hidden.has-split-editor .editor-area,
.main-content.inspector-hidden.has-browser .editor-area {
    flex: 0 0 calc((100% - 260px) / 2);
}

/* Quando la sidebar è nascosta, gli editor si espandono */
.main-content.sidebar-hidden.has-split-editor .editor-area,
.main-content.sidebar-hidden.has-browser .editor-area {
    flex: 0 0 calc((100% - 280px) / 2);
}

/* Quando sia sidebar che inspector sono nascosti, gli editor occupano tutto lo spazio */
.main-content.sidebar-hidden.inspector-hidden.has-split-editor .editor-area,
.main-content.sidebar-hidden.inspector-hidden.has-browser .editor-area {
    flex: 0 0 50%;
}

/* Assicura che l'inspector rimanga sempre visibile */
.inspector-pane {
    flex: 0 0 280px;
    min-width: 0;
}

/* Modalità focus - concentrazione */
.app-container.focus-mode .main-content {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.app-container.focus-mode .main-content.has-split-editor,
.app-container.focus-mode .main-content.has-browser {
    max-width: 100%;
    margin: 0;
}

.app-container.focus-mode .editor-area {
    max-width: 100%;
}

.app-container.focus-mode .main-content.has-split-editor .editor-area,
.app-container.focus-mode .main-content.has-browser .editor-area {
    flex: 0 0 calc(50% - 8px);
}

.app-container.focus-mode .editor-content {
    max-width: 1000px;
    margin: 0 auto;
    padding: 10px 60px;
}

.app-container.focus-mode .main-content.has-split-editor .editor-content,
.app-container.focus-mode .main-content.has-browser .editor-content {
    max-width: 100%;
    padding: 16px 24px;
}

.app-container.focus-mode .editor-content .ql-editor {
    font-size: 18px;
    line-height: 1.8;
    max-width: 100%;
    padding: 24px 32px;
}

.app-container.focus-mode .main-content.has-split-editor .editor-content .ql-editor,
.app-container.focus-mode .main-content.has-browser .editor-content .ql-editor {
    font-size: 16px;
    line-height: 1.5;
    padding: 24px 32px;
}

.app-container.focus-mode .editor-header {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.app-container.focus-mode .main-content.has-split-editor .editor-area .editor-header,
.app-container.focus-mode .main-content.has-browser .editor-area .editor-header {
    max-width: 100%;
    margin: 0;
}

.app-container.focus-mode .split-editor {
    flex: 0 0 calc(50% - 8px);
}

.app-container.focus-mode .browser-pane {
    flex: 0 0 calc(50% - 8px);
}

.editor-header {
    background-color: var(--md-surface);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    padding: 8px 20px;
    height: 40px;
    box-sizing: border-box;
}

/* Quando ci sono due editor o editor+browser, torna a layout a colonne */
.main-content.has-split-editor .editor-area .editor-header,
.main-content.has-browser .editor-area .editor-header {
    flex-direction: column;
    height: auto;
    padding: 0;
}

.main-content.has-split-editor .editor-title-row,
.main-content.has-browser .editor-title-row,
.main-content.has-split-editor .split-editor .editor-title-row,
.main-content.has-browser .split-editor .editor-title-row {
    padding: 8px 20px !important;
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    overflow: hidden !important;
}

/* Allinea anche editor-title-container quando ci sono due editor */
.main-content.has-split-editor .editor-title-container,
.main-content.has-browser .editor-title-container,
.main-content.has-split-editor .split-editor .editor-title-container,
.main-content.has-browser .split-editor .editor-title-container {
    min-height: auto;
    height: auto;
}

.main-content.has-split-editor .editor-actions,
.main-content.has-browser .editor-actions,
.main-content.has-split-editor .split-editor .editor-actions,
.main-content.has-browser .split-editor .editor-actions {
    padding: 6px 20px !important;
    min-height: 44px !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex-wrap: wrap !important;
}

.editor-title-row {
    padding: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    position: relative;
    height: 40px;
    box-sizing: border-box;
}

.editor-title-row #close-split {
    margin-left: auto;
    width: 24px;
    height: 24px;
    padding: 0;
    flex-shrink: 0;
}

.editor-title-row #close-split .material-icons {
    font-size: 18px;
    color: rgb(141, 6, 6);
}

.editor-title-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
}

.split-editor .editor-title-container {
    min-height: 38px;
}

.split-editor .editor-header {
    padding: 8px 20px;
    height: 40px;
    background-color: var(--md-surface);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* Quando ci sono due editor, anche il secondo editor-header deve avere padding 0 e layout a colonne */
.main-content.has-split-editor .split-editor .editor-header,
.main-content.has-browser .split-editor .editor-header {
    padding: 0 !important;
    height: auto !important;
    flex-direction: column !important;
}

.split-editor .editor-title-row {
    padding: 0;
    flex: 1;
    min-width: 0;
    height: 40px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
}


.split-editor .editor-actions {
    padding: 0;
    gap: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

.editor-actions {
    padding: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.editor-icon {
    font-size: 20px;
    color: var(--md-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    vertical-align: middle;
    font-feature-settings: 'liga' off;
}

.editor-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--md-on-surface);
    cursor: pointer;
}

.editor-title input {
    border: 1px solid var(--md-outline-variant);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 22px;
    font-weight: 600;
    outline: none;
    background-color: var(--md-surface);
    color: var(--md-on-surface);
}


.zoom-control {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    border-left: 1px solid var(--md-outline-variant);
    margin-left: 4px;
    padding-left: 8px;
}

.zoom-value {
    font-size: 12px;
    font-weight: 500;
    color: var(--md-on-surface-variant);
    min-width: 40px;
    text-align: center;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--md-outline-variant);
    border-radius: 8px;
    overflow: hidden;
}

.view-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    min-width: 32px;
    height: 32px;
}

.view-button.active {
    background-color: var(--md-primary);
    color: var(--md-on-primary);
}

.binder-actions .view-button {
    background-color: var(--md-on-primary);
    color:  var(--md-primary);
}

.view-button .material-icons {
    font-size: 16px;
}

.editor-actions .icon-button .material-icons {
    font-size: 18px;
}

.view-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.view-button:disabled:hover {
    background-color: transparent;
}

.editor-content .ql-toolbar {
    position: sticky;
    top: 40px; /* Altezza header: 40px (stessa riga) */
    z-index: 15;
}

/* Quando ci sono due editor o editor+browser, aggiorna il top del ql-toolbar */
.main-content.has-split-editor .editor-content .ql-toolbar,
.main-content.has-browser .editor-content .ql-toolbar {
    top: 100px; /* Altezza header: 40px (title-row) + 44px (actions) + padding = ~100px */
}

.editor-content .ql-toolbar {
    background-color: var(--md-surface);
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 8px;
    max-width: 100%;
}


.editor-content {
    flex: 1;
    background-color: var(--md-scaffold-background);
    padding: 16px 24px;
    position: relative;
}

.editor-content .ql-container {
    background-color: var(--md-surface);
    border: none;
    border-radius: 8px;
    margin-top: 8px;
}

.editor-content .ql-editor {
    min-height: 400px;
    padding: 24px 32px;
    font-size: 17px;
    line-height: 1.7;
    font-family: 'Georgia', 'Times New Roman', serif;
}

/* Allineamento giustificato di default per i paragrafi */
.editor-content .ql-editor p {
    text-align: justify;
}

.editor-content #quill-editor,
.editor-content #quill-editor-secondary,
#split-editor-content #quill-editor-secondary {
    min-height: 400px;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--md-on-surface);
    font-size: 18px;
}

/* Inspector Pane */
.inspector-pane {
    width: 280px;
    background-color: var(--md-surface);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.inspector-header {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 16px;
    font-weight: 600;
}

.inspector-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.inspector-section {
    margin-bottom: 16px;
}

.inspector-section-title {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--md-on-surface-variant);
    margin-bottom: 8px;
}

.inspector-section-content {
    font-size: 14px;
    color: var(--md-on-surface);
}

/* Footer */
.footer {
    height: 36px;
    background-color: var(--md-surface);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 12px;
}

.footer-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--md-on-surface-variant);
    flex: 1;
}

.footer-info .material-icons {
    font-size: 16px;
}

.footer-status {
    font-size: 12px;
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Split Editor */
.split-editor {
    flex: 0 0 calc((100% - 260px - 280px) / 2);
    min-width: 0;
    background-color: var(--md-scaffold-background);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    isolation: isolate;
}

/* Quando l'inspector è nascosto, il secondo editor si espande */
.main-content.inspector-hidden.has-split-editor .split-editor {
    flex: 0 0 calc((100% - 260px) / 2);
}

/* Quando la sidebar è nascosta, il secondo editor si espande */
.main-content.sidebar-hidden.has-split-editor .split-editor {
    flex: 0 0 calc((100% - 280px) / 2);
}

/* Quando sia sidebar che inspector sono nascosti */
.main-content.sidebar-hidden.inspector-hidden.has-split-editor .split-editor {
    flex: 0 0 50%;
}

.split-editor .editor-header {
    position: sticky;
    top: 0;
    z-index: 20;
}

.split-editor .ql-toolbar {
    position: sticky;
    /*top: 100px; /* Altezza header: 40px (title-row) + 44px (actions) + padding = ~100px */
    z-index: 15;
    background-color: var(--md-surface);
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 8px;
    max-width: 100%;
}

#split-editor-content {
    flex: 1;
    background-color: var(--md-scaffold-background);
    padding: 16px 24px;
    position: relative;
}

/* Browser Pane */
.browser-pane {
    flex: 0 0 calc((100% - 260px - 280px) / 2);
    min-width: 0;
    background-color: var(--md-scaffold-background);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    isolation: isolate;
}

/* Quando l'inspector è nascosto, il browser si espande */
.main-content.inspector-hidden.has-browser .browser-pane {
    flex: 0 0 calc((100% - 260px) / 2);
}

/* Quando la sidebar è nascosta, il browser si espande */
.main-content.sidebar-hidden.has-browser .browser-pane {
    flex: 0 0 calc((100% - 280px) / 2);
}

/* Quando sia sidebar che inspector sono nascosti */
.main-content.sidebar-hidden.inspector-hidden.has-browser .browser-pane {
    flex: 0 0 50%;
}

.browser-pane .editor-header {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-shrink: 0;
    flex-direction: row !important;
    align-items: center !important;
    padding: 8px 16px !important;
    gap: 8px !important;
    height: auto !important;
    flex-wrap: nowrap !important;
}

.browser-pane .editor-header .icon-button {
    flex-shrink: 0;
}

.browser-url {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    background-color: var(--md-surface);
    color: var(--md-on-surface);
    min-width: 0;
}

.browser-frame {
    flex: 1;
    border: none;
    background-color: white;
    min-height: 0;
}

/* Corkboard */
.corkboard {
    padding: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    min-height: 100%;
    position: relative;
    align-content: flex-start;
}

.corkboard-card {
    width: 180px;
    height: 250px;
    background-color: var(--md-surface);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    cursor: grab;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    position: relative;
}

.corkboard-card-nested {
    background-color: var(--md-surface-variant);
    border-left: 3px solid var(--md-primary);
    opacity: 0.95;
}

.corkboard-nested-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 5px solid var(--md-primary);
    opacity: 0.6;
    z-index: 1;
}

.corkboard-card:hover {
    transform: translateY(-2px);
}

.corkboard-card:active {
    cursor: grabbing;
}

.corkboard-card.corkboard-drag-over {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.corkboard-card.corkboard-can-drop-inside {
    box-shadow: 0 0 0 2px var(--md-primary);
    background-color: var(--md-primary-container);
    transform: scale(1.02);
}

.corkboard-drop-indicator {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--md-primary);
    border-radius: 2px;
    z-index: 10;
    pointer-events: none;
}

.corkboard-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.corkboard-card-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.corkboard-card-synopsis {
    font-size: 12px;
    color: var(--md-on-surface-variant);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

/* Search Dialog */
.search-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.search-dialog-content {
    background-color: var(--md-surface);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
    width: 90%;
    max-width: 600px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.search-input-container {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--md-outline-variant);
    gap: 12px;
}

.search-icon {
    color: var(--md-on-surface-variant);
    font-size: 24px;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;
    color: var(--md-on-surface);
    padding: 8px 0;
}

.search-input::placeholder {
    color: var(--md-on-surface-variant);
}

.search-close {
    background: var(--md-surface-container-high);
    border: 1px solid var(--md-outline-variant);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-on-surface);
    transition: all 0.2s;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.search-close:hover {
    background-color: var(--md-surface-container);
    border-color: var(--md-outline);
}

.search-close .material-icons {
    font-size: 20px;
}

.search-input-container .search-clear-btn {
    margin-right: 8px;
    background: transparent;
    border: none;
}

.search-input-container .search-clear-btn:hover {
    background-color: var(--md-surface-container-high);
}

.search-results-container {
    flex: 1;
    overflow-y: auto;
    min-height: 200px;
    max-height: calc(70vh - 140px);
}

.search-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    gap: 16px;
    color: var(--md-on-surface-variant);
    text-align: center;
}

.search-empty-state .material-icons {
    font-size: 48px;
    opacity: 0.5;
}

.search-results-list {
    display: flex;
    flex-direction: column;
}

.search-result-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--md-outline-variant);
    cursor: pointer;
    transition: background-color 0.2s;
}

.search-result-item:hover,
.search-result-item.active {
    background-color: var(--md-surface-variant);
}

.search-result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.search-result-title {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    color: var(--md-on-surface);
}

.search-result-type {
    font-size: 11px;
    color: var(--md-on-surface-variant);
    background-color: var(--md-surface-variant);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-result-path {
    font-size: 11px;
    color: var(--md-on-surface-variant);
    margin-bottom: 4px;
    opacity: 0.7;
}

.search-result-snippet {
    font-size: 13px;
    color: var(--md-on-surface-variant);
    line-height: 1.5;
    margin-top: 4px;
}

.search-result-snippet mark {
    background-color: var(--md-primary-container);
    color: var(--md-on-primary-container);
    padding: 2px 0;
    border-radius: 2px;
    font-weight: 500;
}

.search-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--md-outline-variant);
    background-color: var(--md-surface-variant);
}

.search-count {
    font-size: 12px;
    color: var(--md-on-surface-variant);
}

.search-navigation {
    display: flex;
    gap: 4px;
}

.search-nav-button {
    background: none;
    border: 1px solid var(--md-outline-variant);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-on-surface);
    transition: all 0.2s;
}

.search-nav-button:hover {
    background-color: var(--md-primary-container);
    border-color: var(--md-primary);
    color: var(--md-on-primary-container);
}

.search-nav-button .material-icons {
    font-size: 18px;
}

/* Login Page */
.login-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: linear-gradient(135deg, var(--md-primary-container) 0%, var(--md-surface) 100%);
}

body.theme-dark .login-background {
    background: linear-gradient(135deg, var(--md-dark-primary-container) 0%, var(--md-dark-surface) 100%);
}

#falling-letters-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

.theme-toggle-login {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 100;
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.theme-toggle-login:hover {
    background-color: var(--md-primary-container);
    border-color: var(--md-primary);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-toggle-login .material-icons {
    font-size: 24px;
    color: var(--md-primary);
    transition: transform 0.3s;
}

body.theme-dark .theme-toggle-login .material-icons {
    color: var(--md-on-surface);
}

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    pointer-events: none;
}

.login-card {
    background-color: var(--md-surface);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    width: 100%;
    max-width: 420px;
    padding: 40px;
    animation: slideUp 0.3s ease;
    position: relative;
    pointer-events: auto;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    height: 64px;
    width: auto;
    margin-bottom: 16px;
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    color: #5F5B66;
    margin-bottom: 8px;
}

body.theme-dark .login-title {
    color: var(--md-on-surface-variant);
}

.login-subtitle {
    font-size: 14px;
    color: #5F5B66;
}

body.theme-dark .login-subtitle {
    color: var(--md-on-surface-variant);
}

.login-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--md-outline-variant);
}

.login-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-on-surface-variant);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.login-tab.active {
    color: var(--md-primary);
    border-bottom-color: var(--md-primary);
}

.login-tab:hover:not(.active) {
    color: var(--md-on-surface);
}

.login-content {
    position: relative;
    min-height: 300px;
}

.login-form {
    display: none;
    flex-direction: column;
    gap: 20px;
}

.login-form.active {
    display: flex;
}

.form-row {
    display: flex;
    gap: 16px;
    width: 100%;
}

.form-row .form-group {
    flex: 1;
    min-width: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #49454F;
}

body.theme-dark .form-group label {
    color: var(--md-on-surface-variant);
}

.form-input {
    padding: 12px 16px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 8px;
    font-size: 14px;
    color: #49454F;
    background-color: var(--md-surface);
    transition: border-color 0.2s;
    font-family: inherit;
}

body.theme-dark .form-input {
    color: var(--md-on-surface-variant);
}

.form-input:focus {
    outline: none;
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(45, 55, 72, 0.1);
}

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--md-on-surface-variant);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--md-primary);
}

.checkbox-label a {
    color: var(--md-primary);
    text-decoration: none;
}

.checkbox-label a:hover {
    text-decoration: underline;
}

.forgot-password {
    color: var(--md-primary);
    text-decoration: none;
    font-size: 13px;
    cursor: pointer;
}

.forgot-password:hover {
    text-decoration: underline;
}

/* Forgot Password Dialog */
.forgot-password-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.forgot-password-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.forgot-password-content {
    position: relative;
    background: var(--md-surface);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
    z-index: 1;
}

.forgot-password-header {
    padding: 24px;
    border-bottom: 1px solid var(--md-outline-variant);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.forgot-password-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: var(--md-on-surface);
}

.forgot-password-close {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--md-on-surface-variant);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.forgot-password-close:hover {
    background: var(--md-surface-variant);
}

.forgot-password-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.forgot-password-body p {
    margin: 0 0 20px 0;
    color: var(--md-on-surface-variant);
    font-size: 14px;
    line-height: 1.5;
}

.forgot-password-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--md-outline-variant);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
}

.btn-secondary {
    padding: 10px 24px;
    border: 1px solid var(--md-outline-variant);
    background: transparent;
    color: var(--md-on-surface);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: var(--md-surface-variant);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: var(--md-primary);
    color: var(--md-on-primary);
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Roboto', sans-serif;
    white-space: nowrap;
    height: 40px;
    box-sizing: border-box;
}

.btn-primary .material-icons {
    font-size: 18px;
}

.btn-primary:hover {
    background-color: var(--md-primary);
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Login Footer */
.login-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 20px 24px;
    pointer-events: none;
}

.login-footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 13px;
    color: rgba(95, 91, 102, 0.7);
}

body.theme-dark .login-footer-content {
    color: rgba(230, 225, 229, 0.6);
}

.login-footer-link {
    color: rgba(95, 91, 102, 0.8);
    text-decoration: none;
    transition: all 0.2s;
    pointer-events: auto;
}

body.theme-dark .login-footer-link {
    color: rgba(230, 225, 229, 0.7);
}

.login-footer-link:hover {
    color: var(--md-primary);
    text-decoration: underline;
}

.login-footer-separator {
    opacity: 0.5;
    font-weight: 300;
}

.login-footer-author {
    font-weight: 500;
    opacity: 0.8;
}

/* Timeline Styles */
.timeline-container {
    padding: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.timeline-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at center, rgba(45, 55, 72, 0.08) 0%, transparent 70%),
        linear-gradient(to right, 
            transparent 0%, 
            rgba(45, 55, 72, 0.03) 48%, 
            rgba(45, 55, 72, 0.03) 52%, 
            transparent 100%);
    pointer-events: none;
    z-index: 0;
}

body.theme-dark .timeline-container::before {
    background: 
        radial-gradient(ellipse at center, rgba(232, 230, 227, 0.08) 0%, transparent 70%),
        linear-gradient(to right, 
            transparent 0%, 
            rgba(232, 230, 227, 0.03) 48%, 
            rgba(232, 230, 227, 0.03) 52%, 
            transparent 100%);
}

.timeline-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    position: relative;
    z-index: 1;
}

.timeline-visual {
    position: relative;
    padding: 40px 0;
}

.timeline-year-item {
    position: relative;
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    min-height: 60px;
}

.timeline-year-item > div:last-child {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.timeline-entry-card {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.timeline-associations {
    width: 100%;
}

.timeline-year-icon {
    transition: all 0.2s;
}

.timeline-year-icon:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Responsive */
@media (max-width: 1024px) {
    .binder-pane {
        position: fixed;
        left: 0;
        top: 56px;
        height: calc(100vh - 56px);
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease-out;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
        will-change: transform;
    }
    
    .binder-pane.open {
        transform: translateX(0);
    }
    
    .inspector-pane {
        position: fixed;
        right: 0;
        top: 56px;
        height: calc(100vh - 56px);
        width: 280px;
        max-width: 85vw;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.3s ease-out;
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
        will-change: transform;
        display: flex;
        flex-direction: column;
    }
    
    .inspector-pane.mobile-open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .editor-area {
        flex: 1;
    }
    
    /* Quando il secondo editor è aperto su schermi piccoli, nascondilo */
    .main-content.has-split-editor .split-editor {
        display: none;
    }
    
    .main-content.has-split-editor .editor-area {
        flex: 1;
    }
    
    .editor-content {
        padding: 16px 12px;
    }
    
    #split-editor-content {
        padding: 16px 12px;
    }
    
    /* In mobile, editor-header torna a flex-direction: column */
    .editor-header {
        flex-direction: column;
        height: auto;
        padding: 0;
    }
    
    .editor-title-row {
        padding: 8px 20px;
        height: 40px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }
    
    .editor-actions {
        padding: 6px 20px;
        min-height: 44px;
    }
    
    .split-editor .editor-header {
        flex-direction: column;
        height: auto;
        padding: 0;
    }
    
    .split-editor .editor-title-row {
        padding: 8px 20px;
        height: 40px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }
    
    .split-editor .editor-actions {
        padding: 6px 20px;
        min-height: 44px;
    }
    
    .toolbar-button#binder-toggle {
        display: flex !important;
    }
    
    /* Centra il logo nella toolbar su mobile */
    .toolbar {
        justify-content: space-between;
    }
    
    .toolbar-logo {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }
    
    /* Nascondi sidebar-toggle-btn nel footer su mobile */
    .footer .sidebar-toggle-btn {
        display: none;
    }
    
    /* Nascondi toolbar-actions nella toolbar su mobile (incluso avatar) */
    .toolbar-actions {
        display: none;
    }
    
    /* Mostra sidebar-toolbar-actions nella sidebar su mobile */
    .sidebar-toolbar-actions {
        display: flex;
    }
    
    /* Mostra binder-actions-container su mobile */
    .binder-actions-container {
        display: flex;
    }
    
    /* Mostra sidebar-avatar-container nella sidebar su mobile */
    .sidebar-avatar-container {
        display: flex;
    }
    
    /* Posiziona il menu dell'avatar correttamente nella sidebar (si apre verso l'alto) */
    .sidebar-avatar-container .avatar-menu {
        right: 12px;
        left: 12px;
        top: auto;
        bottom: calc(100% + 8px);
        min-width: auto;
        width: calc(100% - 24px);
    }
}

/* Overlay per chiudere sidebar e inspector quando sono aperti su mobile */
@media (max-width: 1024px) {
    .binder-pane.open::after {
        content: '';
        position: fixed;
        top: 56px;
        left: 260px;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.3);
        z-index: 99;
        opacity: 0;
        animation: fadeInOverlay 0.3s ease-out 0.1s forwards;
        pointer-events: auto;
    }
    
    .inspector-pane.mobile-open::before {
        content: '';
        position: fixed;
        top: 56px;
        left: 0;
        right: 280px;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.3);
        z-index: 99;
        opacity: 0;
        animation: fadeInOverlay 0.3s ease-out 0.1s forwards;
        pointer-events: auto;
    }
    
    @keyframes fadeInOverlay {
        from {
            opacity: 0;
        }
        to {
            opacity: 1;
        }
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    border: 3px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.3);
}

body.theme-dark ::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
}

body.theme-dark ::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Quill Toolbar - Tema Scuro */
body.theme-dark .ql-toolbar.ql-snow {
    background-color: var(--md-surface);
    border-color: rgba(255, 255, 255, 0.1);
}

body.theme-dark .ql-container.ql-snow {
    border-color: rgba(255, 255, 255, 0.1);
}

body.theme-dark .ql-editor {
    color: var(--md-on-surface);
    font-family: 'Georgia', 'Times New Roman', serif;
}

body.theme-dark .ql-editor.ql-blank::before {
    color: rgba(255, 255, 255, 0.5);
}

body.theme-dark .ql-toolbar svg {
    fill: var(--md-on-surface);
    stroke: var(--md-on-surface);
}

body.theme-dark .ql-toolbar button,
body.theme-dark .ql-toolbar .ql-picker-label {
    color: var(--md-on-surface);
}

body.theme-dark .ql-toolbar button:hover,
body.theme-dark .ql-toolbar .ql-picker-label:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

body.theme-dark .ql-toolbar button.ql-active,
body.theme-dark .ql-toolbar .ql-picker-label.ql-active,
body.theme-dark .ql-toolbar .ql-picker-item.ql-selected {
    background-color: rgba(255, 255, 255, 0.12);
    color: var(--md-primary);
}

body.theme-dark .ql-toolbar button.ql-active svg,
body.theme-dark .ql-toolbar .ql-picker-label.ql-active svg,
body.theme-dark .ql-toolbar .ql-picker-item.ql-selected svg {
    fill: var(--md-primary);
    stroke: var(--md-primary);
}

body.theme-dark .ql-toolbar .ql-picker-options {
    background-color: var(--md-surface-container-high);
    border-color: rgba(255, 255, 255, 0.2);
}

body.theme-dark .ql-toolbar .ql-picker-item {
    color: var(--md-on-surface);
}

body.theme-dark .ql-toolbar .ql-picker-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

body.theme-dark .ql-snow .ql-stroke {
    stroke: var(--md-on-surface);
}

body.theme-dark .ql-snow .ql-stroke.ql-fill {
    fill: var(--md-on-surface);
}

body.theme-dark .ql-snow .ql-fill {
    fill: var(--md-on-surface);
}

body.theme-dark .ql-toolbar button.ql-active .ql-stroke,
body.theme-dark .ql-toolbar .ql-picker-label.ql-active .ql-stroke {
    stroke: var(--md-primary);
}

body.theme-dark .ql-toolbar button.ql-active .ql-fill,
body.theme-dark .ql-toolbar .ql-picker-label.ql-active .ql-fill {
    fill: var(--md-primary);
}

body.theme-dark .ql-snow a {
    color: var(--md-primary);
}

body.theme-dark .ql-editor span.internal-link {
    color: var(--md-primary);
}

/* Modal per link interni */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background-color: var(--md-surface);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    margin: auto;
    position: relative;
    overflow: hidden;
}

/* Padding di default quando il modal-content non ha header/body/footer */
.modal-content > *:not(.modal-header):not(.modal-body):not(.modal-footer) {
    padding: 24px;
}

/* Assicura che il contenuto diretto sia ben allineato */
.modal-content > *:first-child:not(.modal-header) {
    padding-top: 24px;
}

.modal-content > *:last-child:not(.modal-footer) {
    padding-bottom: 24px;
}

@media (max-width: 600px) {
    .modal-overlay {
        padding: 16px;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: calc(100vh - 32px);
        border-radius: 12px;
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--md-outline-variant);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 60px;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--md-on-surface);
    line-height: 1.4;
}

.modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--md-outline-variant);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--md-outline);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--md-outline-variant);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
    background-color: var(--md-surface-container-low);
}

@media (max-width: 600px) {
    .modal-header {
        padding: 16px 20px;
        min-height: 56px;
    }
    
    .modal-header h3 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 20px;
        gap: 12px;
    }
    
    .modal-footer {
        padding: 12px 20px;
        flex-direction: column-reverse;
    }
    
    .modal-footer button {
        width: 100%;
    }
}

.modal-search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.modal-search {
    width: 100%;
    padding: 8px 40px 8px 12px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    background-color: var(--md-surface);
    color: var(--md-on-surface);
}

.modal-search:focus {
    border-color: var(--md-primary);
}

.modal-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.modal-document-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
}

.modal-document-list::-webkit-scrollbar {
    width: 8px;
}

.modal-document-list::-webkit-scrollbar-track {
    background: transparent;
}

.modal-document-list::-webkit-scrollbar-thumb {
    background: var(--md-outline-variant);
    border-radius: 4px;
}

.modal-document-list::-webkit-scrollbar-thumb:hover {
    background: var(--md-outline);
}

.modal-document-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    transition: background-color 0.2s;
}

.modal-document-item:hover {
    background-color: var(--md-surface-container-high);
}

body.theme-dark .modal-document-item:hover {
    background-color: var(--md-surface-container);
}

.modal-document-item .material-icons {
    color: var(--md-primary);
    font-size: 20px;
    flex-shrink: 0;
}

.modal-document-info {
    flex: 1;
    min-width: 0;
}

.modal-document-item .document-name {
    font-weight: 500;
    display: block;
}

.modal-document-item .document-path {
    font-size: 12px;
    color: var(--md-on-surface-variant);
    margin-top: 2px;
    display: block;
}

/* Stile per link interni nell'editor */
a[href^="scrivener://"] {
    color: var(--md-primary);
    text-decoration: underline;
    cursor: pointer;
}

a[href^="scrivener://"]:hover {
    background-color: rgba(66, 133, 244, 0.1);
}

/* Pulsante link interno nella toolbar Quill */
.ql-internal-link {
    width: 28px !important;
    height: 24px !important;
}

.ql-internal-link .material-icons {
    font-size: 18px !important;
}

/* Pulsante AI assistant nella toolbar Quill */
.ql-ai-assistant {
    width: 28px !important;
    height: 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--md-on-surface);
}

.ql-ai-assistant:hover {
    background: var(--md-surface-container-high) !important;
}

.ql-ai-assistant .material-icons {
    font-size: 18px !important;
}

/* Menu operazioni AI */
.ai-menu {
    font-family: 'Roboto', sans-serif;
}

.ai-menu-option {
    transition: background-color 0.2s, color 0.2s;
}

.ai-menu-option:hover {
    background-color: var(--md-primary-container) !important;
    color: var(--md-on-primary-container) !important;
}

.ai-menu-option:hover .material-icons {
    color: var(--md-on-primary-container) !important;
}

/* Loading indicator AI */
.ai-loading-indicator {
    color: var(--md-on-surface);
}

.ai-loading-indicator .material-icons {
    color: var(--md-primary);
}

/* Dialog risultato AI */
.ai-result-dialog {
    color: var(--md-on-surface);
}

.ai-result-dialog h3 {
    color: var(--md-on-surface);
}

.ai-dialog-btn-secondary {
    transition: background-color 0.2s, border-color 0.2s;
}

.ai-dialog-btn-secondary:hover {
    background-color: var(--md-surface-container-high) !important;
}

.ai-dialog-btn-replace,
.ai-dialog-btn-insert {
    transition: background-color 0.2s, opacity 0.2s;
}

.ai-dialog-btn-replace:hover,
.ai-dialog-btn-insert:hover {
    opacity: 0.9;
    background-color: var(--md-primary) !important;
}

/* Dark theme specific styles */
body.theme-dark .ai-menu {
    background: var(--md-surface);
    border-color: var(--md-outline-variant);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

body.theme-dark .ai-loading-indicator {
    background: var(--md-surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

body.theme-dark .ai-result-dialog {
    background: var(--md-surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Light theme specific styles */
body.theme-light .ai-menu {
    background: var(--md-surface);
    border-color: var(--md-outline-variant);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.theme-light .ai-loading-indicator {
    background: var(--md-surface);
}

body.theme-light .ai-result-dialog {
    background: var(--md-surface);
}

body.theme-dark .ai-result-dialog .ai-dialog-btn-secondary:hover {
    background-color: var(--md-surface-container-high) !important;
}

/* Stili per confronto prima/dopo nel dialog AI */
.ai-result-dialog [style*="flex: 1; display: flex"] {
    scrollbar-width: thin;
    scrollbar-color: var(--md-outline-variant) transparent;
}

.ai-result-dialog [style*="flex: 1; display: flex"]::-webkit-scrollbar {
    width: 8px;
}

.ai-result-dialog [style*="flex: 1; display: flex"]::-webkit-scrollbar-track {
    background: transparent;
}

.ai-result-dialog [style*="flex: 1; display: flex"]::-webkit-scrollbar-thumb {
    background-color: var(--md-outline-variant);
    border-radius: 4px;
}

.ai-result-dialog [style*="flex: 1; display: flex"]::-webkit-scrollbar-thumb:hover {
    background-color: var(--md-outline);
}

/* Animazione spin per loading indicator */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Stile per gli span dei link interni */
.ql-editor span.internal-link {
    color: var(--md-primary);
    text-decoration: underline;
    cursor: pointer;
    transition: opacity 0.2s;
}

.ql-editor span.internal-link:hover {
    opacity: 0.7;
}

body.theme-dark .modal-overlay {
    background-color: rgba(0, 0, 0, 0.7);
}

body.theme-dark .modal-content {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    background-color: var(--md-surface);
}

body.theme-dark .modal-header {
    border-bottom-color: var(--md-outline-variant);
}

body.theme-dark .modal-footer {
    background-color: var(--md-surface-container-low);
    border-top-color: var(--md-outline-variant);
}

body.theme-dark .modal-document-item:hover {
    background-color: var(--md-surface-container);
}

/* Modal Cover Viewer */
.modal-cover-viewer {
    max-width: 90vw;
    max-height: 90vh;
    padding: 0;
    background: transparent;
    width: auto;
    height: auto;
    overflow: visible;
}

.modal-cover-container {
    position: relative;
    background: var(--md-surface);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    max-height: 90vh;
}

.modal-cover-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-cover-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

.modal-cover-image {
    max-width: 90vw;
    max-height: 90vh;
    display: block;
    object-fit: contain;
    width: auto;
    height: auto;
}

body.theme-dark .modal-cover-container {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

@media (max-width: 600px) {
    .modal-cover-viewer {
        max-width: 95vw;
        max-height: 95vh;
    }
    
    .modal-cover-container {
        max-width: 95vw;
        max-height: 95vh;
        border-radius: 12px;
    }
    
    .modal-cover-image {
        max-width: 95vw;
        max-height: 95vh;
    }
    
    .modal-cover-close {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
    }
}

/* ============================================
   PROJECTS PAGE
   ============================================ */

.projects-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--md-surface-container-low);
    position: relative;
    overflow-x: hidden;
}

.projects-page #falling-letters-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.projects-header {
    background-color: rgba(var(--md-surface-rgb), 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--md-outline-variant);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.projects-header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.projects-logo {
    height: 40px;
    width: auto;
}

.projects-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.projects-main {
    flex: 1;
    padding: 40px 24px;
    position: relative;
    z-index: 2;
}

.projects-container {
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

.projects-title-section {
    margin-bottom: 32px;
}

.projects-title {
    font-size: 32px;
    font-weight: 600;
    color: #2c2c2c;
    margin: 0 0 8px 0;
}

body.theme-dark .projects-title {
    color: #e8eaed;
}

.projects-subtitle {
    font-size: 16px;
    color: #5f6368;
    margin: 0;
}

body.theme-dark .projects-subtitle {
    color: #9aa0a6;
}

.projects-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .projects-actions-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

.projects-search {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: 24px;
    padding: 8px 16px;
    flex: 1;
    max-width: 400px;
}

.projects-search .material-icons {
    color: var(--md-on-surface-variant);
    font-size: 20px;
}

.projects-search-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--md-on-surface);
    font-size: 14px;
    flex: 1;
    font-family: 'Roboto', sans-serif;
}

.search-clear-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-on-surface-variant);
    transition: all 0.2s;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.search-clear-btn:hover {
    background-color: var(--md-surface-container-high);
    color: var(--md-on-surface);
}

.search-clear-btn .material-icons {
    font-size: 18px;
}

.projects-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.projects-filter-btn,
.projects-sort-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: 24px;
    color: var(--md-on-surface);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Roboto', sans-serif;
    white-space: nowrap;
    height: 40px;
    box-sizing: border-box;
}

.projects-filter-btn:hover,
.projects-sort-btn:hover {
    background-color: var(--md-surface-container-high);
    border-color: var(--md-outline);
}

.projects-filter-btn.active,
.projects-sort-btn.active {
    background-color: var(--md-primary-container);
    border-color: var(--md-primary);
    color: var(--md-on-primary-container);
}

.projects-filter-btn .material-icons,
.projects-sort-btn .material-icons {
    font-size: 18px;
}

/* Filter and Sort Dropdown */
.filter-dropdown,
.sort-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    padding: 8px;
    min-width: 200px;
    z-index: 1000;
    display: none;
}

.filter-dropdown.show,
.sort-dropdown.show {
    display: block;
}

.filter-option,
.sort-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s;
    color: var(--md-on-surface);
    font-size: 14px;
}

.filter-option:hover,
.sort-option:hover {
    background-color: var(--md-surface-container-high);
}

.filter-option.active,
.sort-option.active {
    background-color: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.filter-option .material-icons,
.sort-option .material-icons {
    font-size: 18px;
}

.projects-actions {
    position: relative;
}

/* Projects Grid */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    position: relative;
    z-index: 5;
}

.project-card {
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: 16px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

.project-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    border-color: var(--md-primary);
}

body.theme-dark .project-card:hover {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.project-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    margin-bottom: 16px;
    position: relative;
    z-index: 10;
}

.project-card-cover-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: -20px -20px 20px -20px;
    padding: 0;
    position: relative;
}

.project-card-cover {
    width: 140px;
    height: 200px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 8px;
    position: relative;
    cursor: default;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.project-card:hover .project-card-cover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.theme-dark .project-card-cover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.theme-dark .project-card:hover .project-card-cover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.4);
}

.project-card-cover-placeholder {
    background: linear-gradient(135deg, var(--md-surface-container-high) 0%, var(--md-surface-container) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--md-outline-variant);
}

.project-card-cover-placeholder .project-card-icon {
    width: 64px;
    height: 64px;
    background: var(--md-surface-container-high);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-primary);
    font-size: 32px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body.theme-dark .project-card-cover-placeholder .project-card-icon {
    background: linear-gradient(135deg, var(--md-primary) 0%, var(--md-secondary) 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}


.project-card-menu {
    opacity: 0;
    transition: opacity 0.2s;
}

.project-card:hover .project-card-menu {
    opacity: 1;
}

.project-card-menu-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--md-on-surface-variant);
    transition: all 0.2s;
}

.project-card-menu-btn:hover {
    background-color: var(--md-surface-container-high);
    color: var(--md-on-surface);
}

.project-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    text-align: center;
}

.project-card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--md-on-surface);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

.project-card-description {
    font-size: 14px;
    color: var(--md-on-surface-variant);
    line-height: 1.6;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 42px;
}

.project-card-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--md-outline-variant);
    align-items: center;
    text-align: center;
}

.project-card-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--md-on-surface-variant);
    justify-content: center;
}

.project-card-info-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.project-card-info-item .material-icons {
    font-size: 18px;
    opacity: 0.7;
}

.project-card-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.project-card-badge {
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.project-card-badge-template {
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
}

.project-card-badge-genre {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

/* Empty State */
.projects-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.projects-empty-icon {
    font-size: 80px;
    color: var(--md-on-surface-variant);
    opacity: 0.5;
    margin-bottom: 24px;
}

.projects-empty-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--md-on-surface);
    margin: 0 0 12px 0;
}

.projects-empty-text {
    font-size: 16px;
    color: var(--md-on-surface-variant);
    margin: 0 0 32px 0;
}

/* Modal Project */
.modal-project {
    max-width: 500px;
    width: 90%;
}

.modal-project .form-group {
    margin-bottom: 20px;
}

.modal-project .form-group:last-of-type {
    margin-bottom: 0;
}

.modal-project label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-on-surface);
    margin-bottom: 8px;
}

.modal-project .form-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 8px;
    background-color: var(--md-surface);
    color: var(--md-on-surface);
    font-size: 14px;
    font-family: 'Roboto', sans-serif;
    transition: all 0.2s;
}

.modal-project .form-input:focus {
    outline: none;
    border-color: var(--md-primary);
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.1);
}

.modal-project textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

.genre-input-container {
    position: relative;
}

.genre-input-container select,
.genre-input-container input {
    width: 100%;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

.btn-secondary {
    padding: 10px 24px;
    background-color: transparent;
    border: 1px solid var(--md-outline);
    border-radius: 20px;
    color: var(--md-on-surface);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Roboto', sans-serif;
}

.btn-secondary:hover {
    background-color: var(--md-surface-container-high);
}

/* Project Options Modal */
.modal-project-options {
    max-width: 300px;
    width: 90%;
}

.project-option-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 8px;
    color: var(--md-on-surface);
}

.project-option-item:hover {
    background-color: var(--md-surface-container-high);
}

.project-option-item.danger {
    color: var(--md-error);
}

.project-option-item.danger:hover {
    background-color: rgba(179, 38, 30, 0.1);
}

.project-option-item .material-icons {
    font-size: 20px;
}

.project-option-divider {
    height: 1px;
    background-color: var(--md-outline-variant);
    margin: 8px 0;
}

/* Dark Theme */
body.theme-dark.projects-page {
    background-color: #1c1b1f;
}

body.theme-dark .projects-header {
    background-color: rgba(var(--md-surface-rgb), 0.95);
}

/*
body.theme-dark .projects-main {
    background-color: #1c1b1f;
}*/

body.theme-dark .project-card:hover {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
}

/* Auth Messages */
.auth-message {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 24px;
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideDown 0.3s ease-out;
    transition: opacity 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-message::before {
    content: '';
    font-family: 'Material Icons';
    font-size: 20px;
}

.auth-message-success {
    background-color: rgba(76, 175, 80, 0.1);
    color: #2e7d32;
    border-left: 4px solid #4caf50;
}

.auth-message-success::before {
    content: 'check_circle';
    color: #4caf50;
}

.auth-message-error {
    background-color: rgba(244, 67, 54, 0.1);
    color: #c62828;
    border-left: 4px solid #f44336;
}

.auth-message-error::before {
    content: 'error';
    color: #f44336;
}

.auth-message-warning {
    background-color: rgba(255, 152, 0, 0.1);
    color: #e65100;
    border-left: 4px solid #ff9800;
}

.auth-message-warning::before {
    content: 'warning';
    color: #ff9800;
}

.auth-message-info {
    background-color: rgba(33, 150, 243, 0.1);
    color: #1565c0;
    border-left: 4px solid #2196f3;
}

.auth-message-info::before {
    content: 'info';
    color: #2196f3;
}

/* Resend Email Button */
.resend-email-container {
    margin-top: 16px;
    text-align: center;
}

.btn-resend-email {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background-color: transparent;
    border: 2px solid var(--md-primary);
    color: var(--md-primary);
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-resend-email:hover:not(:disabled) {
    background-color: rgba(var(--md-primary-rgb), 0.08);
    transform: translateY(-1px);
}

.btn-resend-email:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-resend-email .material-icons {
    font-size: 18px;
}

/* Dark Theme Messages */
body.theme-dark .auth-message-success {
    background-color: rgba(76, 175, 80, 0.15);
    color: #81c784;
}

body.theme-dark .auth-message-error {
    background-color: rgba(244, 67, 54, 0.15);
    color: #e57373;
}

body.theme-dark .auth-message-warning {
    background-color: rgba(255, 152, 0, 0.15);
    color: #ffb74d;
}

body.theme-dark .auth-message-info {
    background-color: rgba(33, 150, 243, 0.15);
    color: #64b5f6;
}

/* Projects Page Messages */
.projects-message-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
}

.projects-message {
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateX(100px);
    transition: all 0.3s ease;
}

.projects-message.show {
    opacity: 1;
    transform: translateX(0);
}

.projects-message-success {
    background-color: #4caf50;
    color: white;
}

.projects-message-error {
    background-color: #f44336;
    color: white;
}

.projects-message-warning {
    background-color: #ff9800;
    color: white;
}

.projects-message-info {
    background-color: #2196f3;
    color: white;
}

/* Responsive */
@media (max-width: 768px) {
    .projects-title {
        font-size: 24px;
    }
    
    .projects-actions-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .projects-search {
        max-width: 100%;
    }
    
    .projects-grid {
        grid-template-columns: 1fr;
    }
    
    .auth-message {
        font-size: 13px;
        padding: 12px 16px;
    }
    
    .btn-resend-email {
        width: 100%;
        justify-content: center;
    }
}

/* =============================================================================
   COLLABORATION - Real-time presence and notifications
   ============================================================================= */

/* User presence badges nella toolbar */
.user-presence {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 12px;
}

.user-presence-badge {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.user-presence-badge:hover {
    transform: scale(1.1);
}

/* Connection status */
.connection-status {
    position: fixed;
    top: 60px;
    right: 20px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    z-index: 10000;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.connection-status-connected {
    background: #4CAF50;
    color: white;
}

.connection-status-disconnected {
    background: #FF9800;
    color: white;
}

.connection-status-error {
    background: #F44336;
    color: white;
}

/* Toast notifications per modifiche collaborative */
.collaboration-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 350px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.collaboration-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Dark theme adjustments */
.theme-dark .collaboration-toast {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Indicatore "sta scrivendo" per gli editor */
.user-editing-indicator {
    position: absolute;
    top: -25px;
    left: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 100;
}

/* Badge con pulsante animato quando sta editando */
.user-presence-badge.editing {
    animation: pulse-ring 2s ease-in-out infinite;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.3);
}

@keyframes pulse-ring {
    0%, 100% {
        box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.3);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(74, 144, 226, 0.1);
    }
}

.theme-dark .user-editing-indicator {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(5px);
}

/* =============================================================================
   COMPILE DIALOG
   ============================================================================= */

.compile-dialog-overlay {
    animation: fadeIn 0.2s ease;
}

.compile-dialog {
    animation: slideUp 0.3s ease;
}

/* Format Panel */
.compile-format-panel {
    background-color: var(--md-surface);
}

.compile-format-item {
    user-select: none;
}

.compile-format-item.active {
    background-color: var(--md-primary-container) !important;
    color: var(--md-on-primary-container);
    font-weight: 500;
}

/* Layout Preview Panel */
.compile-layout-panel {
    background-color: var(--md-surface);
}

.compile-layout-preview-container {
    background: linear-gradient(135deg, var(--md-surface-variant) 0%, var(--md-surface) 100%);
}

.compile-layout-preview {
    background-color: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    font-family: 'Libre Baskerville', 'Georgia', 'Times New Roman', serif;
}

body.theme-dark .compile-layout-preview {
    background-color: var(--md-surface);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* Entries Panel */
.compile-entries-panel {
    background-color: var(--md-surface);
}

.compile-entry-item {
    border-bottom: 1px solid transparent;
}

.compile-entry-item:hover {
    background-color: var(--md-surface-variant);
}

.compile-entry-type-select {
    opacity: 0;
    transition: opacity 0.2s;
}

.compile-entry-item:hover .compile-entry-type-select {
    opacity: 1;
}

/* Format Select Dropdown */
.compile-format-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23666' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 36px;
}

body.theme-dark .compile-format-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23aaa' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
}

/* Dialog Header */
.compile-dialog-header {
    background-color: var(--md-surface);
}

/* Dialog Footer */
.compile-dialog-footer {
    background-color: var(--md-surface);
}

.compile-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Scrollbar styling for compile panels */
.compile-format-list::-webkit-scrollbar,
.compile-entries-list::-webkit-scrollbar {
    width: 8px;
}

.compile-format-list::-webkit-scrollbar-track,
.compile-entries-list::-webkit-scrollbar-track {
    background: transparent;
}

.compile-format-list::-webkit-scrollbar-thumb,
.compile-entries-list::-webkit-scrollbar-thumb {
    background-color: var(--md-outline-variant);
    border-radius: 4px;
}

.compile-format-list::-webkit-scrollbar-thumb:hover,
.compile-entries-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--md-outline);
}

/* Responsive */
@media (max-width: 900px) {
    .compile-dialog {
        flex-direction: column;
        height: 95vh;
        max-height: none;
    }
    
    .compile-dialog-body {
        flex-direction: column;
    }
    
    .compile-format-panel {
        width: 100%;
        max-height: 150px;
        border-right: none;
        border-bottom: 1px solid var(--md-outline-variant);
    }
    
    .compile-format-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px;
    }
    
    .compile-format-group {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 0;
    }
    
    .compile-format-group-title {
        width: 100%;
    }
    
    .compile-format-item {
        flex: 0 0 auto;
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .compile-layout-panel {
        border-right: none;
        border-bottom: 1px solid var(--md-outline-variant);
        min-height: 200px;
    }
    
    .compile-entries-panel {
        width: 100%;
        flex: 1;
    }
}

/* Spin animation for loading */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* =============================================================================
   LEAFLET MAP STYLES
   ============================================================================= */

/* Assicura che il container della mappa abbia dimensioni corrette */
[id^="location-map-"] {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 400px;
}

/* Fix per Leaflet quando il container è nascosto inizialmente */
.leaflet-container {
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* Assicura che i tile vengano caricati correttamente */
.leaflet-tile-container img {
    max-width: none !important;
    max-height: none !important;
}

