/* ─────────────────────────────────────────────
   leggi.me — stylesheet  (light theme)
   ───────────────────────────────────────────── */

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

:root {
    --bg:         #f8fafc;
    --surface:    #ffffff;
    --surface2:   #f1f5f9;
    --border:     #e2e8f0;
    --text:       #0f172a;
    --text-muted: #64748b;
    --primary:    #2563eb;
    --primary-h:  #1d4ed8;
    --success:    #10b981;
    --danger:     #ef4444;
    --warning:    #f59e0b;
    --shadow-xs:  0 1px 2px rgba(0,0,0,.05);
    --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 16px rgba(0,0,0,.09), 0 2px 4px rgba(0,0,0,.05);
    --radius:     10px;
    --sidebar-w:  224px;
    --topbar-h:   56px;
    --font:       'Inter', system-ui, sans-serif;
}

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Logo ───────────────────────────────────── */
.logo {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
    text-decoration: none;
    display: inline-block;
}
.logo:hover { text-decoration: none; }
.logo span { color: var(--primary); }

/* ── Buttons ────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.15rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background .15s, box-shadow .15s, opacity .15s, border-color .15s;
    font-family: var(--font);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(37,99,235,.35); }
.btn-primary:hover { background: var(--primary-h); box-shadow: 0 2px 8px rgba(37,99,235,.4); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface2); border-color: #cbd5e1; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-block { width: 100%; justify-content: center; }
.btn-lg { padding: .75rem 2rem; font-size: 1rem; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }

.btn-copy {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: .3rem;
    border-radius: 6px;
    transition: color .15s, background .15s;
    display: inline-flex;
    align-items: center;
}
.btn-copy:hover { color: var(--primary); background: rgba(37,99,235,.08); }

/* ── Alerts ─────────────────────────────────── */
.alert {
    padding: .85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: .9rem;
    line-height: 1.5;
}
.alert ul { padding-left: 1.2rem; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ── Forms ──────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: .35rem;
    font-weight: 500;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .65rem .9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .95rem;
    font-family: var(--font);
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-group input::placeholder { color: #94a3b8; }

.form-check label {
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    color: var(--text);
    font-size: .9rem;
}

.input-prefix {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}
.input-prefix:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input-prefix span {
    padding: .65rem .9rem;
    color: var(--text-muted);
    font-size: .85rem;
    white-space: nowrap;
    border-right: 1px solid var(--border);
    background: var(--surface2);
    flex-shrink: 0;
}
.input-prefix input {
    flex: 1;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    min-width: 0;
}

/* ── Auth layout ────────────────────────────── */
.auth-body {
    display: flex;
    min-height: 100dvh;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    background-image: radial-gradient(ellipse at 60% 20%, rgba(37,99,235,.06) 0%, transparent 60%);
}
.auth-wrapper { width: 100%; max-width: 420px; padding: 2rem 1rem; }
.auth-brand { text-align: center; margin-bottom: 1.75rem; }
.auth-brand .logo { font-size: 2rem; }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem 2rem 1.75rem;
    box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: 1.35rem; font-weight: 700; margin-bottom: 1.5rem; color: var(--text); }
.auth-switch { text-align: center; color: var(--text-muted); font-size: .9rem; margin-top: 1.25rem; }

/* ── Mobile top bar ─────────────────────────── */
.nav-topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 400;
    box-shadow: var(--shadow-sm);
    gap: .75rem;
}
.nav-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: .4rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.nav-toggle:hover { background: var(--surface2); color: var(--text); }

/* Sidebar overlay (mobile backdrop) */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,23,42,.25);
    z-index: 450;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ── App layout ─────────────────────────────── */
