/* ============================================================
   Spesa Famiglia — CSS
   ============================================================ */

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

:root {
    --primary:   #2563eb;
    --primary-d: #1d4ed8;
    --success:   #16a34a;
    --danger:    #dc2626;
    --warning:   #d97706;
    --bg:        #f8fafc;
    --surface:   #ffffff;
    --border:    #e2e8f0;
    --text:      #1e293b;
    --text-m:    #64748b;
    --text-l:    #94a3b8;
    --radius:    10px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-m:  0 4px 12px rgba(0,0,0,.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── AUTH ──────────────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }

.auth-container {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-m);
    width: 100%;
    max-width: 420px;
    padding: 2rem;
}

.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.logo-icon { font-size: 2.5rem; display: block; margin-bottom: .5rem; }
.auth-logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.auth-logo p  { color: var(--text-m); margin-top: .25rem; }

.auth-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 1.5rem; gap: 4px; }
.tab-btn {
    flex: 1; padding: .5rem; border: none; border-radius: 6px;
    background: transparent; cursor: pointer; font-size: .9rem; color: var(--text-m);
    transition: all .2s;
}
.tab-btn.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .4rem; color: var(--text-m); }
.form-group input, .form-group select {
    width: 100%; padding: .65rem .9rem; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: .95rem; color: var(--text);
    background: var(--surface); transition: border-color .15s;
    outline: none;
}
.form-group input:focus { border-color: var(--primary); }

.famiglia-scelta { margin: 1rem 0 .75rem; }
.scelta-label { font-size: .85rem; font-weight: 500; color: var(--text-m); margin-bottom: .5rem; }
.radio-group { display: flex; gap: .75rem; flex-wrap: wrap; }
.radio-opt { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .9rem; }
.radio-opt input[type=radio] { accent-color: var(--primary); }

.field-hint { font-size: .8rem; color: var(--text-l); margin-top: .3rem; display: block; }
.form-error { color: var(--danger); font-size: .85rem; margin-top: .75rem; min-height: 1.2em; }

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .6rem 1.2rem; border: none; border-radius: var(--radius);
    font-size: .9rem; font-weight: 500; cursor: pointer; transition: all .15s;
    text-decoration: none;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-d); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #15803d; }
.btn-outline  { background: transparent; color: var(--text-m); border: 1.5px solid var(--border); }
.btn-outline:hover  { border-color: var(--primary); color: var(--primary); }
.btn-ghost    { background: transparent; color: var(--text-m); }
.btn-ghost:hover    { background: var(--bg); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-full     { width: 100%; }
.btn-sm       { padding: .4rem .8rem; font-size: .82rem; }
.btn-link     { background: none; border: none; color: var(--text-m); cursor: pointer; font-size: .85rem; padding: 0; }
.btn-link:hover { color: var(--danger); }
.btn-icon     { background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: .25rem; border-radius: 6px; }
.btn-icon:hover { background: var(--bg); }

/* ── HEADER ────────────────────────────────────────────────── */
.app-header {
    background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem; position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow);
}
.header-left  { display: flex; align-items: center; gap: .5rem; }
.logo-small   { font-size: 1.3rem; }
.app-title    { font-weight: 700; font-size: 1rem; }
.header-right { display: flex; align-items: center; gap: .75rem; }
.user-name    { font-size: .85rem; color: var(--text-m); }

/* ── NAV ───────────────────────────────────────────────────── */
.main-nav {
    display: flex; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 53px; z-index: 99;
}
.nav-btn {
    flex: 1; padding: .75rem .5rem; border: none; background: transparent;
    cursor: pointer; font-size: .85rem; color: var(--text-m); display: flex;
    align-items: center; justify-content: center; gap: .3rem;
    border-bottom: 2px solid transparent; transition: all .2s;
}
.nav-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.badge {
    background: var(--danger); color: #fff; border-radius: 99px;
    font-size: .7rem; padding: 1px 5px; font-weight: 600; min-width: 18px; text-align: center;
}
.badge:empty { display: none; }

/* ── TAB PAGES ─────────────────────────────────────────────── */
.tab-page { display: none; padding-bottom: 5rem; max-width: 680px; margin: 0 auto; }
.tab-page.active { display: block; }

/* ── TOOLBAR ───────────────────────────────────────────────── */
.page-toolbar {
    display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 100px; z-index: 90;
}
.search-wrap { flex: 1; position: relative; }
.search-wrap input {
    width: 100%; padding: .55rem .9rem .55rem 2.2rem;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    font-size: .9rem; outline: none; background: var(--bg);
}
.search-wrap input:focus { border-color: var(--primary); background: var(--surface); }
.toolbar-title { font-weight: 600; }
.page-desc { padding: .75rem 1rem; color: var(--text-m); font-size: .87rem; border-bottom: 1px solid var(--border); }

