/* =========================================================
   FILE: /assets/ui.css
   MODULO: CSS Globale CRM
   SCOPO:
   - Stili globali dell'applicazione CRM
   - Layout generale: sidebar, topbar, content
   - Componenti UI condivisi: card, bottoni, form, tabelle
   - Supporto brand sidebar con logo immagine o testo
   ========================================================= */

:root{
  --bg:#eef2f6;
  --content-bg:#f4f7fa;
  --card:#ffffff;
  --text:#18212b;
  --muted:#7a8794;

  --sidebar-bg:#3d5166;
  --sidebar-bg-dark:#33465a;
  --sidebar-border:rgba(255,255,255,.08);
  --sidebar-text:#f1f5f9;
  --sidebar-text-soft:rgba(255,255,255,.78);
  --sidebar-hover:rgba(255,255,255,.08);
  --sidebar-active:rgba(255,255,255,.14);
  --sidebar-sub-bg:rgba(0,0,0,.10);

  --border:#dbe2ea;
  --border-soft:#e7edf3;
  --shadow:0 8px 24px rgba(16,24,40,.08);

  --topbar-bg:var(--sidebar-bg);
  --topbar-border:rgba(0,0,0,.10);
  --topbar-shadow:0 6px 18px rgba(15,23,42,.10);

  --btn-bg:#eef2f6;
  --btn-text:#1f2a37;
  --btn-border:#d7e0e8;

  --btn-primary-bg:#dcecff;
  --btn-primary-border:#bfd8f6;
  --btn-primary-hover:#d2e6ff;

  --btn-soft-bg:#f7f9fb;
  --btn-soft-border:#d7e0e8;
  --btn-soft-hover:#eef3f7;

  --btn-danger:#c63b3b;
  --btn-danger-hover:#ad2f2f;

  --success-bg:#edf9f0;
  --success-border:#cfe9d5;
  --success-text:#1f5d35;

  --error-bg:#fff1f1;
  --error-border:#efcaca;
  --error-text:#9b1c1c;

  --warning-bg:#fff8e8;
  --warning-border:#f1dfb1;
  --warning-text:#8a6500;

  --info-bg:#eef6ff;
  --info-border:#cfe0f5;
  --info-text:#24496e;

  --focus-ring:0 0 0 3px rgba(159,194,230,.22);
}

*,
*::before,
*::after{
  box-sizing:border-box;
}

html,
body{
  margin:0;
  padding:0;
}

html{
  scroll-behavior:smooth;
}

body{
  font-family:Arial,sans-serif;
  background:var(--content-bg);
  color:var(--text);
  overflow-x:hidden;
  line-height:1.45;
}

a{
  color:inherit;
  text-decoration:none;
}

img{
  max-width:100%;
  height:auto;
  display:block;
}

button,
input,
select,
textarea{
  font:inherit;
}

.app{
  display:flex;
  min-height:100vh;
  background:var(--content-bg);
}

.sidebar{
  width:250px;
  min-width:250px;
  background:var(--sidebar-bg);
  color:var(--sidebar-text);
  position:sticky;
  top:0;
  height:100vh;
  display:flex;
  flex-direction:column;
  z-index:1000;
  border-right:1px solid rgba(0,0,0,.08);
  overflow:hidden;
}

.brand{
  padding:16px 14px 12px;
  border-bottom:1px solid var(--sidebar-border);
  background:var(--sidebar-bg-dark);
  display:flex;
  justify-content:center;
  align-items:center;
}

.brand a{
  display:flex;
  justify-content:center;
  align-items:center;
  width:100%;
  text-decoration:none;
  min-height:56px;
}

.brand img{
  width:100%;
  max-width:190px;
  background:#fff;
  padding:6px;
  border-radius:0;
  margin:0 auto;
}

.brand-text{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:100%;
  min-height:44px;
  padding:10px 12px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:12px;
  background:rgba(255,255,255,.06);
  color:#fff;
  font-size:20px;
  font-weight:800;
  line-height:1.1;
  text-align:center;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.04);
}

.userbox{
  padding:12px 16px;
  font-size:12px;
  color:var(--sidebar-text-soft);
  background:rgba(0,0,0,.06);
  border-bottom:1px solid var(--sidebar-border);
}

.userbox strong{
  color:#fff;
}

.nav{
  display:flex;
  flex-direction:column;
  flex:1;
  min-height:0;
  overflow-y:auto;
  padding:10px 0;
}

.nav > a{
  display:flex;
  align-items:center;
  min-height:42px;
  padding:10px 16px;
  text-decoration:none;
  color:var(--sidebar-text);
  border-left:3px solid transparent;
  font-size:15px;
  transition:background .18s ease, border-color .18s ease, color .18s ease;
}

