/* ============================================================
   CAI Gestionale – Main CSS v1.1
   Palette ufficiale CAI: blu #2E6DB4, bianco, grigio
   Font: Lora (titoli) + Inter (UI)
   ============================================================ */

:root {
  /* Colori ufficiali CAI */
  --blue:         #2E6DB4;
  --blue-dark:    #235a96;
  --blue-darker:  #1a4472;
  --blue-light:   #eaf1fa;
  --blue-mid:     #a8c4e0;

  /* Neutri */
  --white:        #ffffff;
  --bg:           #f4f6f9;
  --bg-card:      #ffffff;
  --bg-hover:     #f8f9fb;
  --border:       #dde3eb;
  --border-dark:  #c4cdd8;

  /* Testo */
  --text:         #1a2332;
  --text-sub:     #4a5568;
  --text-muted:   #718096;
  --text-light:   #a0aec0;

  /* Feedback */
  --green:        #27ae60;
  --green-light:  #eafaf1;
  --yellow:       #e67e22;
  --yellow-light: #fef9ee;
  --red:          #c0392b;
  --red-light:    #fdf0ef;

  /* Topbar */
  --nav-h:        60px;
  --nav-bg:       #1a2d4a;   /* blu scuro CAI */
  --nav-border:   #243d60;

  /* Layout */
  --radius:       6px;
  --radius-lg:    10px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:       0 4px 12px rgba(0,0,0,.1);
  --shadow-lg:    0 8px 24px rgba(0,0,0,.12);

  --font-title:   'Lora', Georgia, serif;
  --font-ui:      'Inter', system-ui, -apple-system, sans-serif;
  --tr:           .16s ease;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  font-size: .925rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); text-decoration: underline; }
img { max-width: 100%; }
button { font-family: inherit; }

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  display: flex; align-items: center;
  padding: 0 1rem; gap: 0;
}

.topbar-brand {
  display: flex; align-items: center; gap: .65rem;
  flex-shrink: 0; padding-right: 1.25rem;
  border-right: 1px solid var(--nav-border);
  margin-right: .75rem;
}

.brand-link {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none !important;
}
.brand-logo { width: 34px; height: 34px; object-fit: contain;  }
.brand-text { display: none; }
@media (min-width: 500px) {
  .brand-text {
    display: flex; flex-direction: column; line-height: 1.1;
  }
  .brand-text strong {
    font-family: var(--font-title); font-size: .95rem; font-weight: 700;
    color: #ffffff; letter-spacing: .01em;
  }
  .brand-text span {
    font-size: .7rem; color: rgba(255,255,255,.6); font-weight: 400;
    text-transform: uppercase; letter-spacing: .08em;
  }
}

/* Hamburger */
.hamburger {
  display: flex; flex-direction: column; gap: 4px;
  width: 32px; height: 32px; padding: 6px 5px;
  background: none; border: none; cursor: pointer; border-radius: var(--radius);
  transition: background var(--tr);
}
.hamburger:hover { background: rgba(255,255,255,.1); }
.hamburger span {
  display: block; width: 100%; height: 2px;
  background: rgba(255,255,255,.8); border-radius: 2px;
  transition: transform var(--tr), opacity var(--tr);
}
.hamburger.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
@media (min-width: 860px) { .hamburger { display: none; } }

