:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-alt: #f1f2f9;
  --border: #e7e8f2;
  --text: #171923;
  --text-secondary: #667085;
  --muted: #98a1b3;

  --primary: #5b4bf5;
  --primary-dark: #4634e0;
  --primary-soft: #eeecff;
  --accent: #06b6d4;
  --accent-soft: #ecfeff;

  --success: #12946f;
  --success-soft: #e7f9f2;
  --danger: #e0364f;
  --danger-soft: #fdeced;
  --warning: #b8600a;
  --warning-soft: #fef3e2;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(23, 25, 35, .05);
  --shadow: 0 2px 10px rgba(23, 25, 35, .06), 0 1px 2px rgba(23, 25, 35, .04);
  --shadow-lg: 0 16px 40px rgba(76, 63, 205, .12);

  --sidebar-w: 236px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 .85rem; }
h2 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; margin: 2rem 0 .85rem; }
h3 { font-size: .95rem; font-weight: 700; margin: 0 0 .75rem; }

.muted { color: var(--text-secondary); }
.small { font-size: .85rem; }
.text-right { text-align: right; }

/* ============ App shell / sidebar ============ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.35rem 1.25rem 1rem;
  color: var(--text);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-soft);
  font-size: 1.1rem;
}

.mainnav {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .5rem .75rem;
  flex: 1;
  overflow-y: auto;
}
.mainnav a {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: .89rem;
}
.mainnav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.mainnav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.mainnav a.active .nav-icon { color: var(--primary-dark); }
.nav-icon { width: 19px; height: 19px; color: var(--muted); flex-shrink: 0; }
.mainnav a:hover .nav-icon { color: var(--text); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: .75rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.user-card {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex: 1;
  min-width: 0;
  padding: .4rem .5rem;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.user-card:hover { background: var(--surface-alt); text-decoration: none; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.user-card-info { display: flex; flex-direction: column; min-width: 0; }
.user-card-name { font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-role { font-size: .75rem; color: var(--muted); }
.icon-button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: .5rem;
  border-radius: var(--radius-sm);
  display: flex;
}
.icon-button:hover { background: var(--surface-alt); color: var(--danger); }
.icon-button .nav-icon { width: 18px; height: 18px; }

.main-wrap { flex: 1; min-width: 0; min-height: 100vh; }

/* ============ Mobile top bar + bottom nav (hidden on desktop) ============ */
.topbar-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .6rem .9rem;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-mobile .brand { padding: 0; }
.topbar-mobile .avatar { text-decoration: none; }

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(23, 25, 35, .06);
}
.bottom-nav > a, .bottom-nav > details > summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  padding: .35rem .2rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .64rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
}
.bottom-nav > a:hover { text-decoration: none; }
.bottom-nav > a.active, .bottom-nav > details.active > summary { color: var(--primary-dark); }
.bottom-nav > a.active .nav-icon, .bottom-nav > details.active > summary .nav-icon { color: var(--primary-dark); }
.bottom-nav .nav-icon { width: 21px; height: 21px; color: inherit; }

