/* --- Design Tokens --- */
:root {
    /* Colors */
    --bg-base: #f4f4f5; /* Light gray background */
    --bg-surface: #ffffff; /* Bianco richiesto */
    --bg-elevated: #ffffff;
    --text-primary: #333333;
    --text-secondary: #727272; /* Grigio richiesto */
    --accent: #db2723; /* Rosso richiesto */
    --accent-hover: #b9201d;
    --border: #e0e0e0;
    --danger: #db2723;

    /* Spacing */
    --sp-xs: 4px;
    --sp-sm: 8px;
    --sp-md: 16px;
    --sp-lg: 24px;
    --sp-xl: 32px;

    /* Layout */
    --header-height: 60px;
    --footer-height: 80px; /* Includes safe area for iOS */
    --safe-area-bottom: env(safe-area-inset-bottom, 20px);
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- Resets & Base --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-base);
    color: var(--text-primary);
    overflow: hidden; /* Prevent body scroll, handle scroll in main */
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
}

button {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    color: inherit;
}

a {color:#db2723; font-weight:bold;}


input, textarea {
    font-family: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

/* --- Typography --- */
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
h2 { font-size: 20px; font-weight: 600; margin-bottom: var(--sp-sm); }
h3 { font-size: 16px; font-weight: 600; }
p { font-size: 15px; line-height: 1.4; color: var(--text-secondary); }

/* --- Layout --- */
.app-header {
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

.header-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-md);
    width: 100%;
    padding: 0 var(--sp-md);
}

.logo-placeholder {
    width: 48px;
    height: 48px;
    /*background-color: var(--bg-base);*/
    /*border: 1px dashed var(--text-secondary);*/
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 600;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    padding-top: calc(var(--header-height) + env(safe-area-inset-top));
    padding-bottom: var(--footer-height);
    position: relative;
    scroll-behavior: smooth;
}

.app-footer {
    height: var(--footer-height);
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 100;
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-area-bottom);
}

/* --- Navigation --- */
.bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 100%;
    padding: 0 var(--sp-md);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    transition: color 0.2s ease, transform 0.2s ease;
    padding: var(--sp-sm);
    flex: 1;
}

.nav-btn span {
    font-size: 11px;
    font-weight: 500;
}

.nav-btn svg {
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nav-btn.active {
    color: var(--accent);
}

.nav-btn.active svg {
    transform: scale(1.15);
}

.nav-btn:active {
    transform: scale(0.95);
}

/* --- Views --- */
.view {
    display: none;
    padding: var(--sp-lg);
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: block;
}

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

.view-header {
    margin-bottom: var(--sp-lg);
}

/* --- Programma (Agenda) --- */
.agenda-day {
    margin-bottom: var(--sp-xl);
}

.agenda-day h2 {
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--sp-xs);
}

.agenda-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--sp-md);
    margin-top: var(--sp-md);
}

.agenda-item {
    display: flex;
    gap: var(--sp-md);
    background-color: var(--bg-surface);
    padding: var(--sp-md);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.agenda-time {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-secondary);
    min-width: 50px;
}

.agenda-details h3 {
    margin-bottom: var(--sp-xs);
    color: var(--text-primary);
}

/* --- Checklist --- */
#checklist-form {
    display: flex;
    gap: var(--sp-sm);
    margin-bottom: var(--sp-lg);
}

#new-task-input {
    flex: 1;
    background-color: var(--bg-surface);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 16px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

#new-task-input:focus {
    border-color: var(--accent);
}

