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

:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    --info: #3b82f6;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Login */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--sidebar-bg) 0%, var(--primary) 100%);
}

.login-card {
    background: var(--card);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card h2 {
    text-align: center;
    margin-bottom: 0.25rem;
    font-size: 1.75rem;
    color: var(--text);
}

.login-subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-card input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
}

.login-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-full {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    min-height: 1.2em;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.5rem 0 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.logo {
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 1rem;
}

.logo h2 {
    color: #fff;
    font-size: 1.3rem;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.8rem;
}

.user-info span {
    color: var(--sidebar-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--sidebar-text);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.nav-links {
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.nav-link.active {
    background: var(--primary);
    color: #fff;
}

.icon {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

/* Sidebar Actions */
.sidebar-actions {
    padding: 1rem 1.5rem;
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn-sidebar {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    color: var(--sidebar-text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-sidebar:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

/* Content */
.content {
    margin-left: 240px;
    padding: 2rem;
    flex: 1;
    width: calc(100% - 240px);
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.page h1 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid var(--primary);
}

.stat-card.warning {
    border-left-color: var(--warning);
}

.stat-card.info {
    border-left-color: var(--info);
}

.stat-card h3 {
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}

/* Dashboard Panels */
.dashboard-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.panel {
    background: var(--card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* Forms */
.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-start;
    background: var(--card);
    padding: 1.25rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1.5rem;
}

.form-inline input,
.form-inline select,
.form-inline textarea {
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    flex: 1;
    min-width: 150px;
}

.form-inline textarea {
    min-width: 300px;
    resize: vertical;
}

.form-inline input:focus,
.form-inline select:focus,
.form-inline textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Buttons */
.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-light);
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-small {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-icon.check:hover {
    background: var(--success);
    border-color: var(--success);
}

/* Filters */
.filters {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
}

/* Tables */
.data-table {
    width: 100%;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-collapse: collapse;
}

.data-table th {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 0.85rem 1rem;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: #f8fafc;
}

.totale-box {
    margin-top: 1rem;
    text-align: right;
    font-size: 1.1rem;
    padding: 0.75rem;
    background: var(--card);
    border-radius: 8px;
}

/* Item Lists */
.item-list {
    list-style: none;
}

.item-list li {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

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

.empty-msg {
    color: var(--text-light);
    font-style: italic;
    padding: 1rem 0;
    text-align: center;
}

/* Shopping List */
.lista-spesa-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.lista-section {
    background: var(--card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.lista-section h3 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.shopping-list li {
    gap: 0.75rem;
}

.shopping-list .item-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.shopping-list .item-actions {
    display: flex;
    gap: 0.35rem;
}

.shopping-list.done li .item-info {
    text-decoration: line-through;
    opacity: 0.6;
}

.priority-urgente {
    color: var(--danger);
    font-weight: 600;
}

.priority-opzionale {
    color: var(--text-light);
    font-style: italic;
}

.qty-badge {
    background: var(--primary);
    color: #fff;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Bollette tabs */
.bollette-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    padding: 0.5rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.badge-scaduta {
    background: var(--danger);
    color: #fff;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-in-scadenza {
    background: var(--warning);
    color: #fff;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pagata {
    background: var(--success);
    color: #fff;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

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

.note-card {
    background: var(--card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-top: 4px solid var(--primary);
    position: relative;
}

.note-card h4 {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.note-card p {
    color: var(--text-light);
    font-size: 0.9rem;
    white-space: pre-wrap;
    line-height: 1.5;
}

.note-card .note-date {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.75rem;
}

.note-card .note-delete {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
}

/* Role badge */
.role-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.role-admin {
    background: var(--primary);
    color: #fff;
}

.role-user {
    background: var(--border);
    color: var(--text);
}

/* WhatsApp share */
.share-bar {
    margin-bottom: 1rem;
}

.btn-whatsapp {
    background: #25d366;
    color: #fff;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-whatsapp:hover {
    background: #1da851;
}

/* Mobile topbar - visible only on mobile */
.mobile-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--sidebar-bg);
    color: #fff;
    margin: -1rem -1rem 1rem -1rem;
}

.mobile-topbar h3 {
    font-size: 1rem;
}

.mobile-topbar .btn-logout {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

/* Responsive - Tablet */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        padding-bottom: 64px;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 0;
        z-index: 100;
        overflow: visible;
    }

    .logo, .user-info, .sidebar-actions {
        display: none;
    }

    .nav-links {
        display: flex;
        width: 100%;
        justify-content: space-around;
    }

    .nav-links li {
        flex: 1;
    }

    .nav-link {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0.5rem 0.25rem;
        gap: 0.2rem;
        font-size: 0.65rem;
        text-align: center;
    }

    .nav-link .icon {
        font-size: 1.2rem;
    }

    .nav-link.active {
        background: var(--primary);
    }

    .content {
        margin-left: 0;
        padding: 1rem;
        width: 100%;
    }

    .page h1 {
        font-size: 1.35rem;
        margin-bottom: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.85rem;
    }

    .stat-card h3 {
        font-size: 0.7rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .dashboard-panels,
    .lista-spesa-container {
        grid-template-columns: 1fr;
    }

    .form-inline {
        flex-direction: column;
        padding: 1rem;
    }

    .form-inline input,
    .form-inline select,
    .form-inline textarea {
        min-width: auto;
        width: 100%;
    }

    .data-table {
        font-size: 0.8rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.4rem;
    }

    .notes-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-wrap: wrap;
    }

    .filters select {
        flex: 1;
        min-width: 120px;
    }

    .mobile-topbar {
        display: flex;
    }
}