.more-menu { position: relative; }
.more-menu summary { list-style: none; cursor: pointer; }
.more-menu summary::-webkit-details-marker { display: none; }
.more-menu[open] summary { color: var(--primary-dark); }
.more-menu[open] summary .nav-icon { color: var(--primary-dark); }
.more-panel {
  position: absolute;
  bottom: calc(100% + .6rem);
  right: -.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  width: 190px;
}
.more-panel a, .more-panel button {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .65rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: .88rem;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.more-panel a:hover, .more-panel button:hover { background: var(--surface-alt); text-decoration: none; }
.more-panel button { color: var(--danger); }
.more-panel .nav-icon { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.more-panel .avatar-sm { width: 22px; height: 22px; font-size: .68rem; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ============ Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.form-card { max-width: 540px; }
.auth-card { width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.account-card { display: block; color: inherit; transition: box-shadow .15s, transform .15s; }
.account-card:hover { text-decoration: none; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.account-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }

/* ============ Dashboard hero ============ */
.hero-grid {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.hero-card {
  background: linear-gradient(135deg, var(--primary) 0%, #7c6ef2 55%, var(--accent) 130%);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .35rem;
}
.hero-label {
  font-size: .85rem;
  font-weight: 600;
  opacity: .88;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.hero-value {
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.hero-sub { font-size: .88rem; opacity: .9; }

.stat-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .35rem;
}
.stat-label { color: var(--text-secondary); font-size: .85rem; font-weight: 600; }
.stat-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

/* ============ Timeline (prossime uscite) ============ */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.timeline-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.timeline-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.timeline-date .day { font-size: 1.1rem; font-weight: 800; line-height: 1.1; }
.timeline-date .month { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-name { font-weight: 700; font-size: .95rem; }
.timeline-meta { color: var(--text-secondary); font-size: .82rem; }
.timeline-amount { font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
.timeline-type {
  display: inline-block;
  margin-top: .15rem;
  font-size: .72rem;
  font-weight: 700;
  padding: .12rem .5rem;
  border-radius: 999px;
}
.timeline-type.type-subscription { background: var(--accent-soft); color: #0e7490; }
.timeline-type.type-loan { background: var(--warning-soft); color: var(--warning); }

.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ============ Forms ============ */
form label {
  display: block;
  font-weight: 700;
  font-size: .82rem;
  color: var(--text);
  margin: 1.1rem 0 .4rem;
}
form label:first-child { margin-top: 0; }
input, select, textarea, button {
  font-family: inherit;
  font-size: .95rem;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="file"],
select, textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.inline-form { display: flex; gap: .6rem; }
.inline-form input { flex: 1; }
.inline { display: inline; }

.checkbox-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .3rem; }
.checkbox-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 400;
  margin: 0;
  padding: .5rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}
.checkbox-item input { width: auto; }

.filter-form { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.filter-field { display: flex; flex-direction: column; min-width: 140px; }
.filter-field label { margin: 0 0 .35rem; }
.filter-card { padding: 1.1rem 1.35rem; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: .9rem;
  text-decoration: none;
  transition: all .12s;
}
.btn:hover { text-decoration: none; border-color: var(--primary); color: var(--primary-dark); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(91, 75, 245, .3); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-danger { background: var(--danger-soft); border-color: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  font-weight: 600;
  font-size: .88rem;
}
.link-button:hover { text-decoration: underline; }
.link-button.danger { color: var(--danger); }

/* ============ Alerts ============ */
.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .88rem; font-weight: 500; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f8c8ce; }
.alert-success { background: var(--success-soft); color: var(--success); border: 1px solid #bdeeda; }

/* ============ Tables ============ */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.data-table th, .data-table td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); text-align: left; font-size: .88rem; }
.data-table th { color: var(--text-secondary); font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr[data-href] { cursor: pointer; }
.row-muted { opacity: .5; }
.actions { display: flex; gap: .85rem; align-items: center; white-space: nowrap; }

/* ============ Misc ============ */
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-header .actions { display: flex; gap: .5rem; }
.badge { display: inline-block; padding: .22rem .6rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); font-size: .74rem; font-weight: 700; }
.badge-admin { background: var(--warning-soft); color: var(--warning); }
.badge-active { background: var(--success-soft); color: var(--success); }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: none; }
.attachment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.attachment-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .55rem .75rem; background: var(--surface-alt); border-radius: var(--radius-sm); }
.attachment-list li a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-list li form { flex-shrink: 0; }
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.75rem; margin: 0; }
.detail-list dt { color: var(--text-secondary); font-size: .82rem; font-weight: 600; }
.detail-list dd { margin: 0; font-weight: 600; }

/* ============ Responsive ============ */
@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }
  .topbar-mobile { display: flex; }
  .bottom-nav { display: flex; }
  .main-wrap { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  .container { padding: 1.1rem 1rem 2rem; }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.05rem; margin: 1.6rem 0 .7rem; }

  .hero-grid { grid-template-columns: 1fr; margin-bottom: 1.35rem; }
  .hero-card { padding: 1.5rem 1.35rem; }
  .hero-value { font-size: 2.1rem; }

  .card { padding: 1.1rem; }
  .form-card { max-width: none; }

  /* Bigger, thumb-friendly tap targets */
  .btn { padding: .7rem 1.1rem; font-size: .92rem; min-height: 44px; }
  .link-button { font-size: .92rem; padding: .3rem 0; }
  .icon-button { padding: .6rem; }
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="date"], input[type="file"],
  select, textarea { padding: .7rem .8rem; font-size: 1rem; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-header > .btn { width: 100%; justify-content: center; }
  .page-header h1, .page-header h2 { margin-bottom: 0; }
  .page-header .actions { width: 100%; }
  .page-header .actions .btn { flex: 1 1 0; min-width: 0; justify-content: center; }

  /* Filters stack full-width on mobile */
  .filter-form { flex-direction: column; align-items: stretch; gap: .8rem; }
  .filter-field { min-width: 0; width: 100%; }
  .filter-form > .btn { width: 100%; justify-content: center; }

  .detail-list { grid-template-columns: 1fr; gap: .9rem; }
  .detail-list dt { margin-bottom: -.3rem; }

  .timeline-item { padding: .7rem .85rem; gap: .75rem; }
  .timeline-date { width: 44px; height: 44px; }

  /* ---- Tables become stacked cards ---- */
  .data-table { border: none; box-shadow: none; background: none; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr { display: block; width: 100%; }
  .data-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: .6rem .9rem;
    margin-bottom: .65rem;
  }
  .data-table tbody tr:last-child { margin-bottom: 0; }
  .data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px dashed var(--border);
    padding: .5rem 0;
    text-align: right;
  }
  .data-table tr td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    text-align: left;
    flex-shrink: 0;
  }
  .data-table td.actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: .6rem .9rem;
  }
  .data-table td.actions::before { display: none; }
}
