/* ============================================================
 *  SosMe Emergency Vault — Design System
 *  Dark mode, premium, accessibile, chiaro per emergenza
 *  Font: Inter (Google Fonts)
 * ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ── */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2332;
    --bg-card-hover: #1f2b3d;
    --bg-input: #0d1420;
    --bg-modal: rgba(0,0,0,0.7);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0a0e17;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: rgba(59,130,246,0.15);
    --accent-glow: rgba(59,130,246,0.3);

    --success: #10b981;
    --success-bg: rgba(16,185,129,0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245,158,11,0.12);
    --danger: #ef4444;
    --danger-bg: rgba(239,68,68,0.12);
    --info: #06b6d4;

    --border: #1e293b;
    --border-focus: #3b82f6;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.2s ease;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ── Layout ── */
.container { max-width: 800px; margin: 0 auto; padding: 0 20px; }
.container-sm { max-width: 500px; margin: 0 auto; padding: 0 20px; }
.page { min-height: 100vh; display: flex; flex-direction: column; }
.page-content { flex: 1; padding: 40px 0; }

/* ── Logo & Header ── */
.header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(12px);
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-icon {
    width: 38px; height: 38px; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 800; color: white;
}
.logo-text { font-size: 22px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.5px; }
.logo-text span { color: var(--accent); }
.header-actions { display: flex; gap: 10px; align-items: center; }

/* ── Language Switcher ── */
.lang-switch {
    display: flex; gap: 4px; background: var(--bg-card); border-radius: var(--radius-full);
    padding: 3px; border: 1px solid var(--border);
}
.lang-btn {
    padding: 6px 14px; border-radius: var(--radius-full); border: none; cursor: pointer;
    font-size: 13px; font-weight: 600; font-family: var(--font);
    background: transparent; color: var(--text-secondary); transition: all var(--transition);
}
.lang-btn.active, .lang-btn:hover {
    background: var(--accent); color: white;
}

/* ── Typography ── */
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.5px; line-height: 1.2; }
h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.3px; }
h3 { font-size: 1.2rem; font-weight: 600; }
.subtitle { color: var(--text-secondary); font-size: 1.05rem; margin-top: 8px; line-height: 1.5; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* ── Cards ── */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 28px;
    box-shadow: var(--shadow); transition: all var(--transition);
}
.card-hover:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card-header { margin-bottom: 24px; }
.card-title { font-size: 1.35rem; font-weight: 700; margin-bottom: 6px; }
.card-subtitle { color: var(--text-secondary); font-size: 0.95rem; }
.card + .card { margin-top: 16px; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }
.form-label {
    display: block; font-size: 0.9rem; font-weight: 600;
    color: var(--text-primary); margin-bottom: 6px;
}
.form-label .badge-required { color: var(--danger); font-size: 0.75rem; margin-left: 4px; }
.form-label .badge-optional { color: var(--text-muted); font-size: 0.75rem; margin-left: 4px; font-weight: 400; }
.form-help {
    display: block; font-size: 0.82rem; color: var(--text-muted);
    margin-top: 4px; line-height: 1.4;
}
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 12px 16px;
    background: var(--bg-input); color: var(--text-primary);
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font-family: var(--font); font-size: 1rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input::placeholder { color: var(--text-muted); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-input.error { border-color: var(--danger); }
.form-error { font-size: 0.82rem; color: var(--danger); margin-top: 4px; }

/* Password toggle */
.input-group { position: relative; }
.input-group .form-input { padding-right: 48px; }
.input-toggle {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 18px; padding: 4px;
}
.input-toggle:hover { color: var(--text-primary); }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 24px; border: none; border-radius: var(--radius-sm);
    font-family: var(--font); font-size: 1rem; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: var(--accent); color: white;
    box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-success { background: var(--success); color: white; }
.btn-ghost { background: transparent; color: var(--accent); padding: 8px 16px; }
.btn-ghost:hover { background: var(--accent-light); }
.btn-lg { padding: 16px 32px; font-size: 1.1rem; border-radius: var(--radius); }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn-full { width: 100%; }
.btn-sos {
    background: linear-gradient(135deg, #ef4444, #dc2626); color: white;
    font-size: 1.2rem; padding: 18px 36px; border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(239,68,68,0.4); text-transform: uppercase; letter-spacing: 1px;
}
.btn-sos:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(239,68,68,0.5); }

/* ── Flash Messages ── */
.flash {
    padding: 14px 20px; border-radius: var(--radius-sm);
    font-size: 0.95rem; font-weight: 500; margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px;
    animation: flashIn 0.3s ease;
}
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.flash-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.flash-info { background: var(--accent-light); color: var(--accent); border: 1px solid rgba(59,130,246,0.3); }

@keyframes flashIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Security Badge ── */
.security-badge {
    display: flex; align-items: center; gap: 8px;
    background: rgba(16,185,129,0.08); border: 1px solid rgba(16,185,129,0.2);
    border-radius: var(--radius-sm); padding: 10px 16px;
    font-size: 0.85rem; color: var(--success);
}
.security-badge .icon { font-size: 1.1rem; }

/* ── Steps / Progress ── */
.steps { display: flex; gap: 0; margin-bottom: 32px; }
.step {
    flex: 1; text-align: center; padding: 12px 8px;
    font-size: 0.85rem; font-weight: 600; color: var(--text-muted);
    border-bottom: 3px solid var(--border); transition: all var(--transition);
}
.step.active { color: var(--accent); border-bottom-color: var(--accent); }
.step.done { color: var(--success); border-bottom-color: var(--success); }
.step-number {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--border); color: var(--text-muted);
    font-size: 0.8rem; margin-bottom: 4px;
}
.step.active .step-number { background: var(--accent); color: white; }
.step.done .step-number { background: var(--success); color: white; }

