/**
 * VIEMME Finance — stesso design system del sito viemme.co.uk, di VIEMME ID e di Projects
 * (sfondo scuro, arancio #ff7f00, viola #7d5cff, pannelli in vetro).
 * Base copiata da id/public/style.css; le aggiunte di Finance sono in fondo.
 */
:root {
    --bg: #0b0f14;
    --panel: rgba(255,255,255,0.06);
    --panel-strong: rgba(255,255,255,0.1);
    --text: #e8edf2;
    --muted: #a9b6c6;
    --brand: #ff7f00;
    --brand-2: #7d5cff;
    --ring: rgba(255,255,255,0.12);
    --shadow: 0 10px 30px rgba(0,0,0,0.3);
    --radius: 16px;
    --radius-sm: 12px;
    --maxw: 1320px;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 90% -10%, rgba(255,127,0,0.09), transparent 60%),
        radial-gradient(900px 500px at -10% 10%, rgba(125,92,255,0.12), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--text); text-decoration: none; }
a:hover { opacity: 0.9; }
a.link { color: var(--brand); }
a.link:hover { text-decoration: underline; }
.wrap { max-width: var(--maxw); margin-inline: auto; padding: 0 24px; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 12px; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.sm { font-size: 0.85rem; }
.xs { font-size: 0.75rem; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.inline { display: inline; margin: 0; }

/* HEADER */
.header {
    position: sticky; top: 0; z-index: 50;
    background: linear-gradient(to bottom, rgba(11,15,20,0.92), rgba(11,15,20,0.7));
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--ring);
}
.header .wrap { display: flex; align-items: center; gap: 20px; min-height: 64px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { height: 30px; width: auto; display: block; }
.brand .id-badge {
    font-size: 0.75rem; font-weight: 700; letter-spacing: 1px; color: #111;
    background: linear-gradient(135deg, var(--brand), #ffb266); border-radius: 6px; padding: 2px 7px;
}
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); font-size: 0.9rem; padding: 7px 12px; border-radius: 8px; }
.nav a:hover { color: var(--brand); background: rgba(255,127,0,0.10); opacity: 1; }
.nav a.active { color: var(--text); background: var(--panel-strong); }
.header .spacer { flex: 1; }
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.org-switch select { width: auto; min-width: 150px; padding: 6px 10px; font-size: 0.85rem; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; padding: 6px 10px; border-radius: 8px; }
.user-chip:hover, .user-chip.active { color: var(--text); background: var(--panel-strong); }
.avatar {
    width: 28px; height: 28px; border-radius: 50%; display: grid; place-content: center;
    background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #111; font-weight: 800; font-size: 0.8rem;
}

main.wrap { padding-top: 32px; padding-bottom: 48px; }

/* CARDS */
.card {
    background: var(--panel);
    border: 1px solid var(--ring);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}
.card.glass { background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.danger-zone { border-color: rgba(239,68,68,0.35); }

/* BUTTONS */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: 10px; border: 1px solid var(--ring);
    background: var(--panel-strong); color: var(--text); font-size: 0.9rem; font-weight: 600;
    cursor: pointer; font-family: inherit; line-height: 1.2; transition: opacity .15s, transform .1s;
    text-decoration: none;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.brand { background: linear-gradient(180deg, #ff8a1a, #ff7f00); color: #111; border-color: rgba(255,255,255,0.18); }
.btn.danger { background: rgba(239,68,68,0.15); color: #fca5a5; border-color: rgba(239,68,68,0.45); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 0.8rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; }
.btn-link:hover { text-decoration: underline; }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; letter-spacing: .2px; }
.form-hint { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.form-input, select.form-input, textarea.form-input {
    width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--ring);
    background: rgba(0,0,0,0.25); color: var(--text); font-size: 0.95rem; font-family: inherit;
}
.form-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,127,0,0.14); }
select.form-input option { background-color: #14181f; color: var(--text); }
textarea.form-input { resize: vertical; min-height: 90px; }
.form-input.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.4rem; letter-spacing: 6px; text-align: center; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.92rem; }
.form-check input { accent-color: var(--brand); width: 16px; height: 16px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
fieldset { border: 1px solid var(--ring); border-radius: var(--radius-sm); padding: 12px 16px; margin: 0 0 16px; }
legend { color: var(--muted); font-size: 0.85rem; padding: 0 6px; }

/* PILLS */
.pill {
    display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--panel-strong);
    border: 1px solid var(--ring); font-size: 0.75rem; white-space: nowrap; vertical-align: middle;
}
.pill.orange { background: rgba(255,127,0,0.18); color: #ffb266; border-color: rgba(255,127,0,0.4); }
.pill.purple { background: rgba(125,92,255,0.18); color: #b8a7ff; border-color: rgba(125,92,255,0.4); }
.pill.green { background: rgba(34,197,94,0.16); color: #86efac; border-color: rgba(34,197,94,0.4); }
.pill.red { background: rgba(239,68,68,0.16); color: #fca5a5; border-color: rgba(239,68,68,0.4); }
.pill.gray { color: var(--muted); }

/* ALERTS */
.alert { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--ring); margin-bottom: 16px; font-size: 0.93rem; }
.alert.danger { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.4); color: #fca5a5; }
.alert.info { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.4); color: #93c5fd; }
.alert.success { background: rgba(34,197,94,0.10); border-color: rgba(34,197,94,0.4); color: #86efac; }
.alert.warning { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.4); color: #fcd34d; }
.alert :last-child { margin-bottom: 0; }

/* AUTH (login, registrazione...) */
.auth-page #network-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.auth-container { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-card { max-width: 440px; width: 100%; margin-bottom: 16px; background: rgba(16,20,27,0.82); backdrop-filter: blur(6px); }
.auth-card.wide { max-width: 560px; }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo img { height: 40px; width: auto; }
.auth-logo p { color: var(--muted); margin: 10px 0 0; font-size: 0.9rem; }
.auth-card h1 { font-size: 1.3rem; text-align: center; }
.auth-foot { text-align: center; color: var(--muted); font-size: 0.88rem; }
.auth-foot a { color: var(--brand); }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; font-size: 0.88rem; flex-wrap: wrap; }
.auth-links a, .auth-links .btn-link { color: var(--brand); }

.qr { display: flex; justify-content: center; margin: 12px 0 16px; }
.qr img { border-radius: 12px; background: #fff; padding: 10px; width: 220px; height: 220px; }
.secret { text-align: center; font-family: ui-monospace, Menlo, monospace; font-size: 1rem; letter-spacing: 1px; background: rgba(0,0,0,0.3); border: 1px dashed var(--ring); border-radius: 10px; padding: 10px; word-break: break-all; }
.steps { padding-left: 20px; color: var(--muted); font-size: 0.92rem; }
.steps li { margin-bottom: 6px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 16px 0; }
.codes code { background: rgba(0,0,0,0.3); border: 1px solid var(--ring); border-radius: 8px; padding: 8px; text-align: center; font-size: 1rem; }
.copy-box { display: flex; gap: 8px; align-items: stretch; }
.copy-box code { flex: 1; background: rgba(0,0,0,0.35); border: 1px dashed var(--brand); border-radius: 10px; padding: 10px 12px; font-size: 1rem; word-break: break-all; }

/* PAGE HEADER */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h1 { margin: 0; }
.page-header p { margin: 4px 0 0; color: var(--muted); }
.back-link { display: inline-block; color: var(--muted); margin-bottom: 12px; font-size: 0.9rem; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 24px; border-bottom: 1px solid var(--ring); padding-bottom: 8px; }
.tabs a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-size: 0.9rem; }
.tabs a.active { color: var(--text); background: var(--panel-strong); }
.tabs a:hover { color: var(--brand); }

/* APP TILES */
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.app-tile {
    display: flex; flex-direction: column; gap: 12px; padding: 22px; border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.02));
    border: 1px solid var(--ring); box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.app-tile:hover { transform: translateY(-2px); border-color: rgba(255,127,0,0.5); opacity: 1; }
.app-icon {
    width: 48px; height: 48px; border-radius: 12px; display: grid; place-content: center;
    font-weight: 800; font-size: 22px; color: #111; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2);
    background: var(--brand);
}
.app-tile h3 { margin: 0; font-size: 1.1rem; }
.app-tile p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.app-tile .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* SERVICES (catalogo organizzazione) */
.services { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.service-card { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.service-card .top { display: flex; gap: 14px; align-items: center; }
.service-card .price { font-weight: 700; }
.service-card .actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { padding: 18px; background: var(--panel); border: 1px solid var(--ring); border-radius: var(--radius); }
.kpi .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.kpi .value.brand { color: var(--brand); }

/* TABLES */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--ring); vertical-align: middle; }
.data-table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .4px; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td.actions { text-align: right; white-space: nowrap; }
.data-table td.actions form { display: inline; }
.data-table .pos { color: #86efac; }
.data-table .neg { color: #fca5a5; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }

/* MEMBER ACCESS */
details.member-edit { margin-top: 8px; }
details.member-edit summary { cursor: pointer; color: var(--brand); font-size: 0.85rem; list-style: none; }
details.member-edit summary::-webkit-details-marker { display: none; }
.access-grid { display: grid; gap: 8px; margin: 10px 0; }
.access-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.access-row select { width: auto; min-width: 150px; padding: 6px 10px; font-size: 0.85rem; }

.footer { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 24px 16px 32px; }
.footer a { color: var(--muted); }
.footer a:hover { color: var(--brand); }

@media (max-width: 720px) {
    .wrap { padding: 0 16px; }
    .header .wrap { padding-top: 10px; padding-bottom: 10px; gap: 10px; }
    .header .spacer { display: none; }
    .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .nav a { white-space: nowrap; }
    .card { padding: 18px; }
    main.wrap { padding-top: 20px; }
    .codes { grid-template-columns: 1fr; }
}

/* ═══════════ Finance ═══════════ */

.app-badge {
    display: inline-block; font-size: 0.72rem; font-weight: 800; letter-spacing: 1.5px; color: #111;
    background: linear-gradient(135deg, var(--brand), #ffb266); border-radius: 6px; padding: 2px 8px;
}
.auth-logo .app-badge { font-size: 0.8rem; }
.nav-ext { color: var(--muted); font-size: 0.85rem; padding: 6px 8px; border-radius: 8px; }
.nav-ext:hover { color: var(--brand); opacity: 1; }
.company-switch select { width: auto; min-width: 170px; padding: 6px 10px; font-size: 0.85rem; }
.user-chip .pill { font-size: 0.7rem; }

.neg { color: #fca5a5; }
.pos { color: #86efac; }
.pill.yellow { background: rgba(245,158,11,0.16); color: #fcd34d; border-color: rgba(245,158,11,0.4); }
.proj-id { color: var(--muted); font-size: 0.8em; font-weight: 500; margin-right: 6px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
h1 .proj-id { font-size: 0.6em; }

/* KPI */
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi .value { font-size: 1.35rem; white-space: nowrap; }
.kpi .sub { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.kpi.positive { border-color: rgba(34,197,94,0.35); }
.kpi.positive .value { color: #86efac; }
.kpi.negative { border-color: rgba(239,68,68,0.3); }
.kpi.negative .value { color: #fca5a5; }
.kpi.warn { border-color: rgba(255,127,0,0.4); }
.kpi.warn .value { color: #ffb266; }

/* Layout */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.grid-2 > .card { margin-bottom: 24px; }
.chart-wrap { position: relative; height: 300px; }
.subcard { border: 1px dashed var(--ring); border-radius: var(--radius-sm); padding: 16px; background: rgba(0,0,0,0.12); }
.subcard h3 { margin-bottom: 8px; }

/* Tabelle */
.data-table td { font-size: 0.9rem; }
.data-table tr.group-row td { background: rgba(255,127,0,0.07); font-weight: 600; padding-top: 10px; padding-bottom: 10px; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { background: rgba(255,255,255,0.03); }
.data-table tr.dim td { opacity: 0.6; }
.data-table.summary { max-width: 520px; }
.data-table.summary tr.total td { font-size: 1.1em; border-top: 1px solid var(--ring); }
.data-table.invoices td { padding-top: 8px; padding-bottom: 8px; }
.project-cell select { min-width: 200px; max-width: 280px; }

/* Form compatti */
.form-input.sm { padding: 6px 10px; font-size: 0.85rem; width: auto; }
.form-input.xs-input { width: 110px; padding: 5px 8px; font-size: 0.85rem; }
.form-label.mb-0 { margin: 0; }
.line-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.line-form > div { min-width: 0; }
.line-form .grow { flex: 1 1 200px; }
.line-form .w-sm { flex: 0 0 150px; }
.line-form .w-md { flex: 0 0 200px; }
.line-form .line-actions { flex: 0 0 auto; }
.confirm-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--ring); border-radius: 10px; }

/* Modifica in linea (details) */
details.edit { display: inline-block; text-align: left; }
details.edit > summary { list-style: none; }
details.edit > summary::-webkit-details-marker { display: none; }
details.edit[open] > summary { background: var(--panel-strong); border-color: var(--brand); }
details.edit .edit-panel {
    position: absolute; right: 24px; left: 24px; z-index: 5; margin-top: 8px; padding: 16px;
    background: #141922; border: 1px solid var(--ring); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.card { position: relative; }

/* Clienti con fatture aperte */
.customers { display: grid; gap: 8px; }
details.customer { border: 1px solid var(--ring); border-radius: var(--radius-sm); background: rgba(0,0,0,0.12); }
details.customer > summary { display: flex; gap: 16px; align-items: center; padding: 12px 16px; cursor: pointer; list-style: none; flex-wrap: wrap; }
details.customer > summary::-webkit-details-marker { display: none; }
details.customer > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
details.customer[open] > summary::before { transform: rotate(90deg); }
details.customer .table-wrap { padding: 0 16px 12px; }

@media (max-width: 960px) {
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .user-chip .user-name { display: none; }
    .line-form .w-sm, .line-form .w-md { flex: 1 1 140px; }
    details.edit .edit-panel { left: 12px; right: 12px; }
}
/* le celle numeriche restano a destra anche nell'intestazione */
.data-table th.text-right, .data-table td.text-right { text-align: right; }