@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --ink: #1f2733;
    --muted: #7a8699;
    --line: #e6eaf1;
    --brand: #2f5bea;
    --brand-dark: #2447bd;
    --green: #1ba672;
    --green-bg: #e7f7f0;
    --red: #e03e52;
    --red-bg: #fdebed;
    --shadow: 0 2px 10px rgba(31, 39, 51, .06);
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 17px;
    line-height: 1.5;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1 {
    font-size: 24px;
    margin: 0;
}

h2 {
    font-size: 19px;
    margin: 0 0 16px;
}

/* Topbar */
.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 0 24px;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: flex-end;
}

.topbar-user {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
}

.logo-img {
    max-height: 40px;
    max-width: 120px;
    object-fit: contain;
    cursor: pointer;
}

.logo-upload {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1.5px dashed var(--line);
    border-radius: 8px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.logo-upload:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.brand a {
    font-weight: 700;
    font-size: 22px;
    color: var(--ink);
}

.menu {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.menu a {
    padding: 8px 14px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 500;
    font-size: 13px;
}

.menu a:hover {
    background: var(--bg);
    text-decoration: none;
}

.menu a.active {
    background: var(--brand);
    color: #fff;
}

/* Dropdown nel menu */
.menu-dropdown {
    position: relative;
}

.menu-dropdown-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 500;
    font-size: 13px;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}

.menu-dropdown-btn:hover,
.menu-dropdown.open .menu-dropdown-btn {
    background: var(--bg);
}

.menu-dropdown-btn.active {
    background: var(--brand);
    color: #fff;
}

.menu-dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px;
    min-width: 200px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .10);
    z-index: 200;
    display: none;
}

.menu-dropdown.open .menu-dropdown-panel {
    display: block;
}

.menu-dropdown-panel a,
.menu-dropdown-panel button.dd-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border-radius: 7px;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
}

.menu-dropdown-panel a:hover,
.menu-dropdown-panel button.dd-item:hover {
    background: var(--bg);
    text-decoration: none;
}

.menu-dropdown-panel a.active {
    background: var(--brand);
    color: #fff;
}

.dd-sep {
    border: none;
    border-top: 1px solid var(--line);
    margin: 4px 0;
}

/* Modal lookup (tipologie / giochi) */
.lookup-add {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.lookup-add input {
    flex: 1;
}

.lookup-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 320px;
    overflow-y: auto;
}

.lookup-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

.lookup-item:last-child {
    border-bottom: none;
}

.container {
    max-width: none;
    margin: 0 auto;
    padding: 28px 24px 60px;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.small-cards {
    grid-template-columns: repeat(3, 1fr);
}

.card {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 7px 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-left: 4px solid var(--line);
}

.card-label {
    color: var(--muted);
    font-size: 12px;
}

.card-value {
    font-size: 18px;
    font-weight: 700;
}

.card.in {
    border-left-color: var(--green);
}

.card.out {
    border-left-color: var(--red);
}

.card.total {
    border-left-color: var(--brand);
}

/* Panels */
.panel {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-bottom: 22px;
}

.panel.narrow {
    align-self: start;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.panel-head h2 {
    margin: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    align-items: start;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 7px 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

.table th {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

.table tbody tr:hover {
    background: #fafbfe;
}

#tabellaOrdini th,
#tabellaOrdini td,
#tabellaOF th,
#tabellaOF td {
    padding: 3px 12px;
}

#tabellaProdotti th,
#tabellaProdotti td {
    white-space: nowrap;
}

#tabellaProdotti .gioco-group-body td {
    font-size: 12px;
}

.table .r {
    text-align: right;
}

.table .c {
    text-align: center;
}

select.tag {
    border: none;
    cursor: pointer;
    font-family: inherit;
    width: auto;
    padding-right: 6px;
}

.tasse-check {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--primary);
}

.pos {
    color: var(--green);
    font-weight: 600;
}

.neg {
    color: var(--red);
    font-weight: 600;
}

.muted {
    color: var(--muted);
}

/* Tags */
.tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.tag.entrata {
    background: var(--green-bg);
    color: var(--green);
}

.tag.uscita {
    background: var(--red-bg);
    color: var(--red);
}

/* Tag conti */
.tag.banca {
    background: rgba(47, 91, 234, .12);
    color: #2f5bea;
}


.tag.contanti {
    background: rgba(27, 166, 114, .12);
    color: #1ba672;
}

.tag.carta {
    background: rgba(124, 58, 237, .12);
    color: #7c3aed;
}

.tag.wallet {
    background: rgba(217, 119, 6, .12);
    color: #d97706;
}

