:root {
  --app-bg: #f4f7fb;
  --app-surface: #ffffff;
  --app-text: #182033;
  --app-muted: #718096;
  --app-border: #e6ebf3;
  --app-primary: #3157d5;
  --app-primary-dark: #2444af;
  --app-sidebar: #111827;
  --app-sidebar-soft: #1f2937;
  --app-accent: #6d5dfc;
  --app-success: #169b6b;
  --app-warning: #dd8a12;
  --app-danger: #d6455d;
  --app-info: #1b8ec9;
  --app-radius: 18px;
  --app-shadow: 0 10px 30px rgba(25, 36, 74, .07);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--app-text);
  background: var(--app-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--app-primary); }

/* Shell */
.app-shell { min-height: 100vh; }
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  width: 264px;
  display: flex;
  flex-direction: column;
  color: #fff;
  background:
    radial-gradient(circle at 25% 0%, rgba(109, 93, 252, .24), transparent 34%),
    linear-gradient(180deg, #111827 0%, #121b2d 100%);
  border-right: 1px solid rgba(255,255,255,.06);
  box-shadow: 14px 0 36px rgba(19, 29, 52, .08);
}
.sidebar-brand { padding: 24px 20px 18px; }
.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-size: 20px;
  background: linear-gradient(135deg, #6d5dfc, #3b82f6);
  box-shadow: 0 10px 24px rgba(66, 98, 255, .28);
}
.brand-copy { display: flex; flex-direction: column; line-height: 1.1; }
.brand-copy strong { font-size: 15px; letter-spacing: .01em; }
.brand-copy small { margin-top: 4px; color: #93a4bf; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-nav { padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 10px 14px;
  color: #aebbd0;
  text-decoration: none;
  border-radius: 13px;
  font-size: 14px;
  font-weight: 600;
  transition: .18s ease;
}
.sidebar-link i { width: 22px; font-size: 18px; text-align: center; }
.sidebar-link:hover { color: #fff; background: rgba(255,255,255,.065); transform: translateX(2px); }
.sidebar-link.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(109,93,252,.95), rgba(49,87,213,.95));
  box-shadow: 0 9px 20px rgba(49,87,213,.22);
}
.sidebar-footer { margin-top: auto; padding: 18px 14px 20px; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border-radius: 15px;
  background: rgba(255,255,255,.055);
  border: 1px solid rgba(255,255,255,.07);
}
.user-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  background: linear-gradient(135deg, #2dd4bf, #3157d5);
}
.user-meta { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.user-meta strong { overflow: hidden; color: #fff; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: #8493aa; font-size: 10px; }
.logout-link { color: #8493aa; font-size: 18px; }
.logout-link:hover { color: #fff; }

.app-main { min-height: 100vh; margin-left: 264px; }
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: 66px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 30px;
  background: rgba(244,247,251,.86);
  border-bottom: 1px solid rgba(226,232,240,.78);
  backdrop-filter: blur(14px);
}
.sidebar-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  color: var(--app-text);
  box-shadow: 0 3px 12px rgba(25,36,74,.07);
}
.topbar-spacer { flex: 1; }
.topbar-date {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  color: #53627b;
  background: rgba(255,255,255,.82);
  border: 1px solid var(--app-border);
  font-size: 12px;
  font-weight: 700;
}
.app-content { max-width: 1680px; margin: 0 auto; padding: 28px 30px 42px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 22px; }
.page-heading h1 { margin: 0; color: #182033; font-size: 28px; font-weight: 800; letter-spacing: -.025em; }
.page-heading p { margin: 6px 0 0; color: var(--app-muted); font-size: 13px; }

/* Alerts */
.app-alert { display: flex; align-items: center; gap: 10px; border: 0; border-radius: 14px; box-shadow: var(--app-shadow); }

/* Cards */
.card {
  border: 1px solid rgba(226,232,240,.9);
  border-radius: var(--app-radius);
  background: var(--app-surface);
  box-shadow: var(--app-shadow);
  overflow: hidden;
}
.card.shadow-sm { box-shadow: var(--app-shadow) !important; }
.card-header {
  padding: 16px 18px;
  color: #28354c;
  background: #fff;
  border-bottom: 1px solid var(--app-border);
  font-size: 13px;
  font-weight: 800;
}
.card-footer { padding: 14px 18px; background: #fbfcfe; border-top: 1px solid var(--app-border); }
.card-body { padding: 18px; }

/* KPI */
.kpi-grid { margin-bottom: 22px; }
.card-kpi {
  min-height: 138px;
  position: relative;
  overflow: hidden;
  border: 0;
  color: #fff;
  transition: transform .18s ease, box-shadow .18s ease;
}
a:hover .card-kpi { transform: translateY(-3px); box-shadow: 0 16px 32px rgba(25,36,74,.15) !important; }
.card-kpi::after {
  content: "";
  position: absolute;
  right: -25px;
  bottom: -38px;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
}
.card-kpi .card-body { position: relative; z-index: 1; display: flex; min-height: 138px; flex-direction: column; justify-content: space-between; padding: 19px; }
.kpi-blue { background: linear-gradient(135deg, #3157d5, #5483ee); }
.kpi-purple { background: linear-gradient(135deg, #6d5dfc, #8d77ff); }
.kpi-cyan { background: linear-gradient(135deg, #008bbd, #29b5d9); }
.kpi-green { background: linear-gradient(135deg, #0f9569, #35bc8a); }
.kpi-orange { background: linear-gradient(135deg, #d97a08, #f2a42e); }
.kpi-red { background: linear-gradient(135deg, #cf425a, #ee697d); }
.kpi-indigo { background: linear-gradient(135deg, #4150b7, #6b73df); }
.kpi-slate { background: linear-gradient(135deg, #41526e, #65758f); }
.kpi-label { color: rgba(255,255,255,.82); font-size: 12px; font-weight: 700; }
.kpi-value { color: #fff; font-size: 34px; line-height: 1; font-weight: 800; letter-spacing: -.04em; }
.kpi-icon {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: rgba(255,255,255,.16);
  font-size: 18px;
}
.kpi-foot { color: rgba(255,255,255,.78); font-size: 10px; font-weight: 600; }

/* Buttons */
.btn {
  border-radius: 11px;
  padding: .53rem .9rem;
  font-size: 13px;
  font-weight: 700;
  box-shadow: none !important;
}
.btn-sm { padding: .35rem .65rem; border-radius: 9px; font-size: 12px; }
.btn-primary { border-color: var(--app-primary); background: var(--app-primary); }
.btn-primary:hover { border-color: var(--app-primary-dark); background: var(--app-primary-dark); }
.btn-success { border-color: #169b6b; background: #169b6b; }
.btn-warning { border-color: #f0a62e; background: #f0a62e; color: #fff; }
.btn-outline-primary { color: var(--app-primary); border-color: #b9c8ef; }
.btn-outline-primary:hover { border-color: var(--app-primary); background: var(--app-primary); }
.btn-outline-secondary { color: #65748c; border-color: #d7deea; }
.btn-outline-secondary:hover { color: #29364c; border-color: #cbd4e2; background: #eef2f7; }
.btn-outline-success { color: #18865f; border-color: #b7e1d2; }

/* Forms */
.form-control, .form-select {
  min-height: 42px;
  border: 1px solid #dbe3ef;
  border-radius: 11px;
  color: #25324a;
  background-color: #fff;
  font-size: 13px;
}
.form-control:focus, .form-select:focus {
  border-color: #91a8ef;
  box-shadow: 0 0 0 .2rem rgba(49,87,213,.10);
}
.form-label { margin-bottom: 6px; color: #59677f; font-size: 11px; font-weight: 800; letter-spacing: .01em; }
.form-check-input { border-color: #bdc8d8; }
.form-check-input:checked { border-color: var(--app-primary); background-color: var(--app-primary); }
.required:after { content: ' *'; color: var(--app-danger); }
.filter-box {
  padding: 16px;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  background: #fff;
  box-shadow: var(--app-shadow);
}
.filter-box::before { content: "Filtri"; display: block; margin-bottom: 11px; color: #38465e; font-size: 12px; font-weight: 800; }

/* Tables */
.table { --bs-table-bg: transparent; margin: 0; color: #2a374d; font-size: 12px; }
.table > :not(caption) > * > * { padding: .86rem .9rem; border-bottom-color: #edf1f6; vertical-align: middle; }
.table thead th {
  color: #7b889d;
  background: #f8fafc;
  border-bottom: 1px solid #e8edf4;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
  white-space: nowrap;
}
.table tbody tr { transition: background .12s ease; }
.table tbody tr:hover { background: #f8faff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-responsive { scrollbar-color: #ccd5e4 transparent; }

/* Badges */
.badge { padding: .43rem .62rem; border-radius: 9px; font-size: 10px; font-weight: 800; letter-spacing: .01em; }
.badge-soft { color: #516078; background: #eef2f7; }
.badge-status { border: 1px solid transparent; }
.badge-status.status-attivo { color: #087852; background: #e7f8f1; border-color: #c8efe0; }
.badge-status.status-in-scadenza { color: #9b6200; background: #fff5da; border-color: #f8e4a5; }
.badge-status.status-da-contattare { color: #99551b; background: #fff0e6; border-color: #f9d5ba; }
.badge-status.status-in-attesa-cliente { color: #3658a8; background: #eaf0ff; border-color: #cedaff; }
.badge-status.status-confermato { color: #0d768f; background: #e2f7fb; border-color: #c5edf5; }
.badge-status.status-da-ordinare { color: #6b4fc4; background: #f0ebff; border-color: #ddd2ff; }
.badge-status.status-rinnovato { color: #087852; background: #e7f8f1; border-color: #c8efe0; }
.badge-status.status-non-rinnovare { color: #a62d47; background: #fdecef; border-color: #f7cbd4; }
.badge-status.status-scaduto { color: #a12f3e; background: #ffecef; border-color: #f5c9d0; }
.badge-status.status-cessato { color: #59677f; background: #edf1f5; border-color: #dce3eb; }

/* Detail page */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px 20px; }
.detail-item { padding: 12px 13px; border-radius: 13px; background: #f8fafc; border: 1px solid #edf1f6; }
.detail-item .detail-label { margin-bottom: 5px; color: #8793a5; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .035em; }
.detail-item .detail-value { color: #26334b; font-size: 13px; font-weight: 700; }
.note-panel { min-height: 72px; padding: 13px; border: 1px solid #e7ecf3; border-radius: 13px; background: #fbfcfe; }
.action-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* Login */
.auth-body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(109,93,252,.22), transparent 28%),
    radial-gradient(circle at 90% 80%, rgba(36,160,205,.16), transparent 32%),
    linear-gradient(140deg, #eef3ff 0%, #f8faff 48%, #edf9f6 100%);
}
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.login-wrap { width: min(980px, 100%); }
.login-panel {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.76);
  border-radius: 28px;
  background: rgba(255,255,255,.90);
  box-shadow: 0 28px 80px rgba(36,53,98,.16);
  backdrop-filter: blur(14px);
}
.login-visual {
  position: relative;
  min-height: 520px;
  padding: 42px;
  color: #fff;
  background:
    radial-gradient(circle at 80% 16%, rgba(255,255,255,.16), transparent 26%),
    linear-gradient(145deg, #172033 0%, #273d86 58%, #6d5dfc 100%);
}
.login-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; }
.login-brand .brand-mark { width: 48px; height: 48px; }
.login-visual-copy { position: absolute; left: 42px; right: 42px; bottom: 46px; }
.login-visual h2 { max-width: 420px; margin: 0 0 12px; font-size: 34px; font-weight: 800; line-height: 1.1; letter-spacing: -.035em; }
.login-visual p { max-width: 410px; margin: 0; color: rgba(255,255,255,.72); font-size: 14px; line-height: 1.6; }
.login-form { display: flex; flex-direction: column; justify-content: center; padding: 48px; }
.login-form h1 { margin: 0; color: #1c2940; font-size: 27px; font-weight: 800; }
.login-form .lead-copy { margin: 8px 0 28px; color: #7b8799; font-size: 13px; }
.login-form .form-control { min-height: 48px; }
.login-form .btn { min-height: 48px; }
.auth-alert { position: fixed; top: 24px; left: 50%; z-index: 10; transform: translateX(-50%); min-width: 320px; border: 0; border-radius: 12px; box-shadow: var(--app-shadow); }

/* Small helpers */
.text-muted { color: var(--app-muted) !important; }
.list-group-item { border-color: #edf1f6; font-size: 12px; }
code { color: #6b52d4; }
.sidebar-backdrop { display: none; }
.empty-state { padding: 34px 18px !important; color: #8491a5 !important; }

@media (max-width: 1199.98px) {
  .app-sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-grid; place-items: center; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 1035; background: rgba(14,22,38,.46); }
  .sidebar-backdrop.show { display: block; }
}

@media (max-width: 767.98px) {
  .app-topbar { height: 60px; padding: 0 15px; }
  .app-content { padding: 20px 14px 32px; }
  .page-heading { margin-bottom: 16px; }
  .page-heading h1 { font-size: 23px; }
  .page-heading p { font-size: 12px; }
  .topbar-date span { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .login-panel { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .login-form { padding: 34px 24px; }
  .auth-shell { padding: 16px; }
  .card { border-radius: 15px; }
  .filter-box { border-radius: 15px; }
}