.nav > a:hover{
  background:var(--sidebar-hover);
}

.nav > a.active{
  background:var(--sidebar-active);
  border-left-color:#9fc2e6;
  color:#fff;
  font-weight:700;
}

.nav-label{
  display:flex;
  align-items:center;
  gap:10px;
  width:100%;
  min-width:0;
}

.nav-icon{
  width:18px;
  height:18px;
  flex:0 0 18px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.nav-icon svg{
  width:18px;
  height:18px;
  display:block;
  fill:currentColor;
}

.nav-text{
  min-width:0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.nav-group{
  margin:0;
  padding:0;
  border:0;
}

.nav-group > summary{
  list-style:none;
}

.nav-group > summary::-webkit-details-marker{
  display:none;
}

.nav-group-title{
  display:flex;
  align-items:center;
  justify-content:space-between;
  min-height:42px;
  padding:10px 16px;
  cursor:pointer;
  color:var(--sidebar-text);
  border-left:3px solid transparent;
  font-size:15px;
  transition:background .18s ease, border-color .18s ease, color .18s ease;
}

.nav-group-title:hover{
  background:var(--sidebar-hover);
}

.nav-group-title::after{
  content:"";
  width:8px;
  height:8px;
  border-right:2px solid rgba(255,255,255,.82);
  border-bottom:2px solid rgba(255,255,255,.82);
  transform:rotate(-45deg);
  margin-left:12px;
  margin-right:2px;
  flex:0 0 8px;
  transition:transform .18s ease, opacity .18s ease;
  opacity:.9;
}

.nav-group[open] > .nav-group-title::after{
  transform:rotate(45deg);
}

.nav-group.active > .nav-group-title{
  background:var(--sidebar-active);
  border-left-color:#9fc2e6;
  color:#fff;
  font-weight:700;
}

.nav-sub{
  display:flex;
  flex-direction:column;
  background:var(--sidebar-sub-bg);
  padding:6px 0;
}

.nav-sub .sub{
  display:flex;
  align-items:center;
  min-height:36px;
  padding:8px 16px 8px 30px;
  text-decoration:none;
  color:var(--sidebar-text-soft);
  font-size:14px;
  border-left:3px solid transparent;
  transition:background .18s ease, border-color .18s ease, color .18s ease;
}

.nav-sub .sub:hover{
  background:rgba(255,255,255,.06);
  color:#fff;
}

.nav-sub .sub.active{
  background:rgba(255,255,255,.10);
  border-left-color:#9fc2e6;
  color:#fff;
  font-weight:700;
}

.nav .spacer{
  flex:1;
  min-height:14px;
}

.sidebar-footer{
  margin-top:auto;
  padding:14px 16px 12px;
  border-top:1px solid var(--sidebar-border);
  font-size:11px;
  line-height:1.4;
  color:var(--sidebar-text-soft);
  background:rgba(0,0,0,.08);
}

.sidebar-copy{
  margin-bottom:4px;
  font-weight:700;
  color:#fff;
}

.sidebar-date{
  font-size:11px;
  color:var(--sidebar-text-soft);
}

.logout-btn{
  display:block;
  margin:10px 16px 16px;
  padding:10px 14px;
  border-radius:10px;
  background:var(--btn-danger);
  color:#fff !important;
  text-decoration:none;
  text-align:center;
  font-weight:700;
  border:0;
  transition:background .18s ease;
}

.logout-btn:hover{
  background:var(--btn-danger-hover);
}

.content{
  flex:1;
  min-width:0;
  padding:22px;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:18px;
  padding:14px 16px;
  background:var(--topbar-bg);
  border:1px solid var(--topbar-border);
  border-radius:14px;
  box-shadow:var(--topbar-shadow);
}

.topbar-left{
  display:flex;
  align-items:center;
  gap:12px;
  min-width:0;
}

.topbar h1{
  margin:0;
  font-size:22px;
  line-height:1.2;
  font-weight:800;
  color:#ffffff;
}

.menu-toggle{
  display:none;
  width:40px;
  height:40px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.10);
  color:#fff;
  cursor:pointer;
  font-size:20px;
  line-height:1;
  align-items:center;
  justify-content:center;
}

.menu-toggle:hover{
  background:rgba(255,255,255,.16);
}

.mobile-overlay{
  display:none;
}

.tools{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:16px;
  box-shadow:var(--shadow);
  padding:18px;
}

.card-header{
  margin:-18px -18px 16px;
  padding:10px 14px;
  border-bottom:1px solid var(--border-soft);
  background:#f8fafc;
  border-top-left-radius:16px;
  border-top-right-radius:16px;
}

.card-header-row{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}

.card-title-wrap{
  min-width:0;
}

.card-title{
  margin:0;
  font-size:14px;
  font-weight:700;
  line-height:1.2;
}

.card-subtitle{
  margin:3px 0 0;
  color:var(--muted);
  font-size:11px;
  line-height:1.35;
}

.card-actions{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}

.card-body{
  min-width:0;
}

.card-header-clients{
  background:#eef6ff;
}

.card-header-users{
  background:#f3f7ff;
}

.card-header-security{
  background:#fff5ef;
}

.card-header-system{
  background:#f3f8f1;
}

.crm-kpi-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(120px,1fr));
  gap:8px;
}