/* Nav links */
.topbar-nav {
  display: flex; align-items: center; gap: .1rem;
  flex: 1; overflow-x: auto; scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.topbar-nav a {
  display: flex; align-items: center; gap: .4rem;
  padding: .45rem .75rem; border-radius: var(--radius);
  font-size: .83rem; font-weight: 500;
  color: rgba(255,255,255,.7) !important; white-space: nowrap;
  text-decoration: none !important;
  transition: background var(--tr), color var(--tr);
}
.topbar-nav a:hover { background: rgba(255,255,255,.1); color: #fff !important; }
.topbar-nav a.active {
  background: var(--blue); color: #fff !important; font-weight: 600;
}
.nav-icon { width: 15px; height: 15px; flex-shrink: 0; }
.nav-icon svg { width: 100%; height: 100%; }

/* Nav mobile */
@media (max-width: 859px) {
  .topbar-nav {
    position: fixed; top: var(--nav-h); left: 0; right: 0; bottom: 0;
    background: var(--nav-bg); border-top: 1px solid var(--nav-border);
    flex-direction: column; align-items: stretch;
    padding: .5rem; overflow-y: auto; gap: .2rem;
    display: none;
  }
  .topbar-nav.open { display: flex; }
  .topbar-nav a { padding: .75rem 1rem; font-size: .95rem; }
  .nav-icon { width: 18px; height: 18px; }
}

/* User widget */
.topbar-user { margin-left: auto; flex-shrink: 0; }
.user-widget { position: relative; }

.user-trigger {
  display: flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  border-radius: 40px; padding: .3rem .75rem .3rem .35rem;
  cursor: pointer; color: #fff;
  transition: background var(--tr), border-color var(--tr);
}
.user-trigger:hover { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.25); }

.av {
  width: 30px; height: 30px; border-radius: 50%; overflow: hidden;
  background: var(--blue); border: 2px solid rgba(255,255,255,.3);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.av-img { width: 100%; height: 100%; object-fit: cover; }
.av-init { font-size: .68rem; font-weight: 700; color: #fff; }

.user-name {
  font-size: .83rem; font-weight: 500; color: rgba(255,255,255,.9);
  display: none; max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (min-width: 500px) { .user-name { display: block; } }

.chevron { width: 10px; height: 10px; color: rgba(255,255,255,.5);
           transition: transform var(--tr); flex-shrink: 0; }
.user-trigger[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.user-menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 230px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: none; z-index: 200;
}
.user-menu.open { display: block; }

.user-menu-header {
  padding: .9rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: .1rem;
}
.user-menu-header strong { font-size: .88rem; color: var(--text); }
.user-menu-header span { font-size: .77rem; color: var(--text-muted); }

.user-menu a {
  display: flex; align-items: center; gap: .55rem;
  padding: .62rem 1rem; font-size: .875rem;
  color: var(--text-sub) !important; text-decoration: none !important;
  transition: background var(--tr), color var(--tr);
}
.user-menu a:hover { background: var(--bg); color: var(--text) !important; }
.user-menu a.danger:hover { background: var(--red-light); color: var(--red) !important; }
.user-menu a svg { width: 15px; height: 15px; flex-shrink: 0; }
.user-menu hr { border: none; border-top: 1px solid var(--border); margin: .25rem 0; }

/* ── Page layout ────────────────────────────────────────── */
.main-wrap {
  padding-top: var(--nav-h);
  flex: 1;
}
.page-inner {
  max-width: 1200px; margin: 0 auto; padding: 2rem 1.25rem 3rem;
}

/* ── Page header ────────────────────────────────────────── */
.page-hd {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.75rem; flex-wrap: wrap;
}
.page-hd h1 {
  font-family: var(--font-title); font-size: 1.7rem; font-weight: 700;
  color: var(--text); line-height: 1.2;
}
.page-hd p { color: var(--text-muted); font-size: .9rem; margin-top: .2rem; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.card + .card { margin-top: 1.25rem; }
.card-title {
  font-family: var(--font-title); font-size: 1.15rem; font-weight: 700;
  color: var(--text); margin-bottom: 1.25rem;
}
.card-subtitle { font-size: .875rem; color: var(--text-muted); margin-top: -.75rem; margin-bottom: 1.25rem; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem; border-radius: var(--radius);
  font-family: var(--font-ui); font-size: .875rem; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  transition: all var(--tr); text-decoration: none !important;
  white-space: nowrap; line-height: 1.4;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }
.btn-secondary { background: var(--white); color: var(--text); border-color: var(--border-dark); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }
.btn-danger    { background: var(--white); color: var(--red); border-color: #e8b4af; }
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost     { background: transparent; color: var(--text-sub); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm   { padding: .35rem .75rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-label {
  display: block; margin-bottom: .35rem;
  font-size: .8rem; font-weight: 600;
  color: var(--text-sub); text-transform: uppercase; letter-spacing: .05em;
}
.form-control {
  width: 100%; padding: .6rem .85rem;
  background: var(--white); border: 1px solid var(--border-dark);
  border-radius: var(--radius); color: var(--text); font-family: var(--font-ui);
  font-size: .925rem; line-height: 1.5;
  transition: border-color var(--tr), box-shadow var(--tr);
  -webkit-appearance: none; appearance: none;
}
.form-control:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,109,180,.15);
}
.form-control::placeholder { color: var(--text-light); }
.form-control:disabled { background: var(--bg); color: var(--text-muted); cursor: not-allowed; }
select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23718096' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.25rem;
}
.form-hint  { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }
.form-error { font-size: .78rem; color: var(--red); margin-top: .3rem; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; background: var(--white); }
thead tr { background: var(--bg); border-bottom: 2px solid var(--border); }
thead th {
  padding: .75rem 1rem; text-align: left;
  font-size: .78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--tr); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td { padding: .8rem 1rem; color: var(--text); vertical-align: middle; font-size: .9rem; }
.td-actions { display: flex; gap: .4rem; align-items: center; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .2rem .55rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600; line-height: 1;
}
.badge-blue   { background: var(--blue-light); color: var(--blue-dark); }
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-red    { background: var(--red-light); color: var(--red); }
.badge-grey   { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .85rem 1rem; border-radius: var(--radius);
  border: 1px solid; margin-bottom: 1.25rem;
  font-size: .9rem; line-height: 1.5;
}
.alert-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: .1rem; }
.alert-icon svg { width: 100%; height: 100%; }
.alert--success { background: var(--green-light); border-color: #a9dfbf; color: #1d7a42; }
.alert--error   { background: var(--red-light); border-color: #e8b4af; color: var(--red); }
.alert--warning { background: var(--yellow-light); border-color: #f5cba7; color: #a04000; }
.alert--info    { background: var(--blue-light); border-color: var(--blue-mid); color: var(--blue-darker); }

/* ── Grid helpers ───────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.25rem; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.flex-center  { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.mt-1{margin-top:.5rem}.mt-2{margin-top:1rem}.mt-3{margin-top:1.5rem}.mt-4{margin-top:2rem}
.mb-1{margin-bottom:.5rem}.mb-2{margin-bottom:1rem}.mb-3{margin-bottom:1.5rem}
.text-muted{color:var(--text-muted)}.text-sm{font-size:.85rem}.text-center{text-align:center}
hr.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Auth pages ─────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: flex; align-items: stretch; }

.auth-left {
  flex: 1; background: var(--nav-bg); display: none;
  flex-direction: column; justify-content: flex-end;
  padding: 3rem; position: relative; overflow: hidden;
}
@media (min-width: 860px) { .auth-left { display: flex; } }

.auth-left-bg {
  position: absolute; inset: 0;
  background: linear-gradient(160deg, #1a2d4a 0%, #2E6DB4 70%, #1a4472 100%);
}
.auth-left-mountain {
  position: absolute; bottom: 0; left: 0; right: 0; opacity: .12;
}
.auth-left-content { position: relative; z-index: 1; color: #fff; }
.auth-left-content h2 {
  font-family: var(--font-title); font-size: 2.2rem; font-weight: 700;
  color: #fff; margin-bottom: .75rem; line-height: 1.2;
}
.auth-left-content p { color: rgba(255,255,255,.75); font-size: 1rem; line-height: 1.65; }

.auth-left-logo {
  position: relative; z-index: 1; margin-bottom: auto;
  display: flex; align-items: center; gap: .85rem;
}
.auth-left-logo img { width: 54px; height: 54px; object-fit: contain;  }
.auth-left-logo div strong {
  display: block; color: #fff; font-family: var(--font-title); font-size: 1.05rem;
}
.auth-left-logo div span { color: rgba(255,255,255,.6); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }

.auth-right {
  width: 100%; max-width: 480px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 2.5rem 2rem; background: var(--white);
}
@media (max-width: 859px) { .auth-right { max-width: 100%; } }

.auth-box { width: 100%; max-width: 380px; }

.auth-logo-mobile {
  text-align: center; margin-bottom: 2rem; display: block;
}
@media (min-width: 860px) { .auth-logo-mobile { display: none; } }
.auth-logo-mobile img { width: 64px; height: 64px; object-fit: contain; margin-bottom: .5rem; }
.auth-logo-mobile strong {
  display: block; font-family: var(--font-title); font-size: 1.1rem;
  color: var(--blue-dark);
}
.auth-logo-mobile span { display: block; font-size: .78rem; color: var(--text-muted); }

.auth-title { font-family: var(--font-title); font-size: 1.6rem; font-weight: 700; color: var(--text); margin-bottom: .3rem; }
.auth-sub   { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.75rem; }

/* OTP */
.otp-row { display: flex; gap: .5rem; justify-content: center; margin: 1.5rem 0; }
.otp-digit {
  width: 46px; height: 54px; text-align: center;
  font-size: 1.5rem; font-weight: 700;
  border: 2px solid var(--border-dark); border-radius: var(--radius);
  background: var(--white); color: var(--text);
  transition: border-color var(--tr), box-shadow var(--tr);
}
.otp-digit:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,109,180,.15); }

/* ── Dashboard ──────────────────────────────────────────── */
.stat-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm); border-top: 3px solid var(--border);
}
.stat-card.accent { border-top-color: var(--blue); }
.stat-card.green  { border-top-color: var(--green); }
.stat-card.yellow { border-top-color: var(--yellow); }
.stat-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.stat-value { font-family: var(--font-title); font-size: 2.2rem; font-weight: 700; color: var(--text); line-height: 1; margin: .35rem 0 .25rem; }
.stat-sub   { font-size: .8rem; color: var(--text-muted); }

.mod-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--tr), box-shadow var(--tr), transform var(--tr);
  text-decoration: none !important; color: var(--text) !important;
}
.mod-card:hover {
  border-color: var(--blue-mid); box-shadow: var(--shadow);
  transform: translateY(-1px); color: var(--text) !important;
}
.mod-card-icon {
  width: 44px; height: 44px; border-radius: var(--radius);
  background: var(--blue-light); color: var(--blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.mod-card-icon svg { width: 22px; height: 22px; }
.mod-card-text strong { display: block; font-size: .95rem; font-weight: 600; color: var(--text); }
.mod-card-text span   { font-size: .8rem; color: var(--text-muted); }

/* ── Permessi ───────────────────────────────────────────── */
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); }
.perm-table th { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); background: var(--bg); }
.perm-table td:not(:first-child) { text-align: center; }
.perm-check { width: 17px; height: 17px; accent-color: var(--blue); cursor: pointer; }