.app-body { display: flex; min-height: 100dvh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1rem;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 500;
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.sidebar-top {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.sidebar-bottom {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: .85rem;
    color: var(--text-muted);
}
.user-name { display: block; font-weight: 600; color: var(--text); margin-bottom: .25rem; font-size: .88rem; }
.nav-logout { color: var(--text-muted); font-size: .82rem; transition: color .15s; }
.nav-logout:hover { color: var(--danger); text-decoration: none; }

.nav-menu { list-style: none; margin-top: .25rem; }
.nav-menu li { margin-bottom: .1rem; }
.nav-menu a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: .9rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    text-decoration: none;
}
.nav-menu a:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-menu a.active { background: rgba(37,99,235,.1); color: var(--primary); }
.nav-menu a.active svg { stroke: var(--primary); }

.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 2rem 2.5rem;
    max-width: calc(var(--sidebar-w) + 980px);
    min-width: 0;
}
.main-content.wide { max-width: calc(var(--sidebar-w) + 1200px); }

/* ── Page header ────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.3px; }
.page-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.count-badge {
    background: var(--surface2);
    padding: .28rem .8rem;
    border-radius: 20px;
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 500;
    border: 1px solid var(--border);
}

.back-link {
    color: var(--text-muted);
    font-size: .875rem;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    transition: color .15s;
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* ── Search / Filters ───────────────────────── */
.filters-bar {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.search-form { display: flex; gap: .4rem; flex: 1; min-width: 200px; }
.search-input {
    flex: 1;
    padding: .55rem .9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    font-family: var(--font);
    transition: border-color .15s, box-shadow .15s;
    box-shadow: var(--shadow-xs);
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.search-input::placeholder { color: #94a3b8; }

.filter-tabs {
    display: flex;
    gap: .15rem;
    background: var(--surface2);
    padding: .2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.filter-tab {
    padding: .3rem .75rem;
    border-radius: 6px;
    font-size: .83rem;
    color: var(--text-muted);
    transition: background .15s, color .15s, box-shadow .15s;
    text-decoration: none;
    font-weight: 500;
}
.filter-tab:hover { color: var(--text); text-decoration: none; }
.filter-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
    font-weight: 600;
}

/* ── Links list ─────────────────────────────── */
.links-list { list-style: none; display: flex; flex-direction: column; gap: .4rem; }
.link-item {
    display: flex;
    align-items: center;
    padding: .85rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    gap: .9rem;
    transition: border-color .15s, box-shadow .15s;
    box-shadow: var(--shadow-xs);
}
.link-item:hover {
    border-color: #bfdbfe;
    box-shadow: 0 2px 10px rgba(37,99,235,.1);
}
.link-inactive { opacity: .5; }

.link-favicon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
    object-fit: contain;
}

.link-info { flex: 1; min-width: 0; }
.link-title-row { display: flex; align-items: center; gap: .4rem; margin-bottom: .2rem; }
.link-title {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    font-size: .9rem;
    display: block;
}
.link-title-row .link-title { margin-bottom: 0; }
.link-title:hover { color: var(--primary); }

.link-meta { display: flex; align-items: center; gap: .35rem; font-size: .8rem; flex-wrap: wrap; }
.short-url { color: var(--primary); font-weight: 600; font-size: .8rem; }
.short-url:hover { text-decoration: underline; }
.separator { color: #cbd5e1; }
.dest-url {
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}
.link-tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }

.btn-copy-inline {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    transition: color .15s, background .15s;
    flex-shrink: 0;
}
.btn-copy-inline:hover { color: var(--primary); background: rgba(37,99,235,.08); }

.link-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .3rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.click-count {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .78rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(37,99,235,.08);
    padding: .2rem .6rem;
    border-radius: 20px;
}
.link-date { font-size: .73rem; color: var(--text-muted); text-align: right; }
.sparkline { flex-shrink: 0; opacity: .7; }

/* ── Stats grid ─────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .3rem;
    box-shadow: var(--shadow-xs);
}
.stat-label {
    font-size: .72rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.stat-value { font-size: 1.9rem; font-weight: 800; color: var(--text); letter-spacing: -.5px; line-height: 1.15; }
.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }
.stat-sub { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }

/* ── Detail page ────────────────────────────── */
.detail-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-xs);
}
.detail-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}
.detail-title-row h1 { font-size: 1.2rem; font-weight: 700; flex: 1; }
.detail-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.detail-url-block {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .35rem;
}
.short-url-big { font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.dest-url-detail { font-size: .85rem; color: var(--text-muted); margin-bottom: .35rem; }
.detail-date { font-size: .78rem; color: #94a3b8; }
.detail-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0 .25rem; }

/* ── Chart ──────────────────────────────────── */
.chart-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-xs);
}
.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.chart-header h2 { font-size: 1rem; font-weight: 600; }
.chart-wrapper { height: 220px; }
.chart-wrapper-lg { height: 260px; }

