:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e5e9f2;
    --text: #1a1f36;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --success-soft: #ecfdf5;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --neutral: #64748b;
    --neutral-soft: #f1f5f9;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }

/* ---------- Login ---------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #4f46e5 0%, #312e81 100%);
    padding: 20px;
}
.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo { font-size: 40px; }
.login-brand h1 { font-size: 22px; margin-top: 8px; }
.login-brand p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-size: 13px; font-weight: 600; margin-top: 12px; color: var(--text-muted); }
.login-form input {
    padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 15px; margin-top: 4px;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.login-form .btn { margin-top: 20px; }
.login-forgot { display: block; text-align: center; margin-top: 16px; font-size: 13px; color: var(--primary); }

/* ---------- Buttons / alerts ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px; border-radius: var(--radius-sm); border: none;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: all .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px 14px; position: fixed; top: 0; bottom: 0; left: 0;
    transition: transform .2s ease; z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; }
.sidebar-logo { font-size: 22px; }
.sidebar-title { font-weight: 700; font-size: 16px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500; color: var(--text-muted);
}
.sidebar-link:hover { background: var(--surface-alt); color: var(--text); }
.sidebar-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-link.disabled { color: #c3c9d6; cursor: default; }
.sidebar-icon { font-size: 16px; width: 20px; text-align: center; }
.badge-soon { margin-left: auto; font-size: 10px; background: var(--neutral-soft); color: var(--text-muted); padding: 2px 6px; border-radius: 20px; }
.sidebar-cta { margin-top: 12px; }

.app-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 14px; padding: 16px 28px; background: var(--surface);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 19px; font-weight: 700; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user-name { font-size: 13.5px; color: var(--text-muted); font-weight: 500; }
.icon-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.app-content { padding: 24px 28px 90px; flex: 1; }

.mobile-only { display: none; }

/* ---------- Cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 8px; }
.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }
.stat-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }

.section-title { font-size: 15px; font-weight: 700; margin: 28px 0 14px; }
.section-title:first-child { margin-top: 0; }

.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.account-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow); border-top: 4px solid var(--acc-color, var(--primary));
    display: block; transition: transform .12s ease, box-shadow .12s ease;
}
.account-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(16,24,40,.1); }
.account-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.account-icon { width: 34px; height: 34px; border-radius: 10px; background: var(--acc-color-soft, var(--primary-soft)); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.account-name { font-weight: 700; font-size: 14.5px; }
.account-type { font-size: 12px; color: var(--text-muted); }
.account-balance { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.account-flow { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-muted); }
.account-flow span.in { color: var(--success); font-weight: 600; }
.account-flow span.out { color: var(--danger); font-weight: 600; }

/* ---------- Table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-alt); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); font-weight: 700; }
tr:last-child td { border-bottom: none; }
.amount { font-weight: 700; }
.amount.entrata { color: var(--success); }
.amount.uscita { color: var(--danger); }
.amount.giroconto { color: var(--neutral); }
.type-pill { display: inline-flex; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.type-pill.entrata { background: var(--success-soft); color: var(--success); }
.type-pill.uscita { background: var(--danger-soft); color: var(--danger); }
.type-pill.giroconto { background: var(--neutral-soft); color: var(--neutral); }
.row-actions { display: flex; gap: 8px; }
.row-actions a { font-size: 12.5px; color: var(--primary); font-weight: 600; }
.row-actions a.danger { color: var(--danger); }
.table-scroll { overflow-x: auto; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 14px; }

/* ---------- Filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.filter-bar select, .filter-bar input {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface-alt);
}
.filter-bar .btn { align-self: center; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-field input, .form-field select, .form-field textarea {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.type-toggle { display: flex; gap: 8px; }
.type-toggle label {
    flex: 1; text-align: center; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 700; cursor: pointer; color: var(--text-muted);
}
.type-toggle input { display: none; }
.type-toggle input:checked + label.entrata { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.type-toggle input:checked + label.uscita { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.type-toggle input:checked + label.giroconto { background: var(--neutral-soft); color: var(--neutral); border-color: var(--neutral); }

/* ---------- Badges ---------- */
.role-badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); }
.badge-inactive { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px; background: var(--neutral-soft); color: var(--neutral); }

/* ---------- Bottom nav / FAB (mobile) ---------- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border);
    display: flex; justify-content: space-around; padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); z-index: 30;
}
.bottom-nav-link { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--text-muted); font-weight: 600; padding: 4px 10px; }
.bottom-nav-link.active { color: var(--primary); }
.bottom-nav-icon { font-size: 18px; }
.fab {
    position: fixed; right: 18px; bottom: 74px; width: 54px; height: 54px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: 26px; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 20px rgba(79,70,229,.4); z-index: 30;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .mobile-only { display: flex; }
    .icon-btn.mobile-only { display: inline-flex; }
    .app-content { padding: 18px 16px 90px; }
    .topbar { padding: 14px 16px; }
    .form-grid { grid-template-columns: 1fr; }
}