/* ── AUTOCOMPLETE ──────────────────────────────────────────── */
.autocomplete-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-m); z-index: 200; display: none; max-height: 280px; overflow-y: auto;
}
.autocomplete-dropdown.open { display: block; }
.ac-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .6rem .9rem; cursor: pointer; transition: background .1s;
    border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--bg); }
.ac-nome { font-size: .9rem; font-weight: 500; }
.ac-cat  { font-size: .78rem; color: var(--text-m); }
.ac-new  { background: #eff6ff; font-size: .85rem; color: var(--primary); font-style: italic; }

/* ── PANEL AGGIUNTA ────────────────────────────────────────── */
.aggiunta-panel {
    border-bottom: 2px solid var(--primary); background: #eff6ff;
    padding: .75rem 1rem;
}
.panel-inner strong { display: block; margin-bottom: .6rem; font-size: .95rem; }
.qty-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.qty-btn {
    width: 32px; height: 32px; border: 1.5px solid var(--border); border-radius: 6px;
    background: var(--surface); font-size: 1.1rem; cursor: pointer; color: var(--text);
}
#panel-qty { width: 52px; text-align: center; padding: .3rem; border: 1.5px solid var(--border); border-radius: 6px; font-size: .9rem; }
#panel-unita { padding: .3rem .5rem; border: 1.5px solid var(--border); border-radius: 6px; font-size: .85rem; background: var(--surface); }
#panel-nota {
    width: 100%; padding: .4rem .7rem; border: 1.5px solid var(--border); border-radius: 6px;
    font-size: .85rem; margin-bottom: .6rem; outline: none;
}
.panel-buttons { display: flex; gap: .5rem; justify-content: flex-end; }

/* ── LISTA SPESA ───────────────────────────────────────────── */
.categoria-group { margin-top: .5rem; }
.cat-header {
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem 1rem; font-size: .8rem; font-weight: 600;
    color: var(--text-m); background: var(--bg); border-bottom: 1px solid var(--border);
    text-transform: uppercase; letter-spacing: .05em;
}
.cat-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.spesa-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.spesa-item.acquistato { opacity: .5; }
.spesa-item.acquistato .item-nome { text-decoration: line-through; }

.item-check {
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    flex-shrink: 0; transition: all .2s; background: var(--surface);
}
.item-check.checked { background: var(--success); border-color: var(--success); color: #fff; }
.item-check:hover { border-color: var(--success); }

.item-info { flex: 1; min-width: 0; }
.item-nome { font-size: .93rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: .78rem; color: var(--text-m); }
.item-qty  { font-size: .85rem; color: var(--text-m); font-weight: 500; white-space: nowrap; }
.item-del  { background: none; border: none; color: var(--text-l); cursor: pointer; padding: .2rem .4rem; font-size: 1rem; border-radius: 4px; }
.item-del:hover { color: var(--danger); background: #fee2e2; }

/* ── LISTA STANDARD ────────────────────────────────────────── */
.std-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .7rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.std-icona { font-size: 1.1rem; width: 26px; text-align: center; }
.std-info { flex: 1; }
.std-nome { font-size: .9rem; font-weight: 500; }
.std-cat  { font-size: .78rem; color: var(--text-m); }
.std-qty  { font-size: .82rem; color: var(--text-m); }
.std-del  { background: none; border: none; color: var(--text-l); cursor: pointer; padding: .2rem .4rem; border-radius: 4px; }
.std-del:hover { color: var(--danger); background: #fee2e2; }

/* ── STORICO ───────────────────────────────────────────────── */
.storico-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .65rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface);
}
.storico-item:hover { background: var(--bg); }
.st-nome { flex: 1; font-size: .9rem; }
.st-meta { font-size: .78rem; color: var(--text-m); }
.st-data { font-size: .78rem; color: var(--text-l); white-space: nowrap; }
.storico-pager { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 1rem; }
#storico-page-info { font-size: .85rem; color: var(--text-m); }

/* ── FOOTER SPESA ──────────────────────────────────────────── */
.lista-footer {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: .75rem 1rem; display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 -2px 10px rgba(0,0,0,.06); max-width: 680px; margin: 0 auto;
}
#count-acquistati { font-size: .85rem; color: var(--text-m); }

/* ── MODALI ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    display: flex; align-items: center; justify-content: center; z-index: 500; padding: 1rem;
}
.modal-box {
    background: var(--surface); border-radius: 16px; padding: 2rem;
    max-width: 400px; width: 100%; text-align: center; box-shadow: var(--shadow-m);
    position: relative;
}
.modal-close {
    position: absolute; top: .75rem; right: .75rem;
    background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-m);
}
.modal-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.modal-box h2 { font-size: 1.2rem; margin-bottom: .5rem; }
.modal-box p  { color: var(--text-m); font-size: .9rem; margin-bottom: 1rem; }

.codice-display {
    font-size: 1.6rem; font-weight: 700; letter-spacing: .2em;
    background: #eff6ff; color: var(--primary); border-radius: 10px;
    padding: .75rem 1.5rem; margin: 1rem 0; font-family: monospace;
}
.codice-hint { font-size: .82rem !important; }

/* ── INFO FAMIGLIA ─────────────────────────────────────────── */
.famiglia-info .codice-fam {
    font-size: 1.3rem; font-weight: 700; letter-spacing: .2em;
    background: #eff6ff; color: var(--primary); border-radius: 8px;
    padding: .5rem 1rem; margin: .75rem 0; display: inline-block; font-family: monospace;
}
.famiglia-info .membri { color: var(--text-m); font-size: .9rem; margin-top: .5rem; }

/* ── UTILITIES ─────────────────────────────────────────────── */
.loading { padding: 2rem; text-align: center; color: var(--text-m); }
.empty   { padding: 2rem; text-align: center; color: var(--text-l); font-size: .9rem; }
.toast {
    position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
    background: #1e293b; color: #fff; padding: .6rem 1.2rem; border-radius: 99px;
    font-size: .85rem; z-index: 999; box-shadow: var(--shadow-m);
    animation: fadeInOut 2.5s forwards;
}
@keyframes fadeInOut {
    0%   { opacity: 0; transform: translateX(-50%) translateY(10px); }
    15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 480px) {
    .app-title { display: none; }
    .spesa-item, .std-item { padding: .65rem .75rem; }
    .lista-footer { padding: .65rem .75rem; }
    .btn-sm { padding: .35rem .65rem; }
}

/* ── PWA: BANNER INSTALLAZIONE ─────────────────────────────────── */
.install-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    background: #1e40af; color: #fff;
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem;
    transform: translateY(-100%); transition: transform .35s ease;
    box-shadow: 0 2px 12px rgba(0,0,0,.2);
}
.install-banner.visible { transform: translateY(0); }
.install-icon { font-size: 1.4rem; flex-shrink: 0; }
.install-text { flex: 1; line-height: 1.3; }
.install-text strong { display: block; font-size: .9rem; }
.install-text span   { font-size: .78rem; opacity: .85; }
.install-close {
    background: none; border: none; color: inherit; opacity: .7;
    cursor: pointer; font-size: 1rem; padding: .2rem .4rem; border-radius: 4px;
    flex-shrink: 0;
}
.install-close:hover { opacity: 1; }

/* ── PWA: HINT iOS ──────────────────────────────────────────────── */
.ios-hint {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: rgba(0,0,0,.5); display: flex;
    align-items: flex-end; justify-content: center;
    padding: 1rem;
}
.ios-hint-box {
    background: var(--surface); border-radius: 14px; padding: 1.25rem 1.5rem;
    max-width: 380px; width: 100%; text-align: center;
    box-shadow: var(--shadow-m); position: relative;
}
.ios-hint-box p { font-size: .9rem; margin-bottom: .5rem; color: var(--text-m); }
.ios-hint-box p:first-of-type { font-weight: 600; color: var(--text); }
.ios-hint-box .install-close { position: absolute; top: .6rem; right: .75rem; color: var(--text-m); }

/* ── PASSWORD TOGGLE ────────────────────────────────────────────── */
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 2.5rem; }
.pass-toggle {
    position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; font-size: 1rem;
    color: var(--text-m); padding: .2rem;
}

/* ── REMEMBER ME ────────────────────────────────────────────────── */
.remember-label {
    display: flex; align-items: center; gap: .5rem;
    margin-bottom: 1rem; cursor: pointer; font-size: .87rem; color: var(--text-m);
}
.remember-label input[type=checkbox] { accent-color: var(--primary); width: 16px; height: 16px; }

/* ── SAFE AREA (notch iPhone) ───────────────────────────────────── */
@supports (padding: max(0px)) {
    .app-header { padding-top: max(.75rem, env(safe-area-inset-top)); }
    .lista-footer { padding-bottom: max(.75rem, env(safe-area-inset-bottom)); }
}
