/* ===== Com24 Forfettario - Compact business style ===== */

:root {
    --primary: #0a2540;
    --primary-2: #1e3a5f;
    --accent: #c79b50;
    --accent-2: #b3863a;
    --success: #0d8b5e;
    --warning: #c97a14;
    --danger: #b3261e;
    --info: #0b6b8a;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --text: #0e1a2b;
    --text-muted: #56627a;
    --text-soft: #8893a8;
    --border: #e2e6ee;
    --border-strong: #c8cfdc;

    --nav-h: 60px;
    --header-h: 56px;

    --r-sm: 6px;
    --r-md: 8px;
    --r-lg: 12px;

    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    overscroll-behavior-y: none;
    font-feature-settings: "tnum" 1, "ss01" 1;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    user-select: none;
    -webkit-user-select: none;
}

input, textarea { user-select: text; -webkit-user-select: text; }

/* === App shell === */
.app-shell {
    max-width: 460px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    box-shadow: 0 0 24px rgba(10,37,64,.06);
}

/* === Header === */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--primary);
    color: #fff;
    padding-top: var(--safe-top);
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-header > div { padding: 12px 14px !important; }

.app-header-title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: .01em;
    line-height: 1.1;
}

.app-header-sub {
    font-size: .7rem;
    opacity: .65;
    margin-top: 2px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.btn-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--r-sm);
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.06);
    color: #fff;
    font-size: .9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.btn-icon:active { background: rgba(255,255,255,.18); }
.btn-icon.muted { opacity: .5; }

/* === Main === */
.app-main {
    padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 16px);
    min-height: calc(100vh - var(--header-h));
}

.view { display: none; animation: fadeIn .18s ease; }
.view.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === Hero card === */
.hero-card {
    background: var(--primary);
    color: #fff;
    border-radius: var(--r-lg);
    padding: 14px 16px;
    margin-bottom: 10px;
    border: 1px solid var(--primary-2);
    position: relative;
    overflow: hidden;
}

.hero-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.04) 0%, transparent 60%);
    pointer-events: none;
}

.hero-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255,255,255,.6);
    font-weight: 600;
    margin-bottom: 4px;
}

