/* ============================================================
   LinkSaver – Design System
   Mobile-first, clean, accessibile
   ============================================================ */

:root {
    --primary:      #4f46e5;
    --primary-dark: #3730a3;
    --primary-light:#eef2ff;
    --success:      #16a34a;
    --danger:       #dc2626;
    --text:         #1e1e2e;
    --text-muted:   #6b7280;
    --border:       #e5e7eb;
    --bg:           #f8f9ff;
    --card-bg:      #ffffff;
    --radius:       12px;
    --shadow:       0 2px 12px rgba(79,70,229,.10);
    --shadow-hover: 0 6px 24px rgba(79,70,229,.18);
    --navbar-h:     60px;
    --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
}

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

img { max-width: 100%; }

/* ---- LAYOUT ---- */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1rem 1rem 5rem;
}
.container-sm { max-width: 480px; }

/* ---- AUTH PAGE ---- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: linear-gradient(135deg, #eef2ff 0%, #f8f9ff 100%);
}

.auth-container {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 2rem 1.75rem;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 8px 40px rgba(79,70,229,.15);
}

.auth-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: .5rem;
}
.auth-logo p { color: var(--text-muted); font-size: .875rem; }

.auth-tabs {
    display: flex;
    background: #f3f4f6;
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 1.25rem;
}
.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: .5rem;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .2s, color .2s;
    color: var(--text-muted);
}
.tab-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ---- NAVBAR ---- */
.navbar {
    height: var(--navbar-h);
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(0,0,0,.06);
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}
.nav-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
}

/* ---- SEARCH BAR ---- */
.search-bar-wrapper {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: .75rem 1rem;
    position: sticky;
    top: var(--navbar-h);
    z-index: 90;
}
.search-form {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    gap: .5rem;
}
.search-input-wrap {
    position: relative;
    flex: 1;
}
.search-icon {
    position: absolute;
    left: .75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: .625rem .75rem .625rem 2.5rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: .95rem;
    background: #f9f9fb;
    transition: border-color .2s;
    outline: none;
}
.search-input:focus { border-color: var(--primary); background: white; }
.search-clear {
    position: absolute;
    right: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: .875rem;
}

.sort-select {
    padding: .625rem .75rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: .875rem;
    font-family: var(--font);
    background: #f9f9fb;
    color: var(--text);
    cursor: pointer;
    outline: none;
    transition: border-color .2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.sort-select:focus { border-color: var(--primary); background: white; }

/* ---- STATS ROW ---- */
.stats-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem 0;
}
.stat-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: .25rem .75rem;
    border-radius: 20px;
    font-size: .8rem;
    font-weight: 600;
}
.stat-hint { font-size: .875rem; color: var(--text-muted); }

/* ---- LINKS GRID ---- */
.links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.link-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    transition: transform .15s, box-shadow .15s;
    position: relative;
}
.link-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.link-card-header {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.link-favicon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
}
.link-url-domain {
    font-size: .75rem;
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}
.link-url-domain:hover { color: var(--primary); }

.btn-edit {
    background: none;
    border: none;
    cursor: pointer;
    color: #ccc;
    padding: 2px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color .15s, background .15s;
    flex-shrink: 0;
    text-decoration: none;
}
.btn-edit:hover { color: var(--primary); background: var(--primary-light); text-decoration: none; }

