/* Hide elements managed by Alpine.js until it's initialized */
[x-cloak] {
    display: none !important;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    padding: 30px;
}

h1 {
    color: #333;
    margin-bottom: 30px;
    text-align: center;
    font-size: 2.5em;
}

.icon-btn {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background-color 0.15s;
}

.icon-btn:hover {
    background: rgba(0,0,0,0.06);
}

.form-group {
    margin-bottom: 15px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
    font-size: 14px;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group textarea {
    height: 60px;
    resize: vertical;
}

.btn {
    background: #007bff;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.btn:hover {
    background: #0056b3;
}

.btn-primary {
    background: #007bff;
}
.btn-primary:hover {
    background: #0056b3;
}
.btn-secondary {
    background: #6c757d;
}

/* Controlli vista */
.view-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.add-bookmark-btn {
    background: #28a745;
    color: white;
}

.view-btn > img, .view-btn > svg, .view-btn::before {
    font-size: 18px;
    line-height: 1;
    vertical-align: middle;
}

.view-btn {
    padding: 8px 12px;
    border: 2px solid #007bff;
    background: white;
    color: #007bff;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    line-height: 1;
    min-height: 36px;
    min-width: 160px;
    white-space: nowrap;
    flex-shrink: 0;
    box-sizing: border-box;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.filter-btn, .btn-toggle {
    flex-shrink: 0;
}

.view-btn.active {
    background: #007bff;
    color: white;
}

.bookmarks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.bookmark-card {
    background: white;
    border: 1px solid #e9ecef;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-radius: 8px;
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.bookmark-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.bookmark-main {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
}

.bookmark-visuals {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.bookmark-image {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    flex-shrink: 0;
}

.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f2f5;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.image-placeholder.has-error::before {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    content: '🔗'; /* Icona di fallback */
    color: #888;
    font-size: 1.5em;
}

.bookmark-visuals .image-placeholder {
    width: 80px;
    height: 80px;
}

.compact-item .image-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.bookmark-actions {
    display: flex;
    gap: 8px;
}

.bookmark-details {
    flex: 1;
    min-width: 0;
}

.bookmark-title {
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: 4px;
    color: #333;
    line-height: 1.3;
}

.bookmark-title a {
    color: inherit;
    text-decoration: none;
}

.bookmark-domain {
    color: #6c757d;
    font-size: 0.85em;
    font-weight: 500;
}

/* Domain tags removed at user's request: hide them globally */
.bookmark-domain, .compact-domain {
    display: none !important;
}

.bookmark-description {
    color: #666;
    font-size: 0.9em;
    line-height: 1.4;
    margin-bottom: 12px;
}

.bookmark-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
    font-size: 0.8em;
    color: #999;
}

.bookmark-date {
    font-weight: 500;
}

/* Vista compatta */
.bookmarks-compact {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.compact-item {
    display: grid;
    grid-template-columns: 32px 1fr auto auto auto;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    transition: background-color 0.2s;
}

.compact-item:hover {
    background: #f8f9fa;
}

.compact-item:last-child {
    border-bottom: none;
}

.compact-image {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.compact-content {
    min-width: 0;
}

.compact-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
    font-size: 16px;
    line-height: 1.2;
}

.compact-item .image-placeholder.has-error::before {
    font-size: 1em;
}

.compact-date {
    color: #999;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}

.compact-badges {
    display: flex;
    gap: 4px;
}

.hn-link {
    color: #ff6600;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 2px;
}

.icon-btn.read { color: #28a745; }
.icon-btn.delete { color: #c82333; }
.icon-btn.edit { color: #007bff; }

.hn-link:hover {
    text-decoration: underline;
}

.search-container {
    position: relative;
    margin-bottom: 20px;
}

.search-box {
    width: 100%;
    padding: 12px 40px 12px 20px; /* Aggiunto padding a destra per il pulsante */
    border: 2px solid #dee2e6;
    border-radius: 25px;
    font-size: 16px;
}

.clear-search-btn {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

.clear-search-btn:hover { color: #333; }

.search-box:focus {
    outline: none;
    border-color: #007bff;
}

.stats {
    text-align: center;
    margin-bottom: 20px;
    color: #666;
}

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: #f8f9fa;
}

.filter-btn.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.special-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
    color: #999;
    font-size: 0.9em;
}

#loadingIndicator {
    text-align: center;
    padding: 20px;
    font-weight: 500;
    color: #666;
    display: none;
}

/*
  Stili per l'indicatore di caricamento di htmx, compatibili con CSP.
  htmx aggiunge la classe 'htmx-request' all'elemento che fa la richiesta.
  Usiamo il selettore di fratelli (~) per mostrare l'indicatore quando
  un pulsante nel .view-controls è in stato di richiesta.
*/
.view-controls .htmx-request ~ #loadingIndicator,
.special-filters .htmx-request ~ #loadingIndicator {
    display: block;
}

@media (max-width: 768px) {
    .bookmarks-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .compact-item {
        grid-template-columns: 32px 1fr;
        gap: 8px;
    }

    .compact-date, .compact-badges {
        display: none;
    }
}

/* Stili per le notifiche Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 2000;
    opacity: 0;
    transition: transform 0.4s ease-out, opacity 0.4s ease-out;
    font-size: 14px;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.error {
    background-color: #c82333; /* Rosso per errori */
}

/* Stili per le notifiche Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 2000;
    opacity: 0;
    transition: transform 0.4s ease-out, opacity 0.4s ease-out;
    font-size: 14px;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.error {
    background-color: #c82333; /* Rosso per errori */
}

/* --- DARK MODE STYLES --- */
html.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --container-bg: #181818;
    --border-color: #3a3a3a;
    --header-bg: #1a1a1a;
    --link-color: #8ab4f8;
    --link-hover-color: #a7c7fa;
    --button-bg: #333;
    --button-hover-bg: #444;
    --input-bg: #2c2c2c;
    --input-border: #444;
    --toast-bg: #333;
    --toast-text: #fff;
    --modal-bg: rgba(0, 0, 0, 0.7);
    --modal-content-bg: #2b2b2b;
}

html.dark-mode body {
    background: var(--bg-color);
    color: var(--text-color);
}

html.dark-mode .container {
    background: var(--container-bg);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

html.dark-mode h1 {
    color: #f1f1f1;
}

html.dark-mode .search-box,
html.dark-mode .modal-content .form-group input, 
html.dark-mode .modal-content .form-group textarea {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-color);
}

html.dark-mode .modal-content .form-group label {
    color: var(--text-color);
}

html.dark-mode .search-box::placeholder {
    color: #888;
}

html.dark-mode .view-btn,
html.dark-mode .filter-btn,
html.dark-mode .btn {
    background-color: var(--button-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

html.dark-mode .view-btn:hover,
html.dark-mode .filter-btn:hover,
html.dark-mode .btn:hover {
    background-color: var(--button-hover-bg);
}

html.dark-mode .view-btn.active,
html.dark-mode .filter-btn.active {
    background-color: var(--link-color);
    color: #111;
    border-color: var(--link-color);
}

html.dark-mode #viewStatus {
    color: #ccc;
}

html.dark-mode .stats,
html.dark-mode footer {
    color: #aaa;
    border-top-color: var(--border-color);
}

html.dark-mode .bookmark-card,
html.dark-mode .bookmarks-compact {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

html.dark-mode .compact-item {
    border-bottom-color: var(--border-color);
}

html.dark-mode .bookmark-title,
html.dark-mode .compact-title {
    color: #f1f1f1;
}

html.dark-mode .bookmark-url,
html.dark-mode .compact-url {
    color: var(--link-color);
}

html.dark-mode a:hover {
    color: var(--link-hover-color);
}

html.dark-mode .bookmark-description,
html.dark-mode .bookmark-date,
html.dark-mode .compact-date {
    color: #a0a0a0;
}

html.dark-mode .icon-btn {
    color: #bbb;
}

html.dark-mode .icon-btn:hover {
    background-color: #333;
    color: #fff;
}

html.dark-mode .bookmark-footer {
    border-top-color: var(--border-color);
}

html.dark-mode .image-placeholder {
    background-color: #333;
    border-color: #444;
}
html.dark-mode .image-placeholder.has-error::before {
    color: #777;
}

html.dark-mode .modal {
    background-color: var(--modal-bg);
}

html.dark-mode .modal-content {
    background-color: var(--modal-content-bg);
    color: var(--text-color);
    border-color: #555;
}

html.dark-mode .close-btn {
    color: #aaa;
}
html.dark-mode .close-btn:hover {
    color: #fff;
}

html.dark-mode #loadingIndicator {
    color: #888;
}

html.dark-mode .clear-search-btn { color: #777; }
html.dark-mode .clear-search-btn:hover { color: #ccc; }

html.dark-mode .btn-secondary {
    background-color: #5a6268;
    border-color: #545b62;
}

html.dark-mode .modal-header {
    border-bottom-color: var(--border-color);
}

html.dark-mode .modal-footer {
    background-color: #232323;
    border-top-color: var(--border-color);
}

/* --- MODAL STYLES --- */
.modal {
    /* display: none; removed, now controlled by .hidden */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background-color: #fefefe;
    margin: 4% auto;
    padding: 0;
    border: none;
    width: 80%;
    max-width: 700px;
    border-radius: 8px;
    position: relative;
    animation: slideDown 0.3s ease-out;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    overflow: hidden;
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #333;
}

html.dark-mode .modal-header h3 {
    color: #f1f1f1;
}

.modal-body {
    padding: 24px;
}

.modal-body form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.modal-footer {
    padding: 16px 24px;
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-content .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.modal-content .form-group textarea {
    height: auto;
    min-height: 80px;
}

.close-btn {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover, .close-btn:focus {
    color: black;
}

.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.form-group-checkbox {
    /* Allinea il gruppo verticalmente con gli altri campi che hanno un'etichetta sopra */
    padding-top: 24px;
    align-self: center;
}

.form-group-checkbox label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500; /* Rende il testo meno pesante */
    white-space: nowrap; /* Impedisce al testo di andare a capo */
}

.form-group-with-button .input-with-button {
    display: flex;
    gap: 8px;
}

.form-group-with-button input {
    flex-grow: 1;
}

.btn-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 1.2rem;
    background-color: #e9ecef;
    color: #495057;
    border: 1px solid #ced4da;
}

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

/* --- Back to Top Button --- */
#backToTopBtn {
    position: fixed;
    bottom: 20px;
    right: 30px;
    z-index: 99;
    border: none;
    outline: none;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 50px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#backToTopBtn:hover {
    background-color: #0056b3;
}

html.dark-mode #backToTopBtn {
    background-color: var(--link-color);
    color: #111;
}

.hidden {
    display: none !important;
}

.w-100 {
    width: 100%;
}
.full-width-grid-column {
    grid-column: 1 / -1;
}

/* Animation for newly added bookmarks */
@keyframes highlight-fade {
    from { background-color: #d4edda; } /* Light green highlight */
    to { background-color: transparent; }
}

.newly-added {
    animation: highlight-fade 2s ease-out;
}

/* Stile per i placeholder delle immagini (div) */
.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Fallback for broken images, compatible with CSP */
.compact-image::before {
    content: '🔗'; /* Icona di fallback */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background-color: #f0f2f5;
    color: #888;
    font-size: 1.5em;
}

.bookmark-title {
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
    line-height: 1.3;
}

.bookmark-title a {
    color: inherit;
    text-decoration: none;
}

.bookmark-domain {
    color: #6c757d;
    font-size: 0.85em;
    font-weight: 500;
}

/* Domain tags removed at user's request: hide them globally */
.bookmark-domain, .compact-domain {
    display: none !important;
}

.bookmark-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: #f8f9fa;
    font-size: 0.8em;
    color: #999;
}

.bookmark-image-footer {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    object-fit: cover;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    position: absolute;
    left: 12px;
    bottom: 8px;
}

.bookmark-date {
    font-weight: 500;
}

/* Vista compatta */
.bookmarks-compact {
    background: white;
    border-radius: 8px;
}

.bookmarks-compact.show {
    display: block;
}

.compact-item {
    display: grid;
    grid-template-columns: 32px 1fr auto auto auto;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    transition: background-color 0.2s;
}

.compact-item:hover {
    background: #f8f9fa;
}

.compact-item:last-child {
    border-bottom: none;
}

.compact-image {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

html.dark-mode .bookmark-image::before,
html.dark-mode .compact-image::before, html.dark-mode .bookmark-image-footer::before {
    background-color: #333;
    color: #777;
}
.compact-content {
    min-width: 0;
}

.compact-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
    font-size: 16px;
    line-height: 1.2;
}

.compact-date {
    color: #999;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}

.compact-badges {
    display: flex;
    gap: 4px;
}

.hn-link {
    color: #ff6600;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 2px;
}

.icon-btn.read { color: #28a745; }
.icon-btn.delete { color: #c82333; }
.icon-btn.edit { color: #007bff; }

.hn-link:hover {
    text-decoration: underline;
}

.search-container {
    position: relative;
    margin-bottom: 20px;
}

.search-box {
    width: 100%;
    padding: 12px 40px 12px 20px; /* Aggiunto padding a destra per il pulsante */
    border: 2px solid #dee2e6;
    border-radius: 25px;
    font-size: 16px;
}

.clear-search-btn {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

.clear-search-btn:hover { color: #333; }

.search-box:focus {
    outline: none;
    border-color: #007bff;
}

.stats {
    text-align: center;
    margin-bottom: 20px;
    color: #666;
}

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: #f8f9fa;
}

.filter-btn.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.special-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
    color: #999;
    font-size: 0.9em;
}

#loadingIndicator {
    text-align: center;
    padding: 20px;
    font-weight: 500;
    color: #666;
    display: none;
}

/*
  Stili per l'indicatore di caricamento di htmx, compatibili con CSP.
  htmx aggiunge la classe 'htmx-request' all'elemento che fa la richiesta.
  Usiamo il selettore di fratelli (~) per mostrare l'indicatore quando
  un pulsante nel .view-controls è in stato di richiesta.
*/
.view-controls .htmx-request ~ #loadingIndicator,
.special-filters .htmx-request ~ #loadingIndicator {
    display: block;
}

@media (max-width: 768px) {
    .bookmarks-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .compact-item {
        grid-template-columns: 32px 1fr;
        gap: 8px;
    }

    .compact-date, .compact-badges {
        display: none;
    }
}

/* Stili per le notifiche Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 2000;
    opacity: 0;
    transition: transform 0.4s ease-out, opacity 0.4s ease-out;
    font-size: 14px;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.error {
    background-color: #c82333; /* Rosso per errori */
}

/* Stili per le notifiche Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 2000;
    opacity: 0;
    transition: transform 0.4s ease-out, opacity 0.4s ease-out;
    font-size: 14px;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.error {
    background-color: #c82333; /* Rosso per errori */
}

/* --- DARK MODE STYLES --- */
html.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --container-bg: #181818;
    --border-color: #3a3a3a;
    --header-bg: #1a1a1a;
    --link-color: #8ab4f8;
    --link-hover-color: #a7c7fa;
    --button-bg: #333;
    --button-hover-bg: #444;
    --input-bg: #2c2c2c;
    --input-border: #444;
    --toast-bg: #333;
    --toast-text: #fff;
    --modal-bg: rgba(0, 0, 0, 0.7);
    --modal-content-bg: #2b2b2b;
}

html.dark-mode body {
    background: var(--bg-color);
    color: var(--text-color);
}

html.dark-mode .container {
    background: var(--container-bg);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

html.dark-mode h1 {
    color: #f1f1f1;
}

html.dark-mode .search-box,
html.dark-mode .modal-content .form-group input, 
html.dark-mode .modal-content .form-group textarea {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-color);
}

html.dark-mode .modal-content .form-group label {
    color: var(--text-color);
}

html.dark-mode .search-box::placeholder {
    color: #888;
}

html.dark-mode .view-btn,
html.dark-mode .filter-btn,
html.dark-mode .btn {
    background-color: var(--button-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

html.dark-mode .view-btn:hover,
html.dark-mode .filter-btn:hover,
html.dark-mode .btn:hover {
    background-color: var(--button-hover-bg);
}

html.dark-mode .view-btn.active,
html.dark-mode .filter-btn.active {
    background-color: var(--link-color);
    color: #111;
    border-color: var(--link-color);
}

html.dark-mode #viewStatus {
    color: #ccc;
}

html.dark-mode .stats,
html.dark-mode footer {
    color: #aaa;
    border-top-color: var(--border-color);
}

html.dark-mode .bookmark-card,
html.dark-mode .bookmarks-compact {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

html.dark-mode .compact-item {
    border-bottom-color: var(--border-color);
}

html.dark-mode .bookmark-title,
html.dark-mode .compact-title {
    color: #f1f1f1;
}

html.dark-mode .bookmark-date,
html.dark-mode .compact-date {
    color: #a0a0a0;
}

html.dark-mode .icon-btn {
    color: #bbb;
}

html.dark-mode .icon-btn:hover {
    background-color: #333;
    color: #fff;
}

html.dark-mode .bookmark-footer {
    background-color: #232323;
    border-top: 1px solid var(--border-color);
}

html.dark-mode .modal {
    background-color: var(--modal-bg);
}

html.dark-mode .modal-content {
    background-color: var(--modal-content-bg);
    color: var(--text-color);
    border-color: #555;
}

html.dark-mode .close-btn {
    color: #aaa;
}
html.dark-mode .close-btn:hover {
    color: #fff;
}

html.dark-mode #loadingIndicator {
    color: #888;
}

html.dark-mode .clear-search-btn { color: #777; }
html.dark-mode .clear-search-btn:hover { color: #ccc; }

html.dark-mode .btn-secondary {
    background-color: #5a6268;
    border-color: #545b62;
}

html.dark-mode .modal-header {
    border-bottom-color: var(--border-color);
}

html.dark-mode .modal-footer {
    background-color: #232323;
    border-top-color: var(--border-color);
}

/* --- MODAL STYLES --- */
.modal {
    /* display: none; removed, now controlled by .hidden */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background-color: #fefefe;
    margin: 4% auto;
    padding: 0;
    border: none;
    width: 80%;
    max-width: 700px;
    border-radius: 8px;
    position: relative;
    animation: slideDown 0.3s ease-out;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    overflow: hidden;
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #333;
}

html.dark-mode .modal-header h3 {
    color: #f1f1f1;
}

.modal-body {
    padding: 24px;
}

.modal-body form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.modal-footer {
    padding: 16px 24px;
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-content .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.modal-content .form-group textarea {
    height: auto;
    min-height: 80px;
}

.close-btn {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover, .close-btn:focus {
    color: black;
}

.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.form-group-checkbox {
    /* Allinea il gruppo verticalmente con gli altri campi che hanno un'etichetta sopra */
    padding-top: 24px;
    align-self: center;
}

.form-group-checkbox label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500; /* Rende il testo meno pesante */
    white-space: nowrap; /* Impedisce al testo di andare a capo */
}

.form-group-with-button .input-with-button {
    display: flex;
    gap: 8px;
}

.form-group-with-button input {
    flex-grow: 1;
}

.btn-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 1.2rem;
    background-color: #e9ecef;
    color: #495057;
    border: 1px solid #ced4da;
}

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

/* --- Back to Top Button --- */
#backToTopBtn {
    position: fixed;
    bottom: 20px;
    right: 30px;
    z-index: 99;
    border: none;
    outline: none;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 50px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#backToTopBtn:hover {
    background-color: #0056b3;
}

html.dark-mode #backToTopBtn {
    background-color: var(--link-color);
    color: #111;
}

.hidden {
    display: none !important;
}

.w-100 {
    width: 100%;
}
.full-width-grid-column {
    grid-column: 1 / -1;
}

/* Animation for newly added bookmarks */
@keyframes highlight-fade {
    from { background-color: #d4edda; } /* Light green highlight */
    to { background-color: transparent; }
}

.newly-added {
    animation: highlight-fade 2s ease-out;
}