.crm-kpi{
  background:#fff;
  border:1px solid var(--border);
  border-radius:10px;
  padding:8px 10px;
  min-height:52px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  box-shadow:none;
}

.crm-kpi-label{
  font-size:10px;
  color:#667789;
  line-height:1.1;
  margin-bottom:3px;
}

.crm-kpi-value{
  font-size:16px;
  line-height:1;
  font-weight:800;
  color:#0f172a;
}

.crm-kpi-users{
  background:#ffffff;
}

.crm-kpi-security{
  background:#fffaf5;
}

.crm-kpi-clients{
  background:#f8fbff;
}

.crm-row-mine{
  background:rgba(159,194,230,.18);
}

.ui-alert{
  padding:11px 14px;
  border-radius:12px;
  border:1px solid transparent;
  font-size:14px;
}

.ui-alert-success{
  background:var(--success-bg);
  border-color:var(--success-border);
  color:var(--success-text);
}

.ui-alert-error{
  background:var(--error-bg);
  border-color:var(--error-border);
  color:var(--error-text);
}

.ui-alert-warning{
  background:var(--warning-bg);
  border-color:var(--warning-border);
  color:var(--warning-text);
}

.table-wrap{
  width:100%;
  overflow:auto;
  border:1px solid var(--border-soft);
  border-radius:12px;
}

.table{
  width:100%;
  min-width:900px;
  border-collapse:collapse;
  background:#fff;
}

.table th,
.table td{
  padding:10px 12px;
  border-bottom:1px solid var(--border-soft);
  text-align:left;
  vertical-align:middle;
  font-size:13px;
}

.table th{
  background:#f8fafc;
  color:#415163;
  font-weight:700;
  white-space:nowrap;
}

.table tbody tr:hover{
  background:#fafcff;
}

.table tbody tr:last-child td{
  border-bottom:0;
}

.ui-form-row{
  display:flex;
  flex-wrap:wrap;
  gap:14px;
}

.ui-field{
  min-width:0;
}

.ui-col-1{ flex:0 0 calc(8.333% - 14px); max-width:calc(8.333% - 14px); }
.ui-col-2{ flex:0 0 calc(16.666% - 14px); max-width:calc(16.666% - 14px); }
.ui-col-3{ flex:0 0 calc(25% - 14px); max-width:calc(25% - 14px); }
.ui-col-4{ flex:0 0 calc(33.333% - 14px); max-width:calc(33.333% - 14px); }
.ui-col-5{ flex:0 0 calc(41.666% - 14px); max-width:calc(41.666% - 14px); }
.ui-col-6{ flex:0 0 calc(50% - 14px); max-width:calc(50% - 14px); }
.ui-col-7{ flex:0 0 calc(58.333% - 14px); max-width:calc(58.333% - 14px); }
.ui-col-8{ flex:0 0 calc(66.666% - 14px); max-width:calc(66.666% - 14px); }
.ui-col-9{ flex:0 0 calc(75% - 14px); max-width:calc(75% - 14px); }
.ui-col-10{ flex:0 0 calc(83.333% - 14px); max-width:calc(83.333% - 14px); }
.ui-col-11{ flex:0 0 calc(91.666% - 14px); max-width:calc(91.666% - 14px); }
.ui-col-12{ flex:0 0 100%; max-width:100%; }

.ui-label{
  display:block;
  margin-bottom:6px;
  font-size:12px;
  font-weight:700;
  color:#304154;
}