.tag.digitale {
    background: rgba(79, 70, 229, .12);
    color: #4f46e5;
}

.tag.atm {
    background: rgba(8, 145, 178, .12);
    color: #0891b2;
}

.tag.aziendale {
    background: rgba(71, 85, 105, .12);
    color: #475569;
}

.tag.monete {
    background: rgba(146, 64, 14, .12);
    color: #92400e;
}

/* Buttons */
.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 9px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}

.btn:hover {
    background: var(--brand-dark);
    text-decoration: none;
}

.btn.small {
    padding: 7px 13px;
    font-size: 13px;
}

.btn.ghost {
    background: transparent;
    color: var(--brand);
    border: 1px solid var(--line);
}

.btn.ghost:hover {
    background: var(--bg);
}

.link {
    font-size: 13px;
    margin-right: 8px;
}

.link.danger {
    color: var(--red);
}

.actions {
    white-space: nowrap;
}

/* Icon action links */
.actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.actions a:hover {
    background: rgba(0, 0, 0, 0.03);
}

.actions a.link {
    color: inherit;
}

.actions a.link.danger {
    color: var(--red);
}

.actions button.link {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 13px;
    color: inherit;
}

.toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 10px;
    color: var(--muted);
    padding: 2px 4px;
    line-height: 1;
}
.toggle-btn:hover { color: var(--text); }

.gioco-group-row {
    cursor: pointer;
    background: var(--bg2, #eef1f5);
}
.gioco-group-row:hover {
    background: var(--bg3, #e4e8ee);
}
.gioco-group-row td {
    font-weight: 600;
    padding: 10px 12px;
}
.group-toggle-btn {
    display: inline-block;
    font-size: 10px;
    color: var(--muted);
    margin-right: 4px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    font-size: 12px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity .15s, background .15s;
}

.icon-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

.icon-btn.danger {
    color: var(--red);
}

/* Forms */
.form-row {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row label {
    font-weight: 600;
    font-size: 14px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

input[type=text],
input[type=email],
input[type=date],
input[type=month],
input[type=number],
input[type=password],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    font-size: 16px;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(47, 91, 234, .12);
}

.qta-input {
    width: 50px !important;
    padding: 1px 3px !important;
    font-size: 14px !important;
    font-weight: 700;
    font-family: inherit;
    text-align: right;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    border-radius: 4px;
    height: auto;
}

.qta-input:hover {
    border-color: var(--line);
}

.qta-input:focus {
    background: var(--bg);
    box-shadow: 0 0 0 3px rgba(47, 91, 234, .12);
}

.qta-input.small {
    font-size: 12px !important;
    font-weight: normal !important;
    width: 50px !important;
    height: 1.4em !important;
    padding: 0 2px !important;
    line-height: 1.4 !important;
    vertical-align: middle !important;
}

.filtri-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 18px;
}
.filtri-bar input[type=search],
.filtri-bar select {
    width: auto;
    flex: 1;
    min-width: 140px;
    padding: 7px 10px;
    font-family: inherit;
    font-size: 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--ink);
}
.filtri-bar input[type=search] {
    min-width: 200px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.radio-group {
    display: flex;
    gap: 12px;
}

.radio {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
    font-weight: 600;
}

.radio.in:has(input:checked) {
    border-color: var(--green);
    background: var(--green-bg);
    color: var(--green);
}

.radio.out:has(input:checked) {
    border-color: var(--red);
    background: var(--red-bg);
    color: var(--red);
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
}

.filters select,
.filters input {
    width: auto;
}

.filters label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--muted);
}

.period input {
    width: auto;
}

/* Bars */
.bars {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bar-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 4px;
}

.bar {
    background: var(--bg);
    border-radius: 6px;
    height: 10px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--red);
    border-radius: 6px;
}

.bar-fill-in {
    background: var(--green);
    border-radius: 6px;
}

/* Pie chart */
.pie-wrap {
    display: flex;
    align-items: center;
    gap: 20px;
}
.pie-svg {
    flex-shrink: 0;
}
.pie-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    flex: 1;
    min-width: 0;
}
.pie-legend li {
    display: grid;
    grid-template-columns: 14px 1fr auto auto;
    gap: 6px;
    align-items: center;
}
.pie-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}
.pie-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}
.pie-val {
    font-weight: 600;
    white-space: nowrap;
}
.pie-pct {
    color: var(--muted);
    white-space: nowrap;
    min-width: 36px;
    text-align: right;
}

/* Chart */
.chart-wrap {
    width: 100%;
    overflow-x: auto;
}