/* ── Vault Categories ── */
.categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.category-btn {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 16px 12px; background: var(--bg-card); border: 2px solid var(--border);
    border-radius: var(--radius); cursor: pointer; transition: all var(--transition);
    font-family: var(--font); color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
}
.category-btn .icon { font-size: 28px; }
.category-btn .count { font-size: 0.75rem; color: var(--text-muted); }
.category-btn:hover, .category-btn.active {
    border-color: var(--accent); color: var(--text-primary);
    background: var(--accent-light);
}

/* ── Vault Items ── */
.vault-list { display: flex; flex-direction: column; gap: 8px; }
.vault-item {
    display: flex; align-items: center; gap: 16px;
    padding: 16px 20px; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; transition: all var(--transition);
}
.vault-item:hover { border-color: var(--accent); background: var(--bg-card-hover); }
.vault-item .item-icon { font-size: 24px; flex-shrink: 0; }
.vault-item .item-info { flex: 1; min-width: 0; }
.vault-item .item-label { font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault-item .item-value { font-size: 0.85rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault-item .item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.vault-item .action-btn {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-secondary);
    color: var(--text-muted); cursor: pointer; display: flex;
    align-items: center; justify-content: center; font-size: 16px;
    transition: all var(--transition);
}
.vault-item .action-btn:hover { border-color: var(--accent); color: var(--accent); }
.vault-item .action-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0; background: var(--bg-modal);
    display: none; align-items: center; justify-content: center;
    z-index: 1000; padding: 20px;
    animation: fadeIn 0.2s ease;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 32px;
    max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); animation: slideUp 0.3s ease;
}
.modal-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ── Hero Section (Landing) ── */
.hero {
    text-align: center; padding: 80px 20px 60px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}
