/* ===========================================================
   Impegni — stylesheet mobile-first
   =========================================================== */

:root {
    --bg:        #f3f4f6;
    --surface:   #ffffff;
    --text:      #111827;
    --muted:     #6b7280;
    --border:    #e5e7eb;
    --primary:   #1d4ed8;
    --primary-d: #1e40af;
    --success:   #047857;
    --success-bg:#d1fae5;
    --error:     #b91c1c;
    --error-bg:  #fee2e2;
    --radius:    14px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:active { opacity: .7; }

/* ---------- Header / nav ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: calc(.7rem + var(--safe-top)) 1rem .7rem;
    background: var(--primary);
    color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; }
.app-nav { display: flex; gap: .25rem; margin-left: auto; }
.app-nav a {
    color: #fff;
    padding: .35rem .6rem;
    border-radius: 8px;
    font-size: .95rem;
}
.app-nav a:active { background: rgba(255,255,255,.18); }
.logout-form { margin: 0; }
.link-btn {
    background: none; border: none; color: #fff;
    font: inherit; cursor: pointer; padding: .35rem .5rem;
}

/* ---------- Layout principale ---------- */
.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem 1rem calc(1rem + var(--safe-bottom));
}

/* ---------- Card ---------- */
.card,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}
.auth-card {
    max-width: 400px;
    margin: 2.5rem auto;
}
.auth-card h1 { margin-top: 0; font-size: 1.4rem; }
.auth-alt { margin-bottom: 0; color: var(--muted); font-size: .95rem; }

/* ---------- Form ---------- */
label {
    display: block;
    margin: .9rem 0 .3rem;
    font-weight: 600;
    font-size: .92rem;
}
input, select, textarea {
    width: 100%;
    padding: .7rem .8rem;
    font-size: 1rem;            /* 16px+ evita lo zoom automatico su iOS */
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-color: var(--primary);
}
.field-error {
    display: block;
    margin-top: .3rem;
    color: var(--error);
    font-size: .85rem;
}

/* ---------- Bottoni ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .75rem 1.1rem;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    min-height: 44px;           /* area tocco comoda */
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-block { width: 100%; margin-top: 1.2rem; }

/* ---------- Flash ---------- */
.flash {
    padding: .75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    font-size: .95rem;
}
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error   { background: var(--error-bg);   color: var(--error); }

