:root {
    /* iOS System Colors */
    --system-blue: #007AFF;
    --system-blue-active: #0056b3;
    --system-red: #FF3B30;
    --system-red-active: #c22921;
    --system-green: #34C759;
    --system-background: #F2F2F7;
    --system-card: #FFFFFF;
    --system-text: #1C1C1E;
    --system-text-secondary: #8E8E93;
    --system-separator: #C6C6C8;
    --system-overlay: rgba(0, 0, 0, 0.4);

    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;

    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
    --shadow-sheet: 0 -10px 40px rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--system-background);
    color: var(--system-text);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;

    /* Protezione Selezione */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* Permettiamo la selezione e il drag solo negli input e select */
input,
select {
    -webkit-user-select: auto;
    -moz-user-select: auto;
    -ms-user-select: auto;
    user-select: auto;
}

.app-wrapper {
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.5px;
    order: 1;
}

.icon-button {
    background: var(--system-card);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--system-blue);
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: transform 0.1s, background-color 0.2s;
    order: 2;
}

.icon-button:active {
    background-color: #E5E5EA;
    transform: scale(0.95);
}

/* Status Card */
.status-card {
    flex-grow: 1;
    width: 100%;
    order: 3;
    margin: 0;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.status-main {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.status-label {
    font-size: 15px;
    color: var(--system-text-secondary);
    font-weight: 500;
}

.status-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--system-green);
    letter-spacing: -0.5px;
}

.status-meta {
    font-size: 13px;
    color: var(--system-text-secondary);
}

/* Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    align-items: start;
}

@media (min-width: 900px) {
    .main-content {
        grid-template-columns: 3fr 2fr;
    }

    .header {
        flex-wrap: nowrap;
    }

    .status-card {
        order: 2;
        width: auto;
    }

    .icon-button {
        order: 3;
    }
}

/* Cards */
.card {
    background-color: var(--system-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-soft);
}

.card h2 {
    font-size: 22px;
    margin-top: 0;
    margin-bottom: 20px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

/* Forms */
form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 15px;
    font-weight: 500;
    color: var(--system-text);
    text-align: center;
}

input[type="number"],
input[type="text"] {
    font-size: 22px;
    padding: 18px 20px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--system-background);
    color: var(--system-text);
    font-family: inherit;
    transition: all 0.2s;
    width: 100%;
    text-align: center;
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--system-blue);
    background-color: #fff;
}

/* Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

button {
    font-family: inherit;
    font-size: 17px;
    font-weight: 600;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.btn-primary {
    background-color: var(--system-blue);
    color: white;
}

.btn-primary:active {
    background-color: var(--system-blue-active);
    transform: scale(0.98);
}

.btn-secondary {
    background-color: #E5E5EA;
    color: var(--system-red);
}

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

.btn-outline {
    background-color: transparent;
    color: var(--system-blue);
    border: 1px solid var(--system-blue);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 15px;
}

.btn-outline:active {
    background-color: rgba(0, 122, 255, 0.1);
}

.w-100 {
    width: 100%;
}

/* Results */
.result-display {
    margin-top: 32px;
    padding: 24px;
    background-color: #F8F9FA;
    border-radius: var(--radius-md);
    text-align: center;
    animation: fadeIn 0.4s ease-out;
}

.result-label {
    display: block;
    font-size: 14px;
    color: var(--system-text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 8px;
}

#risultato {
    font-size: 42px;
    font-weight: 700;
    color: var(--system-blue);
    margin: 0;
    letter-spacing: -1px;
}

.extra-costs-box {
    margin-top: 16px;
    padding: 16px;
    background-color: #F2F2F7;
    border-radius: var(--radius-sm);
    font-size: 16px;
    color: var(--system-text-secondary);
    text-align: center;
}

.extra-costs-box p {
    margin: 4px 0;
}

.nascosto {
    display: none !important;
}

/* History */
.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-list li {
    padding: 16px;
    background-color: var(--system-background);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--system-text);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.02);
}

/* Modal / Sheet */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal.show {
    opacity: 1;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--system-overlay);
}

.modal-content.sheet {
    position: relative;
    width: 100%;
    max-width: 600px;
    background-color: var(--system-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 0 0 32px 0;
    box-shadow: var(--shadow-sheet);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    max-height: 90vh;
    overflow-y: auto;
}

.modal.show .modal-content.sheet {
    transform: translateY(0);
}

@media (min-width: 768px) {
    .modal {
        align-items: center;
        padding: 20px;
    }

    .modal-content.sheet {
        border-radius: var(--radius-lg);
        max-height: 80vh;
    }
}

.sheet-handle {
    width: 40px;
    height: 5px;
    background-color: #E5E5EA;
    border-radius: 3px;
    margin: 12px auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 24px 16px 24px;
    border-bottom: 1px solid var(--system-separator);
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.close-btn {
    background: transparent;
    color: var(--system-blue);
    font-weight: 600;
    font-size: 17px;
    padding: 0;
    width: auto;
}

.close-btn:active {
    background: transparent;
    opacity: 0.7;
    transform: none;
}

.modal-body {
    padding: 24px;
}

/* Settings Form */
.settings-group {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-group label {
    font-size: 15px;
    font-weight: 500;
    color: var(--system-text);
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: "▼";
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--system-text-secondary);
    pointer-events: none;
}

select {
    width: 100%;
    appearance: none;
    font-size: 18px;
    padding: 14px 16px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--system-background);
    color: var(--system-text);
    font-family: inherit;
    cursor: pointer;
}

select:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--system-blue);
}

.help-text {
    font-size: 13px;
    color: var(--system-text-secondary);
    margin: 0;
}

.update-group {
    background-color: #F8F9FA;
    padding: 16px;
    border-radius: var(--radius-md);
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 0;
}

.footer p {
    font-size: 14px;
    color: var(--system-text-secondary);
    cursor: pointer;
    margin: 0;
    display: inline-block;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}