.hero h1 { font-size: 2.5rem; margin-bottom: 16px; }
.hero .subtitle { font-size: 1.15rem; max-width: 600px; margin: 0 auto 32px; }
.hero-actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; padding: 40px 0; }
.feature {
    text-align: center; padding: 32px 24px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); transition: all var(--transition);
}
.feature:hover { border-color: var(--accent); }
.feature .icon { font-size: 40px; margin-bottom: 16px; }
.feature h3 { margin-bottom: 8px; }
.feature p { color: var(--text-secondary); font-size: 0.95rem; }

/* ── Footer ── */
.footer {
    text-align: center; padding: 24px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem; color: var(--text-muted);
}

/* ── Inactivity Warning Bar ── */
.inactivity-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--warning-bg); border-top: 2px solid var(--warning);
    padding: 12px 20px; text-align: center;
    font-weight: 600; color: var(--warning); z-index: 999;
    display: none; animation: slideUp 0.3s ease;
}

/* ── Copy Tooltip ── */
.copy-tooltip {
    position: absolute; top: -30px; left: 50%; transform: translateX(-50%);
    background: var(--success); color: white; padding: 4px 12px;
    border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 600;
    white-space: nowrap; pointer-events: none;
    animation: fadeIn 0.2s ease;
}

/* ── Safe Area (iPhone notch / Dynamic Island) ── */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── Responsive — Smartphone (≤ 600px) ── */
@media (max-width: 600px) {

    /* --- Header --- */
    .header {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .logo-icon { width: 32px; height: 32px; font-size: 17px; }
    .logo-text { font-size: 18px; }
    .header-actions {
        width: 100%;
        justify-content: flex-end;
        gap: 6px;
    }
    .header-actions .btn { padding: 6px 12px; font-size: 0.8rem; }
    .lang-switch { padding: 2px; }
    .lang-btn { padding: 5px 10px; font-size: 12px; }

    /* --- Hero --- */
    .hero { padding: 40px 16px 30px; }
    .hero h1 { font-size: 1.6rem; }
    .hero .subtitle { font-size: 0.95rem; margin-bottom: 24px; }
    .hero-actions { gap: 10px; }
    .hero-actions .btn-lg { padding: 12px 20px; font-size: 0.95rem; }

    /* --- Typography --- */
    h1 { font-size: 1.4rem; }
    h2 { font-size: 1.2rem; }
    h3 { font-size: 1.05rem; }
    .subtitle { font-size: 0.9rem; }

    /* --- Container --- */
    .container, .container-sm { padding: 0 14px; }
    .page-content { padding: 24px 0; }

    /* --- Card --- */
    .card { padding: 18px 16px; border-radius: var(--radius-sm); }

    /* --- Categories grid: 3 columns for 6-7" --- */
    .categories,
    #categories-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }
    .category-btn { padding: 10px 6px; }
    .category-btn .icon { font-size: 22px; }
    .category-btn .count { font-size: 0.7rem; }
    /* Category card inline styles override */
    #categories-grid > div {
        padding: 12px 8px !important;
    }
    #categories-grid > div > div:first-child {
        font-size: 1.6rem !important;
    }
    #categories-grid > div > div:nth-child(2) {
        font-size: 0.78rem !important;
    }
    #categories-grid > div > div:nth-child(3) {
        font-size: 1.3rem !important;
    }
    #categories-grid > div > button {
        padding: 4px 8px !important;
        font-size: 0.72rem !important;
    }

    /* --- Vault items: actions wrap --- */
    .vault-item { padding: 12px 12px; gap: 10px; flex-wrap: wrap; }
    .vault-item .item-icon { font-size: 20px; }
    .vault-item .item-info { min-width: 0; }
    .vault-item .item-label { font-size: 0.92rem; }
    .vault-item .item-value { font-size: 0.8rem; }
    .vault-item .item-actions { gap: 4px; }
    .vault-item .action-btn { width: 32px; height: 32px; font-size: 14px; }
    /* Inline-styled action buttons in vault items */
    .vault-item div[style*="display:flex"][style*="border-top"] {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .vault-item div[style*="display:flex"][style*="border-top"] button {
        padding: 6px 12px !important;
        font-size: 0.78rem !important;
    }

    /* --- Vault welcome bar --- */
    .vault-item + .flex,
    .container > .flex.items-center.justify-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px !important;
    }

    /* --- Search bar --- */
    #vault-search { max-width: 100% !important; width: 100% !important; }
    #add-btn { width: 100%; }

    /* --- Banners SOS + Condividi: stack vertical --- */
    div[style*="display:flex"][style*="gap:16px"][style*="margin-top:24px"] {
        flex-direction: column !important;
    }
    div[style*="display:flex"][style*="gap:16px"][style*="margin-top:24px"] > * {
        min-width: unset !important;
    }

    /* --- Features grid --- */
    .features { grid-template-columns: 1fr; gap: 12px; padding: 24px 0; }
    .feature { padding: 20px 16px; }
    .feature .icon { font-size: 32px; margin-bottom: 10px; }

    /* --- Modals: viewport-safe --- */
    .modal-overlay { padding: 12px; }
    .modal {
        padding: 22px 18px;
        max-width: calc(100vw - 24px) !important;
        max-height: 85vh;
        border-radius: var(--radius);
    }
    .modal-title { font-size: 1.15rem; margin-bottom: 16px; }
    .modal-actions { gap: 8px; margin-top: 18px; }
    .modal-actions .btn { padding: 10px 16px; font-size: 0.9rem; flex: 1; }

    /* --- OTP input (delete account) --- */
    #del-otp-input {
        font-size: 1.4rem !important;
        letter-spacing: 5px !important;
    }

    /* --- Steps (registration) --- */
    .steps { gap: 0; }
    .step { font-size: 0.72rem; padding: 8px 3px; }
    .step-number { width: 24px; height: 24px; font-size: 0.72rem; }

    /* --- SOS page --- */
    .card-header .icon, div[style*="font-size:56px"] {
        font-size: 40px !important;
    }

    /* --- Buttons touch-friendly --- */
    .btn-lg { padding: 14px 22px; font-size: 1rem; }
    .btn-sos { font-size: 1.05rem; padding: 16px 28px; }
    .btn-sm { padding: 7px 14px; font-size: 0.82rem; }
    .btn-full { width: 100%; }

    /* --- Security badge --- */
    .security-badge { font-size: 0.8rem; padding: 8px 12px; }

    /* --- Flash messages --- */
    .flash { font-size: 0.88rem; padding: 12px 14px; }

    /* --- Footer --- */
    .footer { padding: 16px 14px; font-size: 0.75rem; }

    /* --- Form inputs touch-friendly --- */
    .form-input, .form-select { padding: 11px 14px; font-size: 0.95rem; }
    .form-textarea { min-height: 80px; }
    .form-label { font-size: 0.85rem; }

    /* --- Inactivity bar --- */
    .inactivity-bar { font-size: 0.85rem; padding: 10px 14px; }
}

/* ── Extra small (< 380px, small phones) ── */
@media (max-width: 380px) {
    .header { padding: 8px 10px; }
    .logo-icon { display: none; }
    .logo-text { font-size: 16px; }
    .hero h1 { font-size: 1.35rem; }
    .card { padding: 14px 12px; }
    h1 { font-size: 1.25rem; }
    #categories-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .modal { padding: 18px 14px; }
    .btn-sos { font-size: 0.95rem; padding: 14px 20px; }
}

/* ── Print ── */
@media print {
    body { background: white; color: black; }
    .header, .footer, .btn, .lang-switch, .action-btn, .inactivity-bar { display: none !important; }
    .card { background: white; border: 1px solid #ccc; box-shadow: none; }
    .vault-item { border: 1px solid #ddd; background: white; }
}

/* ── Loading Spinner ── */
.spinner {
    display: inline-block; width: 20px; height: 20px;
    border: 2.5px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ── */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.hidden { display: none !important; }