.chart {
    width: 100%;
    height: auto;
    min-width: 560px;
    font-size: 11px;
}

.chart .grid-line {
    stroke: var(--line);
    stroke-width: 1;
}

.chart .axis-x {
    fill: var(--muted);
    text-anchor: middle;
    font-size: 9px;
}

.chart .axis-y {
    fill: var(--muted);
    text-anchor: end;
    font-size: 9px;
}

.chart .bar-in {
    fill: var(--green);
}

.chart .bar-out {
    fill: var(--red);
}

.chart-legend {
    display: flex;
    gap: 18px;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--muted);
}

.chart-legend .dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    margin-right: 4px;
    vertical-align: -1px;
}

.chart-legend .dot.in {
    background: var(--green);
}

.chart-legend .dot.out {
    background: var(--red);
}

.head-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Impostazioni fiscali + tasse */
.hint {
    color: var(--muted);
    font-size: 12px;
}

.fs-block {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 16px 4px;
    margin-bottom: 16px;
}

.fs-block legend {
    font-weight: 600;
    font-size: 13px;
    color: var(--muted);
    padding: 0 6px;
}

.iva-preview {
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 9px;
    font-size: 14px;
    color: var(--ink);
}

.cat-lists {
    display: flex;
    gap: 22px;
}

.cat-lists>section {
    flex: 1;
}

/* Centra il pulsante "+ Nuova categoria" e aggiunge spazio sotto */
.categories-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.categories-section .head-actions {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 20px;
}

.categories-section .head-actions .btn {
    padding: 12px 24px;
    font-size: 16px;
}

/* Sezione categorie: centra il bottone e dà spazio */
.categories-section {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 18px;
}

.categories-section .head-actions {
    display: flex;
    justify-content: center;
}

.categories-section .head-actions .btn {
    padding: 12px 22px;
    font-size: 16px;
}

/* Attivita badge next to select */
.attivita-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.attivita-badge {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 13px;
    min-width: 56px;
    text-align: center;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
    border: 1px solid rgba(31, 39, 51, 0.08);
    box-shadow: 0 2px 6px rgba(31, 39, 51, 0.06), 0 1px 0 rgba(255, 255, 255, 0.18) inset;
}

/* stronger outline for .tag when inline colored */
.tag[style] {
    border: 1px solid rgba(31, 39, 51, 0.06);
}


/* Color palette for category modal */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.color-palette .swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 2px solid rgba(0, 0, 0, 0.06);
    padding: 0;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

.color-palette .swatch.selected {
    outline: 3px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

@media (max-width: 760px) {
    .cat-lists {
        flex-direction: column;
    }
}

/* Page-specific font increase for Categorie and Conti */
.categorie .panel,
.categorie .table,
.conti .panel,
.conti .table {
    font-size: 17px;
}

.categorie h2,
.conti h2 {
    font-size: 18px;
}

.conto-icona {
    font-size: 17px;
    vertical-align: -2px;
    margin-right: 4px;
}

.saldo-hint {
    font-size: 13px;
    color: var(--muted);
    margin-top: 5px;
    min-height: 18px;
}

.row-past td {
    opacity: .5;
}

.trend-total td {
    border-top: 2px solid var(--ink);
    background: var(--bg);
}

.table-scroll {
    overflow-x: auto;
}

.riepilogo-mesi th,
.riepilogo-mesi td {
    min-width: 82px;
    white-space: nowrap;
}

.riepilogo-mesi .riepilogo-label {
    min-width: 110px;
}

.riepilogo-mesi .riepilogo-totale {
    border-left: 2px solid var(--line);
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(31, 39, 51, .5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 8px 40px rgba(31, 39, 51, .2);
    margin: 16px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-head h2 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--ink);
}

.table.calc td {
    padding: 9px 10px;
}

.table.calc tr.sub td {
    border-top: 1px solid var(--line);
    font-weight: 600;
}

.table.calc tr.tot td {
    border-top: 2px solid var(--ink);
    font-size: 16px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 9px;
    margin-bottom: 18px;
    font-weight: 500;
}

.alert.success {
    background: var(--green-bg);
    color: var(--green);
}

.alert.error {
    background: var(--red-bg);
    color: var(--red);
}

.alert.info {
    background: #e8f0fe;
    color: #1a56db;
}

/* Footer */
.foot {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 24px;
}

@media (max-width: 760px) {

    .cards,
    .small-cards,
    .grid-2,
    .form-grid,
    .form-grid-3 {
        grid-template-columns: 1fr;
    }

    .menu {
        gap: 2px;
    }

    .menu a {
        padding: 8px 10px;
    }
}