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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #f8faf7 0%, #e8f3e8 100%);
    color: #2c3e2c;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 40px;
}

.header {
    text-align: center;
    margin-bottom: 20px;
    padding-top: 8px;
}

.header h1 {
    font-size: 22px;
    font-weight: 600;
    color: #1a5c3a;
}

.date {
    font-size: 13px;
    color: #6b8a6b;
    margin-top: 4px;
    text-transform: capitalize;
}

.link-btn {
    background: none;
    border: none;
    color: #2d8659;
    font-size: 13px;
    margin-top: 8px;
    text-decoration: underline;
    cursor: pointer;
    padding: 4px 8px;
}

.totals {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

@media (min-width: 600px) {
    .totals {
        grid-template-columns: repeat(4, 1fr);
    }
}

.total-card {
    background: white;
    border-radius: 10px;
    border-left: 4px solid;
    padding: 12px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.total-calories { border-left-color: #17a2b8; }
.total-protein { border-left-color: #9b59b6; }
.total-carbs { border-left-color: #f39c12; }
.total-fat { border-left-color: #e74c3c; }

.total-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: #1a5c3a;
}

.total-label {
    font-size: 11px;
    color: #7a9a7a;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
    display: block;
}

.meal-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    border-top: 3px solid #2d8659;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.meal-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a5c3a;
    margin-bottom: 10px;
}

.meal-info {
    background: #f8faf7;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    position: relative;
}

.meal-time {
    font-size: 12px;
    font-weight: 700;
    color: #1a5c3a;
}

.meal-desc {
    font-size: 14px;
    color: #1a2b1a;
    margin-top: 2px;
    word-wrap: break-word;
    font-weight: 500;
}

.meal-macros {
    font-size: 12px;
    color: #2c3e2c;
    margin-top: 4px;
    font-weight: 500;
    padding-right: 40px;
}

.meal-macros-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.meal-details-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    background: #ecf5ec;
    color: #1a5c3a;
    border: 1px solid #d4e8d4;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 700;
    font-size: 16px;
    font-style: italic;
    font-family: Georgia, serif;
    padding: 0;
    transition: background 0.15s;
}

.meal-details-btn:active {
    background: #d4e8d4;
}

.button-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.button-row + .button-row {
    margin-top: 8px;
}

.btn-primary, .btn-secondary, .btn-danger {
    flex: 1;
    min-width: 100px;
    padding: 12px 14px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
    font-family: inherit;
}

.btn-primary {
    background: #2d8659;
    color: white;
}

.btn-primary:active {
    background: #1a5c3a;
    transform: scale(0.98);
}

.btn-primary:disabled {
    background: #a0c0a0;
    cursor: not-allowed;
}

.btn-secondary {
    background: #ecf5ec;
    color: #2d8659;
    border: 1px solid #d4e8d4;
}

.btn-secondary:active {
    background: #dcebd8;
    transform: scale(0.98);
}

.btn-danger {
    background: #f8d7da;
    color: #c0392b;
}

.btn-danger:active {
    background: #f5c6ce;
    transform: scale(0.98);
}

.sheets-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-top: 8px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.sheets-card h2 {
    font-size: 16px;
    font-weight: 600;
    color: #1a5c3a;
    margin-bottom: 10px;
}

.sheets-text {
    font-size: 13px;
    color: #5a7c5a;
    margin-bottom: 10px;
    line-height: 1.4;
}

.sheets-text.connected {
    color: #2d8659;
    font-weight: 500;
}

.spinner-container {
    display: flex;
    justify-content: center;
    padding: 12px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #ecf5ec;
    border-top-color: #2d8659;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    z-index: 100;
    overflow: hidden;
}

.modal-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.modal-card h2 {
    font-size: 16px;
    font-weight: 600;
    color: #1a5c3a;
    margin-bottom: 12px;
}

.modal-subtitle {
    font-size: 14px;
    font-weight: 600;
    color: #1a5c3a;
    margin-top: 4px;
    margin-bottom: 8px;
}

.modal-divider {
    border: none;
    border-top: 1px solid #d4e8d4;
    margin: 16px 0;
}

.subtitle {
    font-size: 13px;
    color: #5a7c5a;
    margin-top: 2px;
    font-style: italic;
}

#subtitleVersion {
    font-family: monospace;
    font-style: normal;
    font-size: 11px;
    color: #7a9a7a;
    letter-spacing: 0.3px;
}

.ai-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px;
    background: #f8faf7;
    border-radius: 8px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #2c3e2c;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.radio-option:hover {
    background: #ecf5ec;
}

.radio-option input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: #2d8659;
    margin: 0;
}

