:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1c2733;
  --text-muted: #5b6b7c;
  --primary: #0f6cbd;
  --primary-hover: #0c5aa0;
  --danger: #c4314b;
  --success: #107c41;
  --warning: #b35c00;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

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

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 72px;
}
.topbar .brand {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: #e8f1fa; color: var(--primary); }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 14px; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; margin: 0; }

/* Cards & tables */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-body { padding: 20px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: none; }
td .sub { color: var(--text-muted); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; padding: 4px 8px; }
.btn-danger:hover { background: #fdf2f4; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.form-group .hint { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
input[type="text"], input[type="date"], input[type="number"], input[type="url"], input[type="file"], select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 4px; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; }
.alert-success { background: #e6f4ea; color: var(--success); border: 1px solid #b7dfc4; }
.alert-error { background: #fdf2f4; color: var(--danger); border: 1px solid #f0c3cc; }

/* Badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: #e6f4ea; color: var(--success); }
.badge-red { background: #fdf2f4; color: var(--danger); }
.badge-orange { background: #fff4e5; color: var(--warning); }
.badge-gray { background: #eef1f4; color: var(--text-muted); }

/* Filters */
.filters { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 180px; }

/* Pagination (Laravel default markup, simplified) */
.pagination-wrapper { margin-top: 16px; }

/* Login page */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 44px 40px; width: 100%; max-width: 400px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 0 0 8px; }
.login-card p { color: var(--text-muted); margin: 0 0 28px; }
.btn-microsoft { display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 11px; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }

/* Pagination (pagination::default view) */
ul.pagination { display: flex; gap: 4px; list-style: none; padding: 0; margin: 0; }
ul.pagination li a, ul.pagination li span {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 14px;
}
ul.pagination li.active span { background: var(--primary); color: #fff; border-color: var(--primary); }
ul.pagination li.disabled span { color: var(--text-muted); background: var(--bg); }
ul.pagination li a:hover { background: var(--bg); text-decoration: none; }

/* Loghi vendor */
.vendor-cell { display: inline-flex; align-items: center; gap: 8px; }
.vendor-logo-sm { height: 20px; max-width: 60px; object-fit: contain; }
.vendor-logo-preview { height: 48px; max-width: 160px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; background: #fff; }
.vendor-logo-col { width: 90px; color: var(--text-muted); }
.vendor-logo-table { height: 28px; max-width: 80px; object-fit: contain; display: block; }

/* Kebab menu (azioni secondarie nel footer dei form) */
.form-actions { align-items: center; }
.kebab { position: relative; margin-left: auto; }
.kebab summary {
  list-style: none; cursor: pointer; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 18px; color: var(--text-muted);
  user-select: none;
}
.kebab summary::-webkit-details-marker { display: none; }
.kebab summary:hover, .kebab[open] summary { background: var(--bg); }
.kebab-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0,0,0,.10);
  min-width: 140px; padding: 4px; z-index: 20;
}
.kebab-danger {
  width: 100%; text-align: left; background: none; border: none;
  padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--danger);
  cursor: pointer; border-radius: 6px; font-family: inherit;
}
.kebab-danger:hover { background: #fdf2f4; }

/* Nav mobile */
.nav-toggle {
  display: none; width: 40px; height: 40px; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  font-size: 18px; color: var(--text); cursor: pointer; font-family: inherit;
}
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 56px; padding: 8px 16px; gap: 8px; }
  .topbar .brand { flex: 1; }
  .nav-toggle { display: flex; }
  .topbar nav, .topbar .user { display: none; }
  .topbar.open nav {
    display: flex; flex-direction: column; gap: 2px; width: 100%; flex: none;
    border-top: 1px solid var(--border); padding-top: 8px;
  }
  .topbar.open nav a { padding: 11px 12px; }
  .topbar.open .user {
    display: flex; width: 100%; justify-content: space-between;
    border-top: 1px solid var(--border); padding: 10px 12px 4px;
  }
  .container { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .card { overflow-x: auto; }
  .card table { min-width: 640px; }
}

/* Logo aziendale nell'header */
.brand-logo { height: 58px; width: auto; display: block; }
@media (max-width: 768px) {
  .brand-logo { height: 46px; }
}

/* Selettore vista tabella/schede */
.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.view-switch button {
  width: 38px; height: 36px; border: none; background: var(--surface); cursor: pointer;
  font-size: 15px; color: var(--text-muted); font-family: inherit;
}
.view-switch button + button { border-left: 1px solid var(--border); }
.view-switch button.active { background: #e8f1fa; color: var(--primary); }

/* Vista a schede delle certificazioni */
.cert-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.cert-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 4px;
}
.cert-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cert-card-logo { height: 34px; max-width: 110px; object-fit: contain; }
.cert-card-logo-placeholder {
  width: 34px; height: 34px; border-radius: 8px; background: var(--bg); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px;
}
.cert-card-title { font-weight: 600; line-height: 1.35; }
.cert-card-meta { margin-top: 10px; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.cert-card-meta span { color: var(--text-muted); display: inline-block; min-width: 92px; }
.cert-card-actions {
  margin-top: auto; padding-top: 14px; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; font-size: 14px;
}

/* Filtri su una sola riga su desktop */
@media (min-width: 769px) {
  .filters { flex-wrap: nowrap; }
  .filters input[type="text"], .filters select { min-width: 0; flex: 1 1 auto; }
  .filters .btn { flex: 0 0 auto; }
}

/* Statistiche: tile KPI */
.stats-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.stat-value { font-size: 32px; font-weight: 650; line-height: 1.1; color: var(--text); }
.stat-value.stat-warning { color: var(--warning); }
.stat-value.stat-danger { color: var(--danger); }
.stat-sub { font-size: 14px; font-weight: 500; color: var(--text-muted); }

/* Statistiche: grafici a barre orizzontali */
.stats-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.chart-title { font-size: 15px; font-weight: 600; margin: 0 0 14px; }
.hbar-chart { display: flex; flex-direction: column; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 10px; }
.hbar-label {
  font-size: 13px; color: var(--text-muted); text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill {
  height: 18px; background: var(--primary);
  border-radius: 0 4px 4px 0; /* punta arrotondata, base squadrata */
  min-width: 2px; flex: none;
  max-width: calc(100% - 38px); /* spazio riservato al valore in punta */
}
.hbar-value { font-size: 13px; color: var(--text); font-weight: 600; }
.chart-note { margin-top: 12px; font-size: 13px; color: var(--text-muted); }