.btn-primary {
    background-color: var(--accent);
    color: white;
    width: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-primary:active {
    transform: scale(0.95);
    background-color: var(--accent-hover);
}

.checklist-items {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
}

.checklist-item {
    display: flex;
    align-items: center;
    background-color: var(--bg-surface);
    padding: 12px 16px;
    border-radius: 12px;
    gap: var(--sp-md);
    transition: transform 0.2s, opacity 0.2s;
}

.checklist-item.done .item-text {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.custom-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.checklist-item.done .custom-checkbox {
    background-color: var(--accent);
    border-color: var(--accent);
}

.custom-checkbox svg {
    opacity: 0;
    color: white;
    width: 14px;
    height: 14px;
    transition: opacity 0.2s;
}

.checklist-item.done .custom-checkbox svg {
    opacity: 1;
}

.item-text {
    flex: 1;
    font-size: 16px;
    transition: color 0.2s;
    word-break: break-word;
}

.btn-delete {
    color: var(--danger);
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-delete:active {
    opacity: 1;
}

/* --- Appunti (Notes) --- */
.notes-container {
    height: calc(100vh - var(--header-height) - var(--footer-height) - 140px);
}

#notes-textarea {
    width: 100%;
    height: 100%;
    background-color: var(--bg-surface);
    border-radius: 16px;
    padding: var(--sp-md);
    font-size: 16px;
    line-height: 1.5;
    resize: none;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* --- Modals (PWA Install Bottom Sheet) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: flex-end; /* Bottom sheet layout by default (mobile) */
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content.bottom-sheet {
    background-color: var(--bg-elevated);
    border-radius: 24px 24px 0 0;
    padding: var(--sp-md) var(--sp-lg) calc(var(--sp-lg) + env(safe-area-inset-bottom, 16px)) var(--sp-lg);
    text-align: left; /* Left align for instruction list */
    box-shadow: 0 -8px 32px rgba(0,0,0,0.15);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.94, 0.6, 1);
    width: 100%;
    max-width: 100%;
    position: relative;
}

.modal-overlay.hidden .modal-content.bottom-sheet {
    transform: translateY(100%);
}

/* Regola aggiunta: fa salire la modale su mobile quando non è nascosta */
.modal-overlay:not(.hidden) .modal-content.bottom-sheet {
    transform: translateY(0);
}

/* Sheet drag handle indicator */
.sheet-handle {
    width: 36px;
    height: 5px;
    background-color: var(--border);
    border-radius: 3px;
    margin: 0 auto 16px auto;
}

/* Prompt Header with App Icon */
.modal-header {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    margin-bottom: var(--sp-md);
}

.app-icon-container {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    background-color: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border: 1px solid var(--border);
    overflow: hidden;
}

.app-prompt-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.app-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 0;
}

.prompt-desc {
    font-size: 14px;
    line-height: 1.45;
    color: var(--text-secondary);
    margin-bottom: var(--sp-lg);
}

/* Steps layout */
.instructions-steps {
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
    margin-bottom: var(--sp-lg);
}

.step-item {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    background-color: var(--bg-base);
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(0,0,0,0.02);
}

.step-badge {
    background-color: var(--accent);
    color: white;
    font-size: 13px;
    font-weight: 700;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-text {
    flex: 1;
    font-size: 13.5px;
    line-height: 1.4;
    color: var(--text-primary);
}

.step-text strong {
    font-weight: 600;
}

.step-icon-box {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background-color: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.04);
}

/* Actions */
.modal-actions {
    display: flex;
    gap: var(--sp-md);
}

.modal-actions button {
    flex: 1;
    padding: 14px;
    border-radius: 14px;
    font-weight: 600;
    font-size: 15px;
    transition: background-color 0.2s, transform 0.1s;
    border: none;
    cursor: pointer;
}

.btn-secondary {
    background-color: var(--bg-base);
    color: var(--text-primary);
}

.btn-secondary:active {
    background-color: var(--border);
    transform: scale(0.98);
}

.btn-primary-action {
    background-color: var(--accent);
    color: white;
}

.btn-primary-action:active {
    background-color: var(--accent-hover);
    transform: scale(0.98);
}

.btn-primary-action.full-width {
    width: 100%;
    flex: none;
}

.hidden {
    display: none !important;
}

/* Responsive details for Desktop view */
@media (min-width: 576px) {
    .modal-overlay {
        align-items: center; /* Center modal on tablet/desktop */
    }
    
    .modal-content.bottom-sheet {
        border-radius: 20px;
        max-width: 420px;
        padding: var(--sp-lg);
        transform: scale(0.9) translateY(20px);
        transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    
    .modal-overlay.hidden .modal-content.bottom-sheet {
        transform: scale(0.9) translateY(20px);
    }
    
    .modal-overlay:not(.hidden) .modal-content.bottom-sheet {
        transform: scale(1) translateY(0);
    }
    
    .sheet-handle {
        display: none; /* No drag handle on desktop */
    }
}