/* ── Avatar ─────────────────────────────────────────────── */
.avatar-edit { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.avatar-lg {
  width: 80px; height: 80px; border-radius: 50%; overflow: hidden;
  border: 3px solid var(--blue-mid); background: var(--blue-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 700; color: var(--blue); flex-shrink: 0;
}
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

/* ── Misc ───────────────────────────────────────────────── */
.role-tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; opacity: .3; margin-bottom: 1rem; }
.empty-state p { font-size: .95rem; }
.pagination { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; }
.pagination a, .pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius);
  font-size: .85rem; font-weight: 500; text-decoration: none !important;
  border: 1px solid var(--border); color: var(--text-sub);
  transition: all var(--tr);
}
.pagination a:hover { background: var(--bg); color: var(--text); }
.pagination span.current { background: var(--blue); color: #fff; border-color: var(--blue); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }

@media print {
  .topbar, .btn, .pagination { display: none !important; }
  .main-wrap { padding-top: 0; }
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  width: 100%;
  background: var(--nav-bg);
  border-top: 3px solid var(--blue);
  padding: 1.1rem 1.25rem;
}
.site-footer-inner {
  max-width: 1200px; margin: 0 auto;
  font-size: .82rem; color: rgba(255,255,255,.6);
  text-align: center; line-height: 1.8;
}
.site-footer-inner p { margin: .1rem 0; }
.site-footer-inner a { color: rgba(255,255,255,.8); text-decoration: none; }
.site-footer-inner a:hover { color: #fff; text-decoration: underline; }
.site-footer-inner strong { color: rgba(255,255,255,.9); }