.ui-input,
.ui-select,
.ui-textarea{
  width:100%;
  min-height:38px;
  padding:8px 12px;
  border:1px solid #cfd9e3;
  border-radius:12px;
  background:#fff;
  color:var(--text);
  outline:none;
  transition:border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.ui-input:focus,
.ui-select:focus,
.ui-textarea:focus{
  border-color:#9fc2e6;
  box-shadow:var(--focus-ring);
}

.ui-textarea{
  min-height:96px;
  resize:vertical;
}

.ui-check-row{
  min-height:38px;
  border:1px solid #d8e1ea;
  border-radius:12px;
  background:#f8fafc;
  padding:8px 12px;
  display:flex;
  align-items:center;
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:34px;
  padding:8px 12px;
  border-radius:10px;
  border:1px solid var(--btn-border);
  background:var(--btn-bg);
  color:var(--btn-text);
  text-decoration:none;
  cursor:pointer;
  font-size:13px;
  font-weight:600;
  transition:background .18s ease, border-color .18s ease, transform .18s ease;
}

.btn:hover{
  background:#e7edf3;
}

.btn-primary{
  background:var(--btn-primary-bg);
  border-color:var(--btn-primary-border);
}

.btn-primary:hover{
  background:var(--btn-primary-hover);
}

.btn-soft{
  background:var(--btn-soft-bg);
  border-color:var(--btn-soft-border);
}

.btn-soft:hover{
  background:var(--btn-soft-hover);
}

.btn-danger{
  background:var(--btn-danger);
  border-color:var(--btn-danger);
  color:#fff;
}

.btn-danger:hover{
  background:var(--btn-danger-hover);
  border-color:var(--btn-danger-hover);
}

.btn-sm{
  min-height:30px;
  padding:6px 10px;
  font-size:12px;
}

.btn-xs{
  min-height:28px;
  padding:5px 9px;
  font-size:12px;
}

.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:24px;
  padding:4px 8px;
  border-radius:999px;
  font-size:12px;
  font-weight:700;
  line-height:1;
  white-space:nowrap;
}

.badge-info{
  background:var(--info-bg);
  border:1px solid var(--info-border);
  color:var(--info-text);
}

.badge-open{
  background:var(--success-bg);
  border:1px solid var(--success-border);
  color:var(--success-text);
}

.badge-high{
  background:var(--error-bg);
  border:1px solid var(--error-border);
  color:var(--error-text);
}

.muted{
  color:var(--muted);
}

.ellipsis{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.ui-empty{
  padding:16px;
  text-align:center;
  color:var(--muted);
  background:#fbfcfd;
  border:1px dashed var(--border);
  border-radius:12px;
}

.ui-mb-18{ margin-bottom:18px; }
.ui-mb-16{ margin-bottom:16px; }
.ui-mt-12{ margin-top:12px; }

@media (max-width: 980px){
  .menu-toggle{
    display:inline-flex;
  }

  .sidebar{
    position:fixed;
    left:0;
    top:0;
    height:100vh;
    transform:translateX(-100%);
    transition:transform .25s ease;
    box-shadow:0 18px 38px rgba(0,0,0,.28);
  }

  body.menu-open .sidebar{
    transform:translateX(0);
  }

  .mobile-overlay{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,.35);
    z-index:999;
  }

  body.menu-open .mobile-overlay{
    display:block;
  }

  .content{
    padding:14px;
  }

  .topbar{
    flex-direction:column;
    align-items:flex-start;
    gap:10px;
  }

  .topbar-left{
    width:100%;
  }

  .topbar h1{
    font-size:19px;
  }

  .tools{
    width:100%;
  }

  .brand-text{
    font-size:18px;
    min-height:42px;
    padding:9px 10px;
  }

  .ui-col-1,
  .ui-col-2,
  .ui-col-3,
  .ui-col-4,
  .ui-col-5,
  .ui-col-6,
  .ui-col-7,
  .ui-col-8,
  .ui-col-9,
  .ui-col-10,
  .ui-col-11{
    flex:0 0 calc(50% - 14px);
    max-width:calc(50% - 14px);
  }

  .ui-col-12{
    flex:0 0 100%;
    max-width:100%;
  }
}

@media (max-width: 640px){
  .card{
    padding:14px;
  }

  .card-header{
    margin:-14px -14px 14px;
    padding:10px 12px;
  }

  .card-header-row{
    flex-direction:column;
    align-items:stretch;
  }

  .card-actions{
    width:100%;
  }

  .card-actions .btn{
    width:100%;
  }

  .brand{
    padding:14px 12px 10px;
  }

  .brand a{
    min-height:50px;
  }

  .brand img{
    max-width:170px;
  }

  .brand-text{
    font-size:17px;
    border-radius:10px;
    min-height:40px;
    padding:8px 10px;
  }

  .ui-col-1,
  .ui-col-2,
  .ui-col-3,
  .ui-col-4,
  .ui-col-5,
  .ui-col-6,
  .ui-col-7,
  .ui-col-8,
  .ui-col-9,
  .ui-col-10,
  .ui-col-11,
  .ui-col-12{
    flex:0 0 100%;
    max-width:100%;
  }

  .btn{
    min-height:36px;
    padding:8px 12px;
  }

  .topbar{
    padding:12px 14px;
  }
}