.modal-label {
    font-size: 13px;
    color: #5a7c5a;
    display: block;
    margin-bottom: 6px;
}

.modal-hint {
    font-size: 12px;
    color: #7a9a7a;
    margin-top: 6px;
    margin-bottom: 12px;
}

input[type="password"], input[type="text"], textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #d4e8d4;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fafcf9;
    color: #2c3e2c;
    outline: none;
    margin-bottom: 12px;
}

input:focus, textarea:focus {
    border-color: #2d8659;
    background: white;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.footer {
    text-align: center;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid #d4e8d4;
}

.footer p {
    font-size: 11px;
    color: #7a9a7a;
}

.version {
    margin-top: 4px !important;
    font-size: 10px !important;
    color: #a0c0a0 !important;
    font-family: monospace;
}

.version-badge {
    font-size: 11px;
    color: #7a9a7a;
    font-weight: normal;
    font-family: monospace;
    margin-left: 8px;
    background: #ecf5ec;
    padding: 2px 6px;
    border-radius: 4px;
}

.diagnostic-info {
    background: #f8faf7;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 11px;
    color: #5a7c5a;
    font-family: monospace;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
    word-break: break-all;
}

.diagnostic-info .diag-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px dashed #d4e8d4;
}

.diagnostic-info .diag-row:last-child {
    border-bottom: none;
}

.diagnostic-info .diag-label {
    font-weight: 700;
    color: #1a5c3a;
    margin-right: 8px;
}

.diagnostic-info .diag-value {
    color: #5a7c5a;
    text-align: right;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a5c3a;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 200;
    max-width: 90%;
    text-align: center;
}

.toast.error {
    background: #c0392b;
}

.toast.success {
    background: #27ae60;
}

@media (max-width: 400px) {
    .button-row {
        flex-direction: column;
    }
    .btn-primary, .btn-secondary, .btn-danger {
        flex: none;
        width: 100%;
    }
}

.header-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 8px;
}

.header-buttons .link-btn {
    margin-top: 0;
}

/* ============ MODAL STORICO FULLSCREEN ============ */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #f8faf7 0%, #e8f3e8 100%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow: hidden;
}

.fullscreen-modal.hidden {
    display: none;
}

.history-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #d4e8d4;
    background: white;
    gap: 12px;
}

.history-close-btn {
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: #1a5c3a;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.history-close-btn:active {
    background: #ecf5ec;
}

.history-close-btn svg {
    width: 26px;
    height: 26px;
}

.history-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: #1a5c3a;
}

.history-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #d4e8d4;
}

.history-tab {
    flex: 1;
    padding: 10px 12px;
    background: #ecf5ec;
    color: #5a7c5a;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.history-tab.active {
    background: #2d8659;
    color: white;
}

.history-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

.day-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 8px 12px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.day-nav-btn {
    background: #ecf5ec;
    color: #2d8659;
    border: 1px solid #d4e8d4;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    min-width: 44px;
}

.day-nav-btn:disabled {
    opacity: 0.3;
}

.day-nav-date {
    font-size: 14px;
    font-weight: 600;
    color: #1a5c3a;
    text-align: center;
    text-transform: capitalize;
    flex: 1;
}

