/* Gestionale AR Revenue — UI v2 */
:root {
    --navy-950: #0a1220;
    --navy-900: #0e192e;
    --navy-800: #14233f;
    --navy-700: #1d3157;
    --amber: #f0a832;
    --amber-600: #dd9420;
    --amber-soft: rgba(240, 168, 50, .14);
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e6eaf1;
    --bg: #f4f6fa;
    --card: #ffffff;
    --ok: #16a34a;
    --err: #dc2626;
    --r-lg: 16px;
    --r-md: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 8px 24px -12px rgba(15, 23, 42, .18);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--navy-700); text-decoration: none; }
a:hover { color: var(--amber-600); }
.ico { flex: none; vertical-align: -3px; }

.shell { display: flex; min-height: 100vh; }

/* ================= Sidebar ================= */
.sidebar {
    width: 254px;
    flex: 0 0 254px;
    background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-950) 100%);
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, #f6bc52 0%, var(--amber) 55%, var(--amber-600) 100%);
    color: var(--navy-950);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 15px; letter-spacing: .02em;
    box-shadow: 0 4px 14px -4px rgba(240, 168, 50, .55);
}
.brand-name { font-weight: 700; color: #fff; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: #64748b; letter-spacing: .1em; text-transform: uppercase; }

.sidebar nav { flex: 1; padding: 4px 14px 14px; overflow-y: auto; }
.nav-label {
    font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
    color: #475569; padding: 16px 10px 6px;
}
.sidebar nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; margin: 1px 0;
    color: #a7b4c7; border-radius: var(--r-md); font-size: 13.5px; font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar nav a .ico { opacity: .75; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .05); color: #e2e8f0; }
.sidebar nav a.active {
    background: var(--amber-soft);
    color: #fdc55e; font-weight: 600;
}
.sidebar nav a.active .ico { opacity: 1; }

.sidebar-foot {
    padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .07);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex: none;
    background: var(--navy-700); color: #e2e8f0;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
}
.who-txt { display: flex; flex-direction: column; min-width: 0; }
.who-name { color: #f1f5f9; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { font-size: 11px; color: #64748b; }
.logout { color: #64748b; display: flex; padding: 8px; border-radius: 8px; transition: color .15s, background .15s; }
.logout:hover { color: #fdc55e; background: rgba(255, 255, 255, .06); }

/* ================= Main ================= */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 18px 32px;
    background: rgba(244, 246, 250, .85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.topbar-date { font-size: 13px; color: var(--muted); font-weight: 500; }
.content { padding: 26px 32px 48px; max-width: 1240px; }

.flash {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 32px -6px; padding: 12px 16px;
    border-radius: var(--r-md); font-size: 14px; font-weight: 500;
    box-shadow: var(--shadow-sm);
}
.flash-ok  { background: #ecfdf3; color: #15803d; border: 1px solid #bbe7c9; }
.flash-err { background: #fef1f1; color: #b91c1c; border: 1px solid #f6caca; }

/* ================= Cards / grid ================= */
.grid { display: grid; gap: 18px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 22px 24px;
    box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 16px; font-size: 15.5px; font-weight: 700; letter-spacing: -.01em; }
.card + .card, .grid + .card, .card + .grid, details.reveal + .card { margin-top: 18px; }

/* KPI */
.kpi { display: flex; align-items: center; gap: 15px; }
.kpi-ico {
    width: 44px; height: 44px; border-radius: 13px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: #eef2f8; color: var(--navy-700);
}
.kpi-ico-amber { background: #fdf3e0; color: var(--amber-600); }
.kpi-ico-green { background: #e8f8ee; color: var(--ok); }
.kpi-ico-red   { background: #fdeeee; color: var(--err); }
.kpi-num { font-size: 27px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.kpi-warn .kpi-num { color: var(--err); }

/* ================= Tables ================= */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
    text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; color: #8494ab;
    padding: 8px 12px; border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr, table tr { transition: background .12s; }
tr:hover td { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; background: #fdf8ee; border-top: 1px solid #f3e3c0; }
tr.total:hover td { background: #fdf8ee; }
td b { font-weight: 600; }

/* ================= Badges ================= */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    letter-spacing: .01em;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-amber { background: #fdf3dd; color: #b07310; }
.badge-blue  { background: #e7effe; color: #2551b3; }
.badge-gray  { background: #edf1f6; color: #5b6b80; }
.badge-red   { background: #fde9e9; color: #b32222; }
.badge-green { background: #e5f7ec; color: #157a3c; }

/* ================= Forms ================= */
form.stack { display: flex; flex-direction: column; gap: 14px; }
.frow { display: flex; gap: 14px; flex-wrap: wrap; }
.frow > label { flex: 1; min-width: 170px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
label.inline { flex-direction: row; align-items: center; gap: 9px; font-weight: 500; font-size: 13.5px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
    padding: 10px 13px; border: 1px solid #d5dce8; border-radius: var(--r-md);
    font: inherit; color: var(--ink); background: #fff; width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(240, 168, 50, .18);
}
::placeholder { color: #9aa8bd; }
select {
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 34px;
}

/* ================= Buttons ================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 17px; border-radius: var(--r-md);
    border: 1px solid transparent; cursor: pointer; font: inherit;
    font-weight: 600; font-size: 13.5px; line-height: 1.4;
    background: var(--navy-900); color: #fff;
    transition: background .15s, box-shadow .15s, transform .08s;
}
.btn:hover { background: var(--navy-700); color: #fff; box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); }
.btn-amber {
    background: linear-gradient(135deg, #f5b64a 0%, var(--amber) 60%, var(--amber-600) 100%);
    color: #241703;
    box-shadow: 0 4px 14px -6px rgba(240, 168, 50, .6);
}
.btn-amber:hover { background: linear-gradient(135deg, #f3ac33 0%, var(--amber-600) 100%); color: #241703; }
.btn-ghost { background: #fff; border-color: #d5dce8; color: var(--ink-2); box-shadow: var(--shadow-sm); }
.btn-ghost:hover { background: #f6f8fb; color: var(--ink); box-shadow: var(--shadow-sm); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-danger { background: #fff; border-color: #f3caca; color: var(--err); box-shadow: none; }
.btn-danger:hover { background: #fdf2f2; color: var(--err); box-shadow: none; }

details.reveal { margin-bottom: 18px; }
details.reveal > summary { cursor: pointer; list-style: none; display: inline-flex; }
details.reveal > summary::-webkit-details-marker { display: none; }
details.reveal > .card { margin-top: 14px; }

.muted { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar label { min-width: 140px; }
.spacer { flex: 1; }

/* ================= Ticket thread ================= */
.thread { display: flex; flex-direction: column; gap: 14px; }
.msg {
    max-width: 760px; border-radius: 14px; padding: 14px 17px;
    border: 1px solid var(--line); background: #fbfcfe;
}
.msg-team { border-left: 3px solid var(--amber); background: #fffdf7; }
.msg-cliente { border-left: 3px solid #4a7bd8; background: #f9fbff; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.msg-head b { color: var(--ink); font-size: 12.5px; }
.msg-body { white-space: pre-wrap; font-size: 14px; }

/* ================= Calendario pagamenti ================= */
.paytable th a { color: inherit; }
.paytable th.th-now { color: var(--amber-600); }
.paytable td { padding: 7px 4px; }
.paycell {
    display: inline-flex; align-items: center; justify-content: center; gap: 1px;
    min-width: 58px; padding: 5px 7px; border-radius: 8px;
    font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
    white-space: nowrap; transition: filter .12s;
}
.paycell small { font-weight: 500; opacity: .65; font-size: 10.5px; }
a.paycell:hover { filter: brightness(.94); }
.cell-ok     { background: #e2f6ea; color: #14713a; }
.cell-part   { background: #fdf0d4; color: #a26a0c; }
.cell-due    { background: #fce5e5; color: #b02525; }
.cell-future { background: #eef2f8; color: #6c7d95; }
.cell-empty  { background: transparent; color: #b6c1d1; }
.pay-legend { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0 0; font-size: 12.5px; }

/* ================= Login ================= */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(900px 500px at 80% -10%, rgba(240, 168, 50, .16), transparent 60%),
        radial-gradient(700px 500px at -10% 110%, rgba(74, 123, 216, .18), transparent 60%),
        linear-gradient(150deg, var(--navy-900) 0%, var(--navy-950) 100%);
    padding: 24px; width: 100%;
}
.login-card {
    width: 100%; max-width: 410px; background: #fff;
    border-radius: 20px; padding: 38px 36px;
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .55);
}
.login-card .brand { padding: 0 0 10px; }
.login-card h1 { font-size: 21px; margin: 14px 0 4px; letter-spacing: -.01em; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.login-card .brand-name { color: var(--ink); }
.login-card .brand-sub { color: var(--muted); }
.login-card .btn { padding: 12px; font-size: 14.5px; margin-top: 4px; }

/* ================= Responsive ================= */
@media (max-width: 800px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; flex: none; height: auto; position: static; }
    .sidebar nav { display: flex; flex-wrap: wrap; gap: 2px; padding-top: 0; }
    .nav-label { display: none; }
    .topbar, .content { padding-left: 18px; padding-right: 18px; }
    .flash { margin-left: 18px; margin-right: 18px; }
    .topbar-date { display: none; }
}