.btn-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: #ccc;
    padding: 2px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color .15s, background .15s;
    flex-shrink: 0;
}
.btn-delete:hover { color: var(--danger); background: #fef2f2; }

/* ---- Link preview in edit.php ---- */
.link-preview {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #f4f4f8;
    border-radius: 8px;
    padding: .5rem .75rem;
    margin-bottom: 1.25rem;
}
.link-preview-host {
    font-size: .8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-title {
    font-size: .925rem;
    font-weight: 600;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
    line-height: 1.4;
}
.link-title:hover { color: var(--primary); }

.link-desc {
    font-size: .8rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.link-tags {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-top: .1rem;
}

/* Tag nelle card – palette multi-colore ciclica via nth-child */
.tag {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .01em;
    padding: .2rem .55rem;
    border-radius: 20px;
    text-decoration: none;
    transition: transform .15s, box-shadow .15s, filter .15s;
    line-height: 1;
}
.tag::before { content: '#'; opacity: .65; font-weight: 400; }
.tag:hover {
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    filter: brightness(.92);
}

/* Colori ciclici: 6 toni pastello distinti */
.tag:nth-child(6n+1) { background:#ede9fe; color:#5b21b6; }
.tag:nth-child(6n+2) { background:#dbeafe; color:#1e40af; }
.tag:nth-child(6n+3) { background:#dcfce7; color:#15803d; }
.tag:nth-child(6n+4) { background:#fef3c7; color:#92400e; }
.tag:nth-child(6n+5) { background:#fce7f3; color:#9d174d; }
.tag:nth-child(6n+0) { background:#e0f2fe; color:#0c4a6e; }

/* Tag attivo (filtro applicato) */
.tag.tag-active {
    background: var(--primary) !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(79,70,229,.35);
}
.tag.tag-active:hover {
    filter: brightness(.9);
    transform: translateY(-1px);
    text-decoration: none;
}

.link-meta {
    font-size: .72rem;
    color: #bbb;
    margin-top: auto;
}

/* ---- EMPTY STATE ---- */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 1rem; }
.empty-state p { font-size: 1rem; }
.empty-state a { color: var(--primary); font-weight: 600; }

/* ---- PAGINATION ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 0 1rem;
}
.page-info { font-size: .875rem; color: var(--text-muted); }

/* ---- CARD (save form) ---- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-top: 1.5rem;
}
.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    color: var(--text);
}

/* ---- FORMS ---- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .35rem;
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: .65rem .875rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: .95rem;
    font-family: var(--font);
    background: #f9f9fb;
    transition: border-color .2s, background .2s;
    outline: none;
    color: var(--text);
}
.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    background: white;
}
.form-group small {
    display: block;
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .3rem;
}

.form-actions { display: flex; flex-direction: column; gap: .5rem; margin-top: 1.25rem; }

.hidden { display: none !important; }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .65rem 1.25rem;
    border-radius: 10px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .2s, transform .1s, box-shadow .2s;
    text-decoration: none;
    white-space: nowrap;
    font-family: var(--font);
    line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(79,70,229,.35); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

.btn-sm { padding: .45rem .875rem; font-size: .8rem; border-radius: 8px; }
.btn-full { width: 100%; }

/* ---- ALERTS ---- */
.alert {
    border-radius: 10px;
    padding: .75rem 1rem;
    font-size: .875rem;
    margin-bottom: 1rem;
}
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ---- FAB (Floating Action Button) ---- */
.fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(79,70,229,.45);
    text-decoration: none;
    transition: transform .2s, box-shadow .2s;
    z-index: 200;
}
.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(79,70,229,.55);
    text-decoration: none;
}

/* ---- Rimuovi FAB su desktop quando ha già il bottone in nav ---- */
@media (min-width: 640px) {
    .fab { display: none; }
}

/* ---- RESPONSIVE ---- */
@media (max-width: 600px) {
    .links-grid {
        grid-template-columns: 1fr;
    }
    .navbar { padding: 0 .75rem; }
    .auth-container { padding: 1.5rem 1.25rem; }
    .card { padding: 1.25rem 1rem; }
    .container { padding-bottom: 6rem; } /* spazio per FAB */
}

/* ---- TAG CLOUD ---- */
.tag-cloud-wrap {
    background: white;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: .875rem 1rem;
    margin-bottom: 1rem;
}

.tag-cloud-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: .6rem;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    max-height: 88px;
    overflow: hidden;
    transition: max-height .4s cubic-bezier(.4,0,.2,1);
}
.tag-cloud.expanded {
    max-height: 800px;
}

.tag-cloud-item {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    background: #f8f8fc;
    color: var(--text-muted);
    border: 1.5px solid #e9eaf0;
    padding: .3rem .75rem;
    border-radius: 999px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: all .18s ease;
    /* font-size e font-weight vengono impostati inline in PHP (scala per conteggio) */
}
.tag-cloud-item::before { content: '#'; opacity: .5; font-weight: 400; margin-right: .05em; }
.tag-cloud-item:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: #a5b4fc;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(79,70,229,.15);
    text-decoration: none;
}
.tag-cloud-item.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 3px 12px rgba(79,70,229,.30);
}
.tag-cloud-item.active::before { opacity: .7; }
.tag-cloud-item.active:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    text-decoration: none;
}

.tag-count {
    font-size: .65em;
    font-weight: 700;
    opacity: .6;
    background: rgba(0,0,0,.06);
    border-radius: 8px;
    padding: .05em .35em;
    margin-left: .1em;
}
.tag-cloud-item.active .tag-count {
    background: rgba(255,255,255,.22);
    opacity: 1;
}

.tag-cloud-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: .5rem;
}
.tag-cloud-toggle {
    background: none;
    border: none;
    color: var(--primary);
    font-size: .75rem;
    cursor: pointer;
    padding: 0;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: .25rem;
}
.tag-cloud-toggle:hover { text-decoration: underline; }

/* Pulsante "Rimuovi filtro" */
.clear-filter {
    font-size: .8rem;
    color: var(--danger);
    border: 1px solid #fecaca;
    background: #fef2f2;
    padding: .2rem .6rem;
    border-radius: 20px;
    text-decoration: none;
    transition: background .15s;
}
.clear-filter:hover { background: #fee2e2; text-decoration: none; }

/* ---- Animazione card delete ---- */
.link-card.removing {
    opacity: 0;
    transform: scale(.95);
    transition: opacity .25s, transform .25s;
    pointer-events: none;
}