.day-empty {
    text-align: center;
    padding: 40px 20px;
    color: #7a9a7a;
    font-size: 14px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.day-totals {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.day-total-card {
    background: white;
    border-radius: 10px;
    padding: 10px 6px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
    border-top: 3px solid;
}

.day-total-card.calories { border-top-color: #17a2b8; }
.day-total-card.protein { border-top-color: #9b59b6; }
.day-total-card.carbs { border-top-color: #f39c12; }
.day-total-card.fat { border-top-color: #e74c3c; }

.day-total-value {
    font-size: 18px;
    font-weight: 700;
    color: #1a5c3a;
    display: block;
}

.day-total-label {
    font-size: 10px;
    color: #7a9a7a;
    text-transform: uppercase;
    margin-top: 2px;
    display: block;
}

.day-meal-card {
    background: white;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
    border-left: 4px solid #2d8659;
}

.day-meal-card.empty {
    opacity: 0.5;
    border-left-color: #d4e8d4;
}

.day-meal-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}

.day-meal-name {
    font-size: 14px;
    font-weight: 700;
    color: #1a5c3a;
}

.day-meal-time {
    font-size: 12px;
    color: #2d8659;
    font-weight: 600;
}

.day-meal-desc {
    font-size: 13px;
    color: #2c3e2c;
    margin-bottom: 6px;
    line-height: 1.4;
}

.day-meal-macros {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 11px;
    color: #5a7c5a;
}

.day-meal-macros span {
    background: #f8faf7;
    padding: 2px 8px;
    border-radius: 4px;
}

.day-meal-macros .kcal {
    background: #fef2e6;
    color: #b8500d;
    font-weight: 700;
}

.day-meal-empty-text {
    font-size: 12px;
    color: #a0c0a0;
    font-style: italic;
}

.week-nav, .month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 10px 14px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.week-nav-label, .month-nav-label {
    font-size: 14px;
    font-weight: 600;
    color: #1a5c3a;
    text-align: center;
    flex: 1;
    text-transform: capitalize;
}

.week-days {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.week-day-card {
    background: white;
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-left: 4px solid #d4e8d4;
}

.week-day-card.has-data {
    border-left-color: #2d8659;
}

.week-day-card.today {
    background: linear-gradient(135deg, #f8faf7 0%, #dcebd8 100%);
    border-left-color: #e67e22;
}

.week-day-name {
    font-size: 13px;
    font-weight: 700;
    color: #1a5c3a;
    text-transform: capitalize;
    min-width: 90px;
    display: flex;
    flex-direction: column;
}

.week-day-name .day-num {
    font-size: 18px;
}

.week-day-name .day-label {
    font-size: 10px;
    color: #7a9a7a;
    text-transform: uppercase;
}

.week-day-stats {
    flex: 1;
    font-size: 12px;
    color: #5a7c5a;
}

.week-day-cal {
    font-size: 16px;
    font-weight: 700;
    color: #e67e22;
}

.week-day-macros {
    display: flex;
    gap: 10px;
    margin-top: 2px;
    font-size: 11px;
    color: #7a9a7a;
}

.week-day-arrow {
    color: #a0c0a0;
    font-size: 20px;
}

.week-day-empty {
    font-size: 12px;
    color: #a0c0a0;
    font-style: italic;
}

.month-legend {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px;
    background: white;
    border-radius: 8px;
    font-size: 10px;
    color: #7a9a7a;
    flex-wrap: wrap;
}

.month-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.month-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.month-grid {
    background: white;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 2px 6px rgba(26, 92, 58, 0.08);
}

.month-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 6px;
}

.month-weekday {
    font-size: 10px;
    font-weight: 700;
    color: #7a9a7a;
    text-transform: uppercase;
    text-align: center;
    padding: 4px 0;
}

.month-cells {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.month-cell {
    aspect-ratio: 1;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    background: #f8faf7;
    color: #2c3e2c;
    cursor: pointer;
    padding: 2px;
}

.month-cell.empty {
    background: transparent;
    cursor: default;
}

.month-cell.today {
    outline: 2px solid #e67e22;
    outline-offset: -2px;
}

.month-cell .cell-num {
    font-size: 14px;
    font-weight: 700;
}

.month-cell .cell-cal {
    font-size: 8px;
    opacity: 0.8;
    margin-top: 1px;
}

.month-cell.cal-none { background: #f8faf7; color: #b0c8b0; }
.month-cell.cal-low { background: #dcebd8; color: #1a5c3a; }
.month-cell.cal-med { background: #a8d5a8; color: #0f3a24; }
.month-cell.cal-high { background: #6fb26f; color: white; }
.month-cell.cal-vhigh { background: #2d8659; color: white; }

.day-nav-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.day-today-btn {
    background: #2d8659;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.day-today-btn:active {
    background: #1a5c3a;
}

/* ============ SCHERMATA SBLOCCO / LICENZA ============ */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a5c3a 0%, #0f3a24 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.lock-screen.hidden {
    display: none;
}

.lock-card {
    background: white;
    border-radius: 20px;
    padding: 32px 24px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.lock-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.lock-card h1 {
    font-size: 28px;
    color: #1a5c3a;
    font-weight: 700;
    margin-bottom: 4px;
}

.lock-subtitle {
    font-size: 14px;
    color: #5a7c5a;
    font-style: italic;
    margin-bottom: 24px;
}

.lock-message {
    font-size: 14px;
    color: #2c3e2c;
    margin-bottom: 20px;
    line-height: 1.5;
}

#unlockCodeInput {
    width: 100%;
    padding: 14px 12px;
    border: 2px solid #d4e8d4;
    border-radius: 10px;
    font-size: 15px;
    font-family: monospace;
    text-align: center;
    letter-spacing: 1px;
    background: #f8faf7;
    margin-bottom: 16px;
    outline: none;
    text-transform: uppercase;
}

#unlockCodeInput:focus {
    border-color: #2d8659;
    background: white;
}

.lock-card .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    margin-bottom: 16px;
}

.lock-contact-btn {
    display: inline-block;
    text-decoration: none;
    padding: 14px 24px;
    font-size: 16px;
    margin-top: 20px;
}

.lock-error {
    color: #c0392b;
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #fadbd8;
    border-radius: 6px;
}

.lock-footer {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #ecf5ec;
}

.lock-footer p {
    font-size: 12px;
    color: #7a9a7a;
    margin-bottom: 8px;
}

.lock-contact {
    display: inline-block;
    color: #2d8659;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    padding: 8px 16px;
    background: #ecf5ec;
    border-radius: 6px;
}

/* ============ WATERMARK ============ */
.watermark {
    font-size: 10px !important;
    color: #a0c0a0 !important;
    margin-top: 8px !important;
    font-family: monospace;
    letter-spacing: 0.3px;
}

.watermark-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    color: #2d8659;
    text-decoration: none;
    background: #ecf5ec;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 600;
}

/* ============ PANNELLO ADMIN ============ */
.admin-login {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.admin-login-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 4px 20px rgba(26, 92, 58, 0.15);
}

.admin-login-card h3 {
    font-size: 18px;
    color: #1a5c3a;
    margin-bottom: 16px;
    text-align: center;
}

.admin-login-card input {
    width: 100%;
    padding: 12px;
    border: 1px solid #d4e8d4;
    border-radius: 8px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
}

.admin-login-card input:focus {
    border-color: #2d8659;
}

.admin-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.admin-content.hidden {
    display: none;
}

.admin-section {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(26, 92, 58, 0.08);
}

.admin-section h3 {
    font-size: 15px;
    color: #1a5c3a;
    font-weight: 700;
    margin-bottom: 12px;
}

.admin-label {
    display: block;
    font-size: 12px;
    color: #5a7c5a;
    margin-bottom: 4px;
    margin-top: 8px;
    font-weight: 600;
}

.admin-section input[type="text"],
.admin-section input[type="date"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #d4e8d4;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
    background: #fafcf9;
}

.admin-section input:focus {
    border-color: #2d8659;
    background: white;
}

.admin-result {
    margin-top: 16px;
    padding: 12px;
    background: #ecf5ec;
    border-radius: 8px;
    border: 1px solid #d4e8d4;
}

.admin-result.hidden {
    display: none;
}

.admin-result h4 {
    font-size: 13px;
    color: #1a5c3a;
    margin-bottom: 8px;
}

.admin-url {
    font-family: monospace;
    font-size: 11px;
    color: #2c3e2c;
    background: white;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    word-break: break-all;
    border: 1px solid #d4e8d4;
    max-height: 100px;
    overflow-y: auto;
}

.admin-hint {
    font-size: 11px;
    color: #7a9a7a;
    margin-top: 8px;
    font-style: italic;
}

.admin-terms {
    font-size: 12px;
    color: #5a7c5a;
    line-height: 1.6;
}

.admin-terms p {
    margin-bottom: 10px;
}

.admin-terms strong {
    color: #1a5c3a;
}

/* ============ BARRA DI PROGRESSO CARD TOTALI ============ */
.total-card {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

.total-progress {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    z-index: 1;
    transition: width 0.4s ease, background-color 0.4s ease, opacity 0.3s ease;
    background: rgba(200, 200, 200, 0.2);
}

.total-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    cursor: pointer;
}

.total-target {
    font-size: 9px;
    color: #7a9a7a;
    margin-top: 2px;
    font-family: monospace;
}

/* Colori per macronutriente (2 tonalità: chiaro → intenso al riempimento) */
/* CALORIE - celeste */
.total-calories .total-progress.level-1 { background: rgba(23, 162, 184, 0.15); }
.total-calories .total-progress.level-2 { background: rgba(23, 162, 184, 0.35); }
.total-calories .total-progress.level-3 { background: rgba(23, 162, 184, 0.55); }
.total-calories .total-progress.level-4 { background: rgba(23, 162, 184, 0.78); }

/* PROTEINE - viola */
.total-protein .total-progress.level-1 { background: rgba(155, 89, 182, 0.15); }
.total-protein .total-progress.level-2 { background: rgba(155, 89, 182, 0.35); }
.total-protein .total-progress.level-3 { background: rgba(155, 89, 182, 0.55); }
.total-protein .total-progress.level-4 { background: rgba(155, 89, 182, 0.78); }

/* CARBOIDRATI - arancione */
.total-carbs .total-progress.level-1 { background: rgba(243, 156, 18, 0.15); }
.total-carbs .total-progress.level-2 { background: rgba(243, 156, 18, 0.35); }
.total-carbs .total-progress.level-3 { background: rgba(243, 156, 18, 0.55); }
.total-carbs .total-progress.level-4 { background: rgba(243, 156, 18, 0.78); }

/* GRASSI - rosso porpora */
.total-fat .total-progress.level-1 { background: rgba(231, 76, 60, 0.15); }
.total-fat .total-progress.level-2 { background: rgba(231, 76, 60, 0.35); }
.total-fat .total-progress.level-3 { background: rgba(231, 76, 60, 0.55); }
.total-fat .total-progress.level-4 { background: rgba(231, 76, 60, 0.78); }

/* Al 100%+ tutte diventano rosse lampeggianti (allarme unico) */
.total-progress.level-max {
    background: linear-gradient(90deg, rgba(220, 60, 60, 0.9), rgba(200, 40, 40, 1));
    animation: pulseAlert 1.2s ease-in-out infinite;
}

/* Quando l'utente tocca per fermare il lampeggio, aggiungiamo la classe .no-blink */
.total-progress.level-max.no-blink {
    animation: none;
}

@keyframes pulseAlert {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* Quando siamo al 100%+, testo bianco per contrasto */
.total-card.at-max .total-value,
.total-card.at-max .total-label {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.total-card.at-max .total-target {
    color: rgba(255, 255, 255, 0.9) !important;
}

/* Feedback tattile al tocco della card lampeggiante */
.total-card.at-max:active .total-progress {
    opacity: 0.85;
}

/* ============ SEZIONE PROFILO NUTRIZIONALE ============ */
.profile-grid, .targets-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.profile-field {
    display: flex;
    flex-direction: column;
}

.profile-field label {
    margin-bottom: 4px;
}

.profile-field input,
.profile-field select,
#profileActivity {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d4e8d4;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: #fafcf9;
    color: #2c3e2c;
}

#profileActivity {
    margin-bottom: 4px;
}

.profile-field input:focus,
.profile-field select:focus,
#profileActivity:focus {
    outline: none;
    border-color: #2d8659;
    background: white;
}

.modal-mini-title {
    font-size: 13px;
    font-weight: 700;
    color: #1a5c3a;
    margin-top: 16px;
    margin-bottom: 8px;
}

/* ============ MODAL DETTAGLIO PORTATE ============ */
.portate-header-info {
    padding: 12px 16px;
    background: #f8faf7;
    border-bottom: 1px solid #d4e8d4;
}

.portate-meal-name {
    font-size: 16px;
    font-weight: 700;
    color: #1a5c3a;
}

.portate-meal-time {
    font-size: 12px;
    color: #5a7c5a;
    margin-top: 2px;
}

.portate-list {
    padding: 12px 16px;
}

.portata-row {
    padding: 12px 4px;
    border-bottom: 1px solid #e5efe5;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.portata-row:last-child {
    border-bottom: none;
}

.portata-nome {
    font-size: 14px;
    color: #1a2b1a;
    font-weight: 600;
    word-wrap: break-word;
    line-height: 1.3;
}

.portata-valori {
    font-size: 13px;
    color: #2c3e2c;
    font-family: monospace;
    padding-left: 8px;
    letter-spacing: -0.3px;
}

.portata-valori .kcal {
    font-weight: 700;
    color: #1a5c3a;
    font-size: 14px;
}

.portata-totale {
    margin-top: 16px;
    padding: 12px 10px;
    border: 2px solid #2d8659;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: linear-gradient(to right, #f8faf7, #ecf5ec);
    border-radius: 8px;
}

.portata-totale-label {
    font-size: 14px;
    font-weight: 700;
    color: #1a5c3a;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.portata-totale-valori {
    font-size: 14px;
    color: #1a5c3a;
    font-weight: 700;
    font-family: monospace;
    padding-left: 8px;
    letter-spacing: -0.3px;
}

/* ============ AZIONI PASTI STORICI ============ */
.day-meal-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e5efe5;
}

.day-meal-action-btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s;
}

.day-meal-action-btn.edit {
    background: #ecf5ec;
    color: #1a5c3a;
    border-color: #d4e8d4;
}

.day-meal-action-btn.edit:active {
    background: #d4e8d4;
}

.day-meal-action-btn.delete {
    background: #fadbd8;
    color: #c0392b;
    border-color: #f5b7b1;
}

.day-meal-action-btn.delete:active {
    background: #f5b7b1;
}

/* ============ BANNER BOZZE PENDENTI ============ */
.pending-drafts-banner {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 12px;
    padding: 12px;
    margin: 16px 0;
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.15);
}

.pending-header {
    font-size: 13px;
    font-weight: 700;
    color: #856404;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ffe082;
}

.pending-item {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid #ffe082;
}

.pending-item:last-child {
    margin-bottom: 0;
}

.pending-info {
    font-size: 13px;
    color: #1a2b1a;
}

.pending-info strong {
    color: #1a5c3a;
}

.pending-actions {
    display: flex;
    gap: 8px;
}

.pending-actions button {
    flex: 1;
    padding: 8px;
    font-size: 13px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

.pending-discard-btn {
    background: #fadbd8 !important;
    color: #c0392b !important;
}

/* ============ AZIONI PORTATE NEL MODAL DETTAGLIO ============ */
.portata-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #d4e8d4;
}

.portata-action-btn {
    flex: 1;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s;
    font-family: inherit;
}

.portata-action-btn.edit {
    background: #ecf5ec;
    color: #1a5c3a;
    border-color: #d4e8d4;
}

.portata-action-btn.edit:active {
    background: #d4e8d4;
}

.portata-action-btn.delete {
    background: #fadbd8;
    color: #c0392b;
    border-color: #f5b7b1;
}

.portata-action-btn.delete:active {
    background: #f5b7b1;
}

/* ============ MACROS ROW STORICO CON PULSANTE i ============ */
.day-meal-macros-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}

.day-meal-macros-row .day-meal-macros {
    flex: 1;
}

.day-details-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    border-radius: 6px;
    background: #ecf5ec;
    color: #1a5c3a;
    border: 1px solid #d4e8d4;
    font-size: 13px;
    font-weight: 700;
    font-style: italic;
    font-family: serif;
    cursor: pointer;
}

.day-details-btn:active {
    background: #d4e8d4;
}

/* Area riscrivi tutto nel modal Dettaglio */
.portata-riscrivi-area {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed #d4e8d4;
    text-align: center;
}

.portata-riscrivi-hint {
    margin-top: 6px;
    font-size: 11px;
    color: #6b8a6b;
    font-style: italic;
}

/* ============ NAVIGAZIONE GIORNI HEADER ============ */
.date-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 8px 0 6px 0;
}

.date-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #ecf5ec;
    color: #1a5c3a;
    border: 1px solid #d4e8d4;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s;
}

.date-nav-btn:active {
    background: #d4e8d4;
}

.date-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.date-nav-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 160px;
}

.date-nav-center .date {
    margin: 0;
}

.date-today-btn {
    padding: 4px 12px;
    background: #2d8659;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.date-today-btn:active {
    background: #1a5c3a;
}

.date-today-btn.hidden {
    display: none;
}

/* Indicatore visivo quando si è su un giorno passato */
.viewing-past-day #app {
    /* padding-top: 0 gia da altre regole */
}

.viewing-past-day .header {
    background: linear-gradient(180deg, #fff8e6 0%, transparent 100%);
    padding-top: 8px;
    border-radius: 12px 12px 0 0;
}