.hero-amount {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -.02em;
    margin-bottom: 12px;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.hero-progress {
    height: 4px;
    background: rgba(255,255,255,.12);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.hero-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
    transition: width .5s ease, background .2s;
}

.hero-progress-bar.warn { background: #d99a3b; }
.hero-progress-bar.danger { background: #d44b3f; }

.hero-meta {
    font-size: .72rem;
    color: rgba(255,255,255,.65);
    margin-top: 6px !important;
    position: relative;
    z-index: 1;
    font-variant-numeric: tabular-nums;
}

/* === Stat grid === */
.row.g-3 { --bs-gutter-x: 8px; --bs-gutter-y: 8px; margin-bottom: 10px !important; }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 12px;
    height: 100%;
    position: relative;
    transition: border-color .15s;
}
.stat-card:active { border-color: var(--border-strong); }

.stat-icon {
    width: 24px;
    height: 24px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    margin-bottom: 6px;
}

.stat-warning .stat-icon { background: rgba(201,122,20,.1); color: var(--warning); }
.stat-success .stat-icon { background: rgba(13,139,94,.1); color: var(--success); }
.stat-info .stat-icon    { background: rgba(11,107,138,.1); color: var(--info); }
.stat-primary .stat-icon { background: rgba(10,37,64,.08); color: var(--primary); }

.stat-label {
    font-size: .65rem;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    line-height: 1.1;
}

.stat-value {
    font-size: .95rem;
    font-weight: 700;
    margin-top: 3px;
    letter-spacing: -.01em;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* === Semaforo === */
.semaforo-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 12px;
    margin-bottom: 10px;
    border-left: 3px solid var(--success);
    transition: border-color .2s;
}

.semaforo-card.state-green  { border-left-color: var(--success); }
.semaforo-card.state-yellow { border-left-color: #d99a3b; background: #fffbf2; }
.semaforo-card.state-red    { border-left-color: var(--danger); background: #fdf3f2; }

.semaforo {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #1a1a1a;
    padding: 6px;
    border-radius: var(--r-sm);
    border: 1px solid #000;
    box-shadow: inset 0 1px 2px rgba(255,255,255,.05);
    flex-shrink: 0;
}

.led {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #2a2a2a;
    border: 1px solid rgba(0,0,0,.4);
    transition: background .25s, box-shadow .25s;
}

.semaforo-card.state-green  .led-green {
    background: radial-gradient(circle at 35% 30%, #6bf08c, #0d8b5e 70%);
    box-shadow: 0 0 8px #1ec97a, inset 0 0 2px rgba(255,255,255,.4);
}
.semaforo-card.state-yellow .led-yellow {
    background: radial-gradient(circle at 35% 30%, #ffe79e, #d99a3b 70%);
    box-shadow: 0 0 10px #f4b431, inset 0 0 2px rgba(255,255,255,.5);
    animation: blinkYellow 1.4s infinite;
}
.semaforo-card.state-red .led-red {
    background: radial-gradient(circle at 35% 30%, #ff8a82, #b3261e 70%);
    box-shadow: 0 0 12px #ff3a30, inset 0 0 2px rgba(255,255,255,.5);
    animation: blinkRed .8s infinite;
}

@keyframes blinkYellow {
    0%, 100% { box-shadow: 0 0 10px #f4b431, inset 0 0 2px rgba(255,255,255,.5); }
    50%      { box-shadow: 0 0 16px #ffce5c, inset 0 0 2px rgba(255,255,255,.7); }
}
@keyframes blinkRed {
    0%, 100% { box-shadow: 0 0 12px #ff3a30, inset 0 0 2px rgba(255,255,255,.5); }
    50%      { box-shadow: 0 0 22px #ff5e54, inset 0 0 2px rgba(255,255,255,.8); }
}

.semaforo-text {
    flex: 1;
    min-width: 0;
}
.semaforo-status {
    font-weight: 700;
    font-size: .92rem;
    color: var(--text);
    line-height: 1.2;
}
.semaforo-card.state-yellow .semaforo-status { color: #7a4e0a; }
.semaforo-card.state-red    .semaforo-status { color: #6e1612; }

.semaforo-detail {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.led-mini {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.led-mini.led-green  { background: #0d8b5e; box-shadow: 0 0 4px rgba(13,139,94,.6); }
.led-mini.led-yellow { background: #d99a3b; box-shadow: 0 0 4px rgba(217,154,59,.6); }
.led-mini.led-red    { background: #b3261e; box-shadow: 0 0 4px rgba(179,38,30,.6); }

/* === Alert banner === */
.alert-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    margin-bottom: 10px;
    background: #fef6e7;
    color: #6b3e0a;
    border: 1px solid #f5d99a;
    border-left: 3px solid var(--warning);
    font-size: .8rem;
}

.alert-banner.danger {
    background: #fdecea;
    color: #5e1612;
    border-color: #f3b8b3;
    border-left-color: var(--danger);
}

.alert-banner i { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }
.alert-banner strong { font-size: .82rem; display: block; margin-bottom: 1px; }

/* === Advice card (suggerimenti business) === */
.advice-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px;
    margin-bottom: 10px;
    border-left: 3px solid var(--accent);
}

.advice-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--accent-2);
    font-weight: 700;
    margin-bottom: 8px;
}
.advice-head i { font-size: .9rem; }

.advice-list { display: flex; flex-direction: column; gap: 8px; }

.advice-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: .82rem;
    line-height: 1.4;
}

.advice-item .advice-bullet {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .7rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.advice-item.tip .advice-bullet    { background: rgba(11,107,138,.12); color: var(--info); }
.advice-item.warn .advice-bullet   { background: rgba(201,122,20,.12); color: var(--warning); }
.advice-item.danger .advice-bullet { background: rgba(179,38,30,.12); color: var(--danger); }
.advice-item.ok .advice-bullet     { background: rgba(13,139,94,.12); color: var(--success); }

.advice-item strong {
    font-weight: 600;
    color: var(--text);
}

.advice-num {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--primary);
}

/* === Tab switch (history) === */
.tab-switch {
    display: flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 3px;
    gap: 3px;
}

.tab-switch-item {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 4px;
    transition: background .15s, color .15s;
}

.tab-switch-item.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(10,37,64,.06);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn .15s ease; }

/* === Numeri fattura === */
.numeri-year {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 12px;
    margin-bottom: 8px;
}

.numeri-year-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
    margin-bottom: 8px;
}

.numeri-year-title {
    font-weight: 700;
    font-size: .85rem;
    color: var(--primary);
    letter-spacing: -.01em;
}

.numeri-year-meta {
    font-size: .68rem;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
}

.numeri-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.numero-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 8px;
    border-radius: var(--r-sm);
    font-size: .76rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.numero-chip i {
    font-size: .65rem;
    color: var(--accent-2);
}

.numero-chip.gap {
    background: rgba(217,154,59,.1);
    border-color: rgba(217,154,59,.3);
    color: var(--warning);
    font-style: italic;
}

/* === Section title === */
.section-title {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-soft);
    font-weight: 700;
    margin: 14px 2px 6px;
}

/* === List === */
.list-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}

.list-group-item {
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
}
.list-group-item:last-child { border-bottom: none; }

.list-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    background: rgba(13,139,94,.1);
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: .85rem;
}

.list-content { flex: 1; min-width: 0; }
.list-title {
    font-weight: 600;
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.list-sub {
    font-size: .7rem;
    color: var(--text-soft);
    margin-top: 1px;
    font-variant-numeric: tabular-nums;
}
.list-amount {
    font-weight: 700;
    color: var(--text);
    font-size: .9rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.btn-del-row {
    border: none;
    background: transparent;
    color: var(--danger);
    padding: 4px 6px;
    border-radius: var(--r-sm);
    font-size: .9rem;
}
.btn-del-row:active { background: rgba(179,38,30,.1); }

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 36px 16px;
    color: var(--text-soft);
}
.empty-state i { font-size: 2rem; opacity: .3; }
.empty-state p { margin-top: 10px; font-size: .85rem; }

/* === Form card === */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
    margin-top: 4px;
}

.form-icon {
    width: 38px;
    height: 38px;
    margin: 0 auto 8px;
    border-radius: var(--r-sm);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

h5.text-center {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px !important;
    letter-spacing: -.01em;
}

.form-label {
    font-size: .68rem;
    font-weight: 700;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 4px;
}

.mb-3 { margin-bottom: 10px !important; }
.mb-4 { margin-bottom: 14px !important; }

.form-control, .input-group-text {
    border-radius: var(--r-sm) !important;
    border-color: var(--border-strong);
    font-size: .9rem;
    padding: 7px 10px;
    background: var(--surface-2);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(10,37,64,.12);
    background: var(--surface);
}

.input-group-lg .form-control,
.input-group-lg .input-group-text {
    font-size: .95rem;
    padding: 8px 12px;
}

.form-control-lg { font-size: .95rem; padding: 8px 12px; }

.input-group-text {
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
}

.btn {
    border-radius: var(--r-sm);
    font-weight: 600;
    font-size: .88rem;
    padding: 8px 14px;
    letter-spacing: .01em;
}

.btn-lg { font-size: .9rem; padding: 10px 16px; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-2);
    border-color: var(--primary-2);
}
.btn-primary:active { background: #001a30 !important; border-color: #001a30 !important; }

.btn-outline-primary {
    border: 1px solid var(--border-strong);
    color: var(--primary);
    background: var(--surface);
    font-weight: 600;
}
.btn-outline-primary:hover, .btn-outline-primary:active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-outline-danger {
    border: 1px solid var(--border-strong);
    color: var(--danger);
    background: var(--surface);
}
.btn-outline-danger:hover { background: var(--danger); border-color: var(--danger); }

.btn-outline-secondary {
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    background: var(--surface);
}

.btn-link { color: var(--primary); text-decoration: none; font-weight: 600; }

/* === CSV import === */
.import-card { border-top: 2px solid var(--accent); }
.import-icon { background: var(--accent); }

.import-card code {
    background: rgba(10,37,64,.06);
    color: var(--primary);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: .82em;
    font-weight: 600;
}

.csv-preview {
    margin-top: 10px;
    background: var(--surface-2);
    border-radius: var(--r-sm);
    padding: 10px 12px;
    border: 1px solid var(--border);
}

.csv-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: .78rem;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.csv-preview-head span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.badge.bg-primary { background: var(--primary) !important; font-size: .68rem; padding: 3px 7px; border-radius: 4px; }

.csv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: .76rem;
    border-bottom: 1px dashed var(--border);
}
.csv-row:last-of-type { border-bottom: none; }

.csv-row-amount {
    font-weight: 700;
    color: var(--success);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.csv-row-meta {
    color: var(--text-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    flex: 1;
    min-width: 0;
}

.csv-row-more {
    text-align: center;
    font-size: .7rem;
    color: var(--text-soft);
    padding-top: 6px;
    font-style: italic;
}

.badge-imported {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: rgba(199,155,80,.15);
    color: var(--accent-2);
    border-radius: 3px;
    font-size: .6rem;
    margin-left: 4px;
    vertical-align: middle;
}

.row-numero {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* === Info cards === */
.info-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 14px;
}
.info-card h6 {
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
    font-size: .82rem;
    letter-spacing: -.01em;
}
.info-card p { font-size: .8rem; color: var(--text-muted); margin-bottom: 6px !important; }
.info-card p:last-child { margin-bottom: 0 !important; }
.info-card ul { padding-left: 16px; font-size: .8rem; color: var(--text-muted); }
.info-card li { margin-bottom: 3px; }
.info-card .form-label { color: var(--text-muted); }
.info-card small { font-size: .7rem; color: var(--text-soft); }

/* === Bottom navigation === */
.app-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 460px;
    background: var(--surface);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    height: var(--nav-h);
    padding-bottom: var(--safe-bottom);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.nav-item {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: .65rem;
    font-weight: 600;
    padding: 0;
    text-transform: uppercase;
    letter-spacing: .04em;
    transition: color .12s;
    position: relative;
}

.nav-item i { font-size: 1.05rem; }

.nav-item.active { color: var(--primary); }

.nav-item.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
}

/* === Toast === */
.toast {
    border-radius: var(--r-sm);
    box-shadow: 0 4px 14px rgba(10,37,64,.15);
    font-size: .85rem;
}

.toast.text-bg-primary { background: var(--primary) !important; }
.toast.text-bg-success { background: var(--success) !important; }
.toast.text-bg-warning { background: var(--warning) !important; color: #fff !important; }
.toast.text-bg-danger  { background: var(--danger) !important; }

/* === Responsive larger screens === */
@media (min-width: 540px) {
    .app-shell {
        margin-top: 16px;
        margin-bottom: 16px;
        min-height: calc(100vh - 32px);
        border-radius: var(--r-lg);
        overflow: hidden;
        border: 1px solid var(--border);
    }
    .app-bottom-nav {
        border-radius: 0 0 var(--r-lg) var(--r-lg);
    }
}