/* ---------- Intestazioni pagina ---------- */
.page-head { margin: .25rem 0 1rem; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-sub { font-size: .95rem; color: var(--muted); font-weight: 400; margin-left: .4rem; }

.section { margin-bottom: 1.6rem; }
.section h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.section-overdue h2 { color: var(--error); }
.day-head {
    font-size: .85rem; color: var(--muted); text-transform: uppercase;
    letter-spacing: .03em; margin: 1rem 0 .4rem;
}
.empty { color: var(--muted); padding: .5rem 0; }

/* ---------- Lista / card impegno ---------- */
.task-list { display: flex; flex-direction: column; gap: .55rem; }
.task {
    display: flex;
    align-items: stretch;
    gap: .6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.task.prio-2 { border-left-color: #dc2626; }
.task.prio-1 { border-left-color: #f59e0b; }
.task.prio-0 { border-left-color: #9ca3af; }

.task-toggle { display: flex; align-items: center; margin: 0; padding-left: .6rem; }
.check {
    width: 28px; height: 28px; flex: 0 0 28px;
    border-radius: 50%;
    border: 2px solid var(--muted);
    background: #fff; color: #fff;
    font-size: .9rem; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.check.checked { background: var(--success); border-color: var(--success); }

.task-body {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: .2rem;
    padding: .7rem .8rem .7rem 0;
    color: var(--text);
}
.task-title { font-weight: 600; word-break: break-word; }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.task-when { white-space: nowrap; }

.badge {
    font-size: .72rem; font-weight: 600;
    padding: .12rem .5rem; border-radius: 999px;
}
.badge-reminder  { background: #ede9fe; color: #6d28d9; }
.badge-scheduled { background: #dbeafe; color: #1d4ed8; }

/* ---------- Form impegno ---------- */
.type-switch { display: flex; gap: .5rem; margin-bottom: .5rem; }
.type-opt { flex: 1; margin: 0; }
.type-opt input { position: absolute; opacity: 0; pointer-events: none; }
.type-opt span {
    display: block; text-align: center;
    padding: .7rem; border: 1px solid var(--border); border-radius: 10px;
    font-weight: 600; cursor: pointer; background: #fff;
}
.type-opt input:checked + span {
    border-color: var(--primary); background: #eff6ff; color: var(--primary-d);
}
.task-form textarea { resize: vertical; }
.danger-form { margin-top: .8rem; }
.btn-danger { background: #fff; color: var(--error); border-color: var(--error); width: 100%; }
.btn-danger:active { background: var(--error-bg); }
.back-link { text-align: center; margin-top: 1rem; }

/* ---------- Filtri elenco ---------- */
.filters { margin-bottom: 1rem; }
.filters-row { display: flex; gap: .5rem; margin-top: .5rem; }
.filters-row select { flex: 1; }
.filters-row .btn { white-space: nowrap; }

/* ---------- Pulsante flottante (+) ---------- */
.fab-wrap { position: sticky; bottom: 0; height: 0; }
.fab {
    position: fixed;
    right: max(1rem, env(safe-area-inset-right));
    bottom: calc(1.1rem + var(--safe-bottom));
    width: 60px; height: 60px;
    border-radius: 50%;
    background: var(--primary); color: #fff;
    font-size: 2rem; line-height: 60px; text-align: center;
    box-shadow: 0 6px 16px rgba(29,78,216,.4);
    z-index: 20;
}
.fab:active { background: var(--primary-d); }

/* ---------- Calendario: toolbar ---------- */
.cal-toolbar {
    display: flex; flex-direction: column; gap: .6rem;
    margin-bottom: 1rem;
}
.view-switch {
    display: flex; background: #e5e7eb; border-radius: 10px; padding: 3px;
}
.view-switch a {
    flex: 1; text-align: center; padding: .45rem; border-radius: 8px;
    color: var(--muted); font-weight: 600; font-size: .9rem;
}
.view-switch a.active { background: #fff; color: var(--primary-d); box-shadow: var(--shadow); }

.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.cal-title { font-weight: 700; font-size: 1.1rem; text-align: center; flex: 1; }
.nav-btn {
    width: 40px; height: 40px; flex: 0 0 40px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; line-height: 1;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.today-btn {
    align-self: center;
    padding: .35rem 1rem; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: .85rem; font-weight: 600;
}

/* ---------- Vista settimana ---------- */
.week-day { margin-bottom: 1.1rem; }
.week-day-head { margin: 0 0 .5rem; font-size: .95rem; }
.week-day-head a { color: var(--text); }
.week-day-head span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 1.6rem; height: 1.6rem; margin-left: .25rem;
    border-radius: 50%; font-size: .85rem; color: var(--muted);
}
.week-day.is-today .week-day-head span { background: var(--primary); color: #fff; }
.empty-sm { padding: .1rem 0; font-size: .9rem; }

/* ---------- Vista mese ---------- */
.month-head, .month-week { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-head span {
    text-align: center; font-size: .72rem; color: var(--muted);
    padding: .3rem 0; text-transform: uppercase; letter-spacing: .02em;
}
.month-cell {
    position: relative;
    min-height: 56px;
    display: flex; flex-direction: column; align-items: center;
    padding: .3rem 0;
    border: 1px solid var(--border);
    margin: -0.5px;                 /* bordi collassati */
    color: var(--text); background: var(--surface);
}
.month-cell.out { background: #f9fafb; color: #cbd5e1; }
.cell-num { font-size: .85rem; }
.month-cell.is-today .cell-num {
    background: var(--primary); color: #fff;
    width: 1.6rem; height: 1.6rem; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.cell-count {
    margin-top: auto;
    min-width: 1.25rem; padding: 0 .25rem;
    font-size: .72rem; font-weight: 700; line-height: 1.25rem; text-align: center;
    background: var(--primary); color: #fff; border-radius: 999px;
}
.cell-count.all-done { background: var(--success); }

/* ---------- Impostazioni / push ---------- */
.card h2 { margin-top: 0; font-size: 1.1rem; }
.muted-text { color: var(--muted); font-size: .92rem; }
.push-status { font-weight: 600; margin: .8rem 0; }
#push-disable, #push-test { background: var(--surface); border-color: var(--border); color: var(--text); }
#push-disable:active, #push-test:active { background: var(--bg); }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
    .app-nav a { font-size: 1rem; }
    .fab { right: calc(50% - 360px + 1rem); }
    .cal-toolbar {
        flex-direction: row; align-items: center; flex-wrap: wrap;
    }
    .view-switch { flex: 0 0 auto; min-width: 280px; }
    .cal-nav { flex: 1; }
    .month-cell { min-height: 84px; }
}