.period-tabs { display: flex; gap: .2rem; }
.period-tab {
    padding: .3rem .65rem;
    border-radius: 6px;
    font-size: .8rem;
    color: var(--text-muted);
    transition: background .15s, color .15s;
    text-decoration: none;
    font-weight: 500;
}
.period-tab:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.period-tab.active { background: var(--primary); color: #fff; }

/* ── Breakdown bars ─────────────────────────── */
.breakdown-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-xs);
}
.breakdown-section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.breakdown-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: .6rem;
    font-size: .85rem;
}
.breakdown-label { width: 80px; color: var(--text-muted); font-size: .82rem; flex-shrink: 0; }
.breakdown-bar-wrap {
    flex: 1;
    background: var(--surface2);
    border-radius: 4px;
    height: 7px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.breakdown-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width .5s ease; }
.breakdown-bar-accent { background: #60a5fa; }
.breakdown-pct { width: 36px; text-align: right; color: var(--text-muted); font-size: .82rem; font-variant-numeric: tabular-nums; }

/* ── Section ────────────────────────────────── */
.section { margin-bottom: 2rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h2 { font-size: 1.1rem; font-weight: 700; }
.link-all { font-size: .85rem; color: var(--primary); font-weight: 500; }
.link-all:hover { text-decoration: underline; }

/* ── Empty state ────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
}
.empty-state p { font-size: .95rem; }

/* ── Pagination ─────────────────────────────── */
.pagination { display: flex; gap: .35rem; margin-top: 1.5rem; justify-content: center; flex-wrap: wrap; }
.page-btn {
    padding: .4rem .75rem;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .85rem;
    text-decoration: none;
    font-weight: 500;
    transition: background .12s, color .12s, border-color .12s;
    box-shadow: var(--shadow-xs);
}
.page-btn:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Modal ──────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.3);
    z-index: 600;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    padding: 1.75rem;
    animation: modalIn .2s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-md);
}
@keyframes modalIn {
    from { transform: translateY(-10px) scale(.98); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: .25rem .3rem;
    border-radius: 6px;
    transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

/* ── Hero ───────────────────────────────────── */
.hero { text-align: center; padding: 3rem 2rem; max-width: 700px; margin: 0 auto; }
.hero h1 { font-size: 3rem; line-height: 1.15; margin-bottom: 1rem; font-weight: 800; letter-spacing: -.5px; }
.hero-sub { color: var(--text-muted); font-size: 1.1rem; margin-bottom: 2.5rem; }
.hero-cta { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* ── Admin table ────────────────────────────── */
.admin-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}
.admin-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .875rem;
}
.admin-table th {
    text-align: left;
    padding: .8rem 1.25rem;
    background: var(--surface2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.admin-table th:first-child { border-radius: var(--radius) 0 0 0; }
.admin-table th:last-child  { border-radius: 0 var(--radius) 0 0; }
.admin-table td {
    padding: .9rem 1.25rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
    color: var(--text);
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: var(--surface2); }
.admin-table tr.row-inactive td { opacity: .45; }
.actions-cell { text-align: right; }

/* ── Dropdown ───────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-trigger {
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    padding: .35rem .45rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s, border-color .15s;
}
.dropdown-trigger:hover { background: var(--surface2); border-color: var(--border); color: var(--text); }
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 175px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 300;
    overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-menu form { margin: 0; }
.dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: .6rem 1rem;
    background: none;
    border: none;
    color: var(--text);
    font-size: .875rem;
    font-family: var(--font);
    cursor: pointer;
    transition: background .12s;
    text-decoration: none;
}
.dropdown-item:hover { background: var(--surface2); text-decoration: none; }
.dropdown-item-danger { color: var(--danger); }
.dropdown-item-danger:hover { background: #fef2f2; }
.dropdown-divider { height: 1px; background: var(--border); margin: .25rem 0; }

/* ── Badges ─────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .65rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-admin    { background: #dbeafe; color: #1e40af; }
.badge-user     { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-active   { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-hidden   { background: #f3f4f6; color: #6b7280; border: 1px solid #e5e7eb; }

/* ── Tag chips ──────────────────────────────── */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .15rem .55rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
    color: #fff;
}

/* ── Edit page ──────────────────────────────── */
.edit-page { max-width: 640px; }
.edit-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.25rem; letter-spacing: -.3px; }
.edit-info-banner {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    background: rgba(37,99,235,.06);
    border: 1px solid rgba(37,99,235,.2);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    font-size: .88rem;
    color: #1e40af;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}
.edit-info-banner svg { flex-shrink: 0; margin-top: 2px; stroke: #1e40af; }
.edit-form { display: flex; flex-direction: column; gap: 1rem; }
.edit-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-xs);
}
.edit-section h2 {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    margin-bottom: .85rem;
}
.edit-section .form-group:last-child { margin-bottom: 0; }
.edit-section input[type="url"],
.edit-section input[type="text"] {
    width: 100%;
    padding: .65rem .9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .95rem;
    font-family: var(--font);
    transition: border-color .15s, box-shadow .15s;
}
.edit-section input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.edit-short-url { display: flex; align-items: center; gap: .75rem; }
.edit-short-url .input-prefix { flex: 1; }
.char-counter { font-size: .8rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.edit-actions { display: flex; gap: .75rem; justify-content: flex-end; padding-top: .25rem; }

/* ── Tag input ──────────────────────────────── */
.tag-input-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-items: center;
    padding: .45rem .75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 44px;
    cursor: text;
    position: relative;
    transition: border-color .15s, box-shadow .15s;
}
.tag-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.tag-input-wrap .tag-chip { cursor: default; }
.tag-input-wrap .tag-chip-remove {
    background: none; border: none;
    color: rgba(255,255,255,.7); cursor: pointer;
    padding: 0; font-size: .85rem; line-height: 1;
}
.tag-input-wrap .tag-chip-remove:hover { color: #fff; }
.tag-text-input {
    flex: 1; min-width: 100px;
    background: none; border: none; outline: none;
    color: var(--text); font-size: .9rem; font-family: var(--font); padding: .1rem 0;
}
.tag-text-input::placeholder { color: #94a3b8; }
.tag-suggestions {
    position: absolute;
    top: calc(100% + 4px); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 400;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}
.tag-suggestions.open { display: block; }
.tag-suggestion-item {
    padding: .55rem 1rem;
    cursor: pointer;
    font-size: .875rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    transition: background .1s;
    color: var(--text);
}
.tag-suggestion-item:hover { background: var(--surface2); }
.tag-suggestion-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tag-hint { font-size: .76rem; color: var(--text-muted); margin-top: .4rem; }

/* ── Filter chips ───────────────────────────── */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
    margin-bottom: 1rem;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .28rem .75rem;
    background: rgba(37,99,235,.07);
    border: 1px solid rgba(37,99,235,.2);
    border-radius: 20px;
    font-size: .8rem;
    color: #1e40af;
}
.filter-chip button, .filter-chip a button {
    background: none; border: none;
    color: inherit; cursor: pointer;
    padding: 0; font-size: 1rem; line-height: 1;
    opacity: .7; text-decoration: none;
}
.filter-chip button:hover { opacity: 1; }
.filter-chip a { color: inherit; text-decoration: none; display: contents; }
.filter-chip-clear { font-size: .78rem; color: var(--text-muted); text-decoration: none; padding: .2rem .5rem; }
.filter-chip-clear:hover { color: var(--danger); text-decoration: none; }

/* ── Filter panel ───────────────────────────── */
.filter-section { margin-bottom: 1.5rem; }
.filter-section h3 {
    font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .07em;
    color: var(--text-muted); margin-bottom: .75rem;
}
.filter-date-label { display: block; font-size: .78rem; color: var(--text-muted); margin-bottom: .3rem; }
.date-range-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.date-range-inputs input[type="date"] {
    width: 100%; padding: .6rem .9rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
    font-size: .875rem; font-family: var(--font);
    transition: border-color .15s;
}
.date-range-inputs input[type="date"]:focus { outline: none; border-color: var(--primary); }
.date-shortcuts { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .65rem; }
.date-shortcut {
    padding: .3rem .65rem;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 6px; font-size: .78rem; color: var(--text-muted);
    cursor: pointer; transition: background .12s, color .12s;
    font-family: var(--font);
}
.date-shortcut:hover { background: var(--border); color: var(--text); }
.filter-tags-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.filter-tag-check { display: none; }
.filter-tag-label {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .35rem .75rem; border-radius: 20px;
    font-size: .82rem; cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .12s, opacity .12s;
    color: #fff; opacity: .6;
}
.filter-tag-check:checked + .filter-tag-label { border-color: rgba(255,255,255,.55); opacity: 1; }
.link-type-opts { display: flex; gap: .5rem; flex-wrap: wrap; }
.link-type-opt { display: none; }
.link-type-label {
    padding: .4rem .85rem;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 6px; font-size: .85rem; color: var(--text-muted);
    cursor: pointer; transition: all .12s; font-family: var(--font);
}
.link-type-opt:checked + .link-type-label { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-panel-footer {
    display: flex; align-items: center;
    justify-content: space-between;
    padding-top: 1.25rem; border-top: 1px solid var(--border);
    margin-top: .5rem;
}
.btn-clear-filters {
    background: none; border: none;
    color: var(--text-muted); font-size: .85rem;
    cursor: pointer; font-family: var(--font);
    display: flex; align-items: center; gap: .3rem; padding: 0;
}
.btn-clear-filters:hover { color: var(--danger); }
.btn-filter { position: relative; }
.filter-count-badge {
    position: absolute; top: -5px; right: -5px;
    background: var(--primary); color: #fff;
    border-radius: 50%; width: 18px; height: 18px;
    font-size: .68rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

/* ── Hidden link ────────────────────────────── */
.alert-hidden {
    display: flex; align-items: flex-start; gap: .6rem;
    background: #eff6ff; border: 1px solid #bfdbfe;
    border-radius: var(--radius); padding: .85rem 1rem;
    font-size: .88rem; color: #1e40af; margin-bottom: 1.5rem;
}

/* ── QR Editor Modal ────────────────────────── */
.qr-editor-modal { max-width: 620px; width: 95%; }
.qr-modal-link-title { font-weight: 400; color: var(--text-muted); font-size: .95rem; }
.qr-editor-body {
    display: grid;
    grid-template-columns: 190px 1fr;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
    align-items: start;
}
.qr-preview-col { display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.qr-preview-frame {
    position: relative;
    width: 180px; height: 180px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.qr-preview-frame img {
    width: 100%; height: 100%;
    object-fit: contain;
    transition: opacity .2s; display: block;
}
.qr-preview-spinner {
    display: none; position: absolute; inset: 0;
    background: rgba(255,255,255,.75);
    border-radius: 12px;
}
.qr-preview-spinner::after {
    content: '';
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 28px; height: 28px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: qr-spin .7s linear infinite;
}
@keyframes qr-spin { to { transform: translate(-50%,-50%) rotate(360deg); } }
.qr-short-url { font-size: .78rem; color: var(--primary); text-align: center; word-break: break-all; font-weight: 600; }

.qr-options-col { display: flex; flex-direction: column; gap: 1.1rem; }
.qr-option-group { display: flex; flex-direction: column; gap: .5rem; }
.qr-option-label {
    font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted);
}
.qr-style-grid { display: flex; gap: .5rem; }
.qr-style-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem;
    padding: .6rem .4rem;
    background: var(--surface2); border: 2px solid var(--border);
    border-radius: 8px; color: var(--text-muted); font-size: .75rem;
    cursor: pointer; font-family: var(--font);
    transition: border-color .15s, color .15s, background .15s;
}
.qr-style-btn:hover { border-color: var(--primary); color: var(--text); background: rgba(37,99,235,.05); }
.qr-style-btn.active { border-color: var(--primary); background: rgba(37,99,235,.08); color: var(--primary); }
.qr-style-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 22px; height: 22px; }
.qr-style-preview span { background: currentColor; }
.qr-style-sq span { border-radius: 0; }
.qr-style-rd span { border-radius: 3px; }
.qr-style-ci span { border-radius: 50%; }

.qr-colors-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.qr-color-item { display: flex; flex-direction: column; align-items: center; gap: .3rem; cursor: pointer; font-size: .75rem; color: var(--text-muted); }
.qr-color-item input[type="color"] {
    width: 40px; height: 32px;
    border: 2px solid var(--border); border-radius: 6px;
    background: var(--surface2); cursor: pointer; padding: 2px;
}
.qr-color-item input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.qr-color-item input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }
.qr-colors-arrow { color: var(--text-muted); flex-shrink: 0; }
.qr-colors-reset {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    color: var(--text-muted); font-size: 1rem;
    width: 32px; height: 32px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: color .12s, border-color .12s; align-self: flex-end; margin-bottom: 1.5rem;
    font-family: var(--font);
}
.qr-colors-reset:hover { color: var(--primary); border-color: var(--primary); }

.qr-toggle-wrap { display: flex; align-items: center; }
#qr-logo-toggle { position: absolute; opacity: 0; width: 0; height: 0; }
#qr-logo-toggle + label { display: flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .88rem; color: var(--text); user-select: none; }
.qr-toggle-track {
    width: 38px; height: 20px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; position: relative;
    transition: background .2s, border-color .2s; flex-shrink: 0;
}
.qr-toggle-thumb {
    position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px;
    background: #cbd5e1; border-radius: 50%;
    transition: transform .2s, background .2s;
}
#qr-logo-toggle:checked + label .qr-toggle-track { background: var(--primary); border-color: var(--primary); }
#qr-logo-toggle:checked + label .qr-toggle-thumb { transform: translateX(18px); background: #fff; }

.qr-download-row { display: flex; gap: .75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.qr-download-row .btn { flex: 1; justify-content: center; }
.qr-png-size { font-size: .75rem; opacity: .7; }

/* ── Analytics ──────────────────────────────── */
.an-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 1rem; margin-bottom: 1.75rem;
}
.an-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.3px; }

.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }

.an-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
.an-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-xs);
}
.an-card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1.1rem; display: flex; align-items: center; gap: .6rem; }
.an-card-full { grid-column: 1 / -1; margin-bottom: 1.25rem; }
.an-sub-label { font-size: .78rem; font-weight: 400; color: var(--text-muted); }
.an-empty { color: var(--text-muted); font-size: .88rem; padding: .75rem 0; }

.referer-list { display: flex; flex-direction: column; gap: .55rem; }
.referer-row { display: grid; grid-template-columns: 140px 1fr 48px; align-items: center; gap: .75rem; }
.referer-label { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

.top-links-table { display: flex; flex-direction: column; gap: .2rem; }
.top-link-row {
    display: grid; grid-template-columns: 28px 20px 1fr 120px 56px;
    align-items: center; gap: .75rem;
    padding: .6rem .5rem; border-radius: 8px;
    text-decoration: none; transition: background .12s; color: inherit;
}
.top-link-row:hover { background: var(--surface2); text-decoration: none; }
.top-link-rank { font-size: .8rem; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.top-link-favicon { flex-shrink: 0; opacity: .9; }
.top-link-info { display: flex; flex-direction: column; overflow: hidden; }
.top-link-title { font-size: .88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.top-link-url { font-size: .75rem; color: var(--primary); opacity: .85; }
.top-link-bar-wrap { height: 5px; background: var(--surface2); border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
.top-link-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }
.top-link-count { font-size: .85rem; font-weight: 700; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

.breakdown-bars-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem .75rem; }
.breakdown-abs { font-size: .75rem; color: var(--text-muted); }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 767px) {
    /* Show mobile top bar */
    .nav-topbar { display: flex; }

    /* Sidebar as a left-drawer */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-md);
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }

    /* Hide the "Crea nuovo" button from sidebar on mobile (topbar has one) */
    .sidebar-top > .btn { display: none; }

    /* Main content: offset for topbar, no sidebar margin */
    .main-content {
        margin-left: 0;
        padding: calc(var(--topbar-h) + 1.25rem) 1rem 2rem;
        max-width: 100%;
    }
    .main-content.wide { max-width: 100%; }

    /* Page layout adjustments */
    .page-header { margin-bottom: 1rem; }
    .page-header h1 { font-size: 1.3rem; }

    /* Filters */
    .filters-bar { gap: .5rem; }
    .search-form { min-width: 0; }
    .filter-tabs { flex-shrink: 0; }

    /* Link items: favicon + info on row 1, stats on row 2, dropdown top-right */
    .link-item {
        position: relative;
        flex-wrap: wrap;
        gap: .5rem .75rem;
        padding: .75rem .9rem;
        padding-right: 2.75rem; /* space for absolute dropdown */
    }
    .link-item .dropdown {
        position: absolute;
        top: .6rem;
        right: .6rem;
    }
    .link-item .link-favicon { align-self: flex-start; margin-top: 2px; }
    .link-stats {
        width: 100%;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: .4rem .65rem;
        justify-content: flex-start;
    }
    .link-date { text-align: left; }
    .dest-url { max-width: 200px; }

    /* Stats */
    .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .stat-value { font-size: 1.5rem; }

    /* Analytics */
    .an-row { grid-template-columns: 1fr; }
    .top-link-row { grid-template-columns: 24px 18px 1fr 40px; }
    .top-link-bar-wrap { display: none; }
    .breakdown-bars-grid { grid-template-columns: 1fr; }
    .referer-row { grid-template-columns: 110px 1fr 38px; }

    /* Detail page */
    .detail-title-row { flex-direction: column; }
    .detail-actions { flex-wrap: wrap; }
    .detail-header { padding: 1.1rem; }

    /* QR editor */
    .qr-editor-body { grid-template-columns: 1fr; }
    .qr-preview-col { flex-direction: row; align-items: flex-start; gap: 1rem; }
    .qr-preview-frame { width: 140px; height: 140px; flex-shrink: 0; }

    /* Charts */
    .chart-wrapper { height: 180px; }
    .chart-wrapper-lg { height: 200px; }

    /* Modals */
    .modal { padding: 1.25rem; border-radius: 12px; }
    .an-card, .chart-section, .breakdown-section { padding: 1.1rem 1rem; }
}

@media (max-width: 480px) {
    .stat-value { font-size: 1.35rem; }
    .filters-bar { flex-direction: column; align-items: stretch; }
    .search-form { width: 100%; }
    .filter-tabs { width: 100%; justify-content: center; }
    .btn-filter { align-self: flex-end; }
    .qr-editor-modal { padding: 1.1rem; }
    .qr-preview-col { flex-direction: column; align-items: center; }
}

@media (min-width: 768px) {
    .nav-topbar { display: none !important; }
    .sidebar-overlay { display: none !important; }
}

/* Tablet tweaks */
@media (min-width: 768px) and (max-width: 1024px) {
    .main-content { padding: 1.5rem 1.75rem; }
    .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .an-row { grid-template-columns: 1fr; }
}
