/* Bauvenuto Gestionale — UI */
:root {
  --c-primary: #1d3557;
  --c-primary-2: #2a4a73;
  --c-primary-d: #142540;
  --c-accent: #e63946;
  --c-accent-d: #c62a36;
  --c-ok: #2e8540;
  --c-warn: #f4a261;
  --c-bg: #f1f4f8;
  --c-card: #ffffff;
  --c-border: #d8dee6;
  --c-border-2: #eef1f5;
  --c-text: #1a1a1a;
  --c-text-mute: #5b6878;
  --c-row-alt: #f5f8fc;
  --c-shadow: 0 2px 6px rgba(20, 37, 64, .08), 0 1px 2px rgba(20, 37, 64, .06);
  --c-shadow-lg: 0 12px 32px rgba(20, 37, 64, .15);
  --radius: 10px;
  --radius-sm: 6px;
  --header-h: 58px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* Loader */
.loader { display: flex; align-items: center; justify-content: center; height: 60vh; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at top, #2a4a73 0%, #1d3557 50%, #142540 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px 26px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.login-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 22px;
}
.login-logo svg { width: 48px; height: 48px; }
.login-logo .name { font-size: 20px; font-weight: 700; color: var(--c-primary); }
.login-logo .sub { font-size: 12px; color: var(--c-text-mute); margin-top: 2px; }
.login-card h1 { font-size: 18px; margin: 0 0 18px; }
.login-card .field { margin-bottom: 14px; }
.login-card label {
  display: block; font-size: 12px; color: var(--c-text-mute); margin-bottom: 5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
}
.login-card input[type=text],
.login-card input[type=password] {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  border: 1.5px solid var(--c-border);
  border-radius: 10px;
  background: #fbfcfe;
  transition: border .15s, box-shadow .15s;
}
.login-card input:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(29, 53, 87, 0.12);
  background: #fff;
}
.login-card .err { color: var(--c-accent); font-size: 13px; margin-bottom: 10px; min-height: 18px; }
.login-card button {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 600;
  background: var(--c-primary); color: #fff; border: 0; border-radius: 10px;
  cursor: pointer; transition: background .15s;
}
.login-card button:hover { background: var(--c-primary-2); }
.login-card button:disabled { opacity: .6; cursor: wait; }
.login-foot { text-align: center; margin-top: 18px; color: var(--c-text-mute); font-size: 11px; }

/* ---------- App layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: var(--c-primary);
  color: #fff;
  display: flex; align-items: center;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar .brand svg { width: 30px; height: 30px; flex-shrink: 0; }
.topbar .brand .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand .badge { font-size: 11px; opacity: .8; margin-left: 6px; padding: 2px 7px; background: rgba(255,255,255,.15); border-radius: 10px; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .user .name { display: none; }
@media (min-width: 720px) { .topbar .user .name { display: inline; } }
.topbar .icon-btn {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.topbar .icon-btn:hover { background: rgba(255,255,255,.25); }
.topbar .menu-btn { display: none; }
@media (max-width: 900px) { .topbar .menu-btn { display: flex; margin-right: 8px; } }

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--c-border);
  padding: 14px 10px;
  overflow-y: auto;
}
.sidebar .nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px;
  border-radius: 9px;
  color: var(--c-text);
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background .12s;
}
.sidebar .nav-item:hover { background: var(--c-row-alt); text-decoration: none; }
.sidebar .nav-item.active { background: var(--c-primary); color: #fff; }
.sidebar .nav-item .ic { width: 20px; text-align: center; font-size: 16px; }
.sidebar .nav-section { margin-top: 14px; padding: 0 14px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--c-text-mute); font-weight: 700; }

@media (max-width: 900px) {
  .sidebar { position: fixed; top: var(--header-h); bottom: 0; left: 0; transform: translateX(-100%); transition: transform .25s; z-index: 49; box-shadow: var(--c-shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0,0,0,.35); z-index: 48; display: none; }
  .sidebar-backdrop.show { display: block; }
}

.content {
  flex: 1; min-width: 0;
  padding: 18px 18px 80px;
  overflow-x: hidden;
}
@media (max-width: 600px) { .content { padding: 14px 12px 80px; } }

/* ---------- Cards / pages ---------- */
.page-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 22px; flex: 1; min-width: 0; }
@media (max-width: 600px) { .page-head h1 { font-size: 18px; } }

.card {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--c-shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; color: var(--c-primary); }
.card .muted { color: var(--c-text-mute); }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

/* Stats tiles */
.stat-tile { background: #fff; border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--c-shadow); display: flex; align-items: center; gap: 14px; border-left: 4px solid var(--c-primary); }
.stat-tile .icon { width: 42px; height: 42px; border-radius: 10px; background: rgba(29,53,87,.1); color: var(--c-primary); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-tile .label { font-size: 12px; color: var(--c-text-mute); text-transform: uppercase; letter-spacing: .3px; font-weight: 600; }
.stat-tile .value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-tile.accent { border-left-color: var(--c-accent); }
.stat-tile.accent .icon { background: rgba(230,57,70,.12); color: var(--c-accent); }
.stat-tile.ok { border-left-color: var(--c-ok); }
.stat-tile.ok .icon { background: rgba(46,133,64,.12); color: var(--c-ok); }
.stat-tile.warn { border-left-color: var(--c-warn); }
.stat-tile.warn .icon { background: rgba(244,162,97,.18); color: #b56424; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: #fff; box-shadow: var(--c-shadow); }
table.data {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
table.data th, table.data td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--c-border-2);
  vertical-align: top;
}
table.data th { background: #f7faff; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--c-text-mute); white-space: nowrap; position: sticky; top: 0; }
table.data tbody tr:hover { background: var(--c-row-alt); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px;
  background: var(--c-primary); color: #fff;
  border: 0; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .12s, transform .04s;
  min-height: 40px;
  white-space: nowrap;
}
.btn:hover { background: var(--c-primary-2); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--c-primary); border: 1.5px solid var(--c-border); }
.btn.ghost:hover { background: var(--c-row-alt); }
.btn.accent { background: var(--c-accent); }
.btn.accent:hover { background: var(--c-accent-d); }
.btn.ok { background: var(--c-ok); }
.btn.ok:hover { background: #226730; }
.btn.danger { background: #c62a36; }
.btn.sm { padding: 6px 11px; font-size: 13px; min-height: 32px; }
.btn.icon { padding: 0; width: 36px; min-height: 36px; border-radius: 50%; }
.btn-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* Status badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.badge.draft { background: rgba(244,162,97,.18); color: #b56424; }
.badge.completed { background: rgba(46,133,64,.15); color: var(--c-ok); }
.badge.admin { background: rgba(230,57,70,.15); color: var(--c-accent-d); }
.badge.capo { background: rgba(29,53,87,.12); color: var(--c-primary); }
.badge.inactive { background: #e9ecef; color: #888; }

/* Forms */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; color: var(--c-text-mute); font-weight: 600; margin-bottom: 5px; text-transform: uppercase; letter-spacing: .3px; }
.form-row input[type=text], .form-row input[type=password], .form-row input[type=date],
.form-row input[type=email], .form-row select, .form-row textarea {
  width: 100%; padding: 11px 12px; font-size: 15px;
  border: 1.5px solid var(--c-border); border-radius: 8px;
  background: #fff; transition: border .15s, box-shadow .15s;
  font-family: inherit;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(29,53,87,.12);
}
.form-row textarea { resize: vertical; min-height: 80px; }
.form-row .check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.form-row .check input { width: 18px; height: 18px; accent-color: var(--c-primary); }

/* Module list (capo) */
.module-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.module-card {
  background: #fff; border-radius: var(--radius); padding: 18px; cursor: pointer;
  box-shadow: var(--c-shadow);
  transition: transform .15s, box-shadow .15s;
  border-top: 4px solid var(--c-primary);
  display: flex; flex-direction: column; gap: 10px;
}
.module-card:hover { transform: translateY(-3px); box-shadow: var(--c-shadow-lg); text-decoration: none; }
.module-card .name { font-weight: 700; font-size: 16px; color: var(--c-primary); }
.module-card .title { font-size: 13px; color: var(--c-text-mute); line-height: 1.4; }
.module-card .meta { font-size: 12px; color: var(--c-text-mute); display: flex; gap: 14px; margin-top: auto; }

/* ---------- Report editor ---------- */
.report-toolbar {
  position: sticky; top: var(--header-h); z-index: 30;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--c-border);
  margin: -18px -18px 14px;
  padding: 10px 18px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
@media (max-width: 600px) { .report-toolbar { margin: -14px -12px 12px; padding: 9px 12px; } }
.report-toolbar .info { flex: 1; min-width: 200px; font-size: 13px; color: var(--c-text-mute); }
.report-toolbar .info b { color: var(--c-text); font-weight: 600; }

/* report data grid */
.report-table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--c-shadow); margin-bottom: 18px; overflow: auto; max-width: 100%; }
.report-table { border-collapse: collapse; min-width: 100%; }
.report-table th {
  background: var(--c-primary); color: #fff;
  padding: 10px 9px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; font-weight: 600;
  text-align: left; position: sticky; top: 0;
  border-right: 1px solid rgba(255,255,255,.12);
  white-space: normal; min-width: 80px; max-width: 220px;
}
.report-table th.eseguito-col { background: var(--c-accent); width: 90px; min-width: 90px; text-align: center; }
.report-table td {
  padding: 9px; font-size: 13.5px; border-bottom: 1px solid var(--c-border-2); border-right: 1px solid var(--c-border-2);
  vertical-align: top; white-space: pre-wrap; word-break: break-word; min-width: 80px; max-width: 260px;
}
.report-table tr:nth-child(even) td { background: var(--c-row-alt); }
.report-table tr.done td { background: rgba(46,133,64,.07); }
.report-table tr.done td.eseg-cell { background: rgba(46,133,64,.18); }
.report-table td.eseg-cell {
  text-align: center; cursor: pointer; user-select: none;
  font-size: 26px; line-height: 1; padding: 0; vertical-align: middle;
  width: 90px; min-width: 90px; transition: background .15s;
}
.report-table td.eseg-cell:hover { background: rgba(0,0,0,.06); }
.report-table td.eseg-cell .x { color: var(--c-ok); font-weight: 800; }
.report-table td.eseg-cell .empty { color: var(--c-border); font-size: 22px; }
.report-table tr.done td.eseg-cell { color: var(--c-ok); }

/* On mobile, present rows as cards */
@media (max-width: 720px) {
  .report-table-wrap { overflow: visible; box-shadow: none; background: transparent; }
  .report-table, .report-table thead, .report-table tbody, .report-table tr, .report-table td, .report-table th {
    display: block; width: 100%; max-width: none; min-width: 0;
  }
  .report-table thead { display: none; }
  .report-table tr {
    background: #fff !important;
    border-radius: var(--radius);
    box-shadow: var(--c-shadow);
    margin-bottom: 12px;
    padding: 10px 12px 12px;
    border: 0;
    position: relative;
  }
  .report-table tr.done { box-shadow: 0 0 0 2px var(--c-ok), var(--c-shadow); }
  .report-table td {
    padding: 6px 0;
    border: 0;
    border-bottom: 1px dashed var(--c-border-2);
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .report-table td:last-of-type { border-bottom: 0; }
  .report-table td:before {
    content: attr(data-label);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--c-text-mute);
    font-weight: 700;
  }
  .report-table td.eseg-cell {
    position: absolute; top: 8px; right: 8px;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--c-row-alt);
    border: 2px solid var(--c-border);
    display: flex; align-items: center; justify-content: center;
    font-size: 30px; padding: 0;
  }
  .report-table td.eseg-cell:before { display: none; }
  .report-table tr.done td.eseg-cell { background: var(--c-ok); border-color: var(--c-ok); color: #fff; }
  .report-table tr.done td.eseg-cell .x { color: #fff; }
  .report-table td.eseg-cell .empty { color: var(--c-border); font-size: 28px; }
}

/* Note area */
.notes-block textarea {
  width: 100%; min-height: 130px; padding: 14px;
  border: 1.5px solid var(--c-border); border-radius: var(--radius);
  font-size: 15px; font-family: inherit; line-height: 1.6;
  background:
    linear-gradient(transparent 0, transparent calc(1.6em - 1px), #e8edf4 calc(1.6em - 1px), #e8edf4 1.6em);
  background-size: 100% 1.6em;
  background-attachment: local;
  resize: vertical;
}

/* Signatures */
.signatures { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .signatures { grid-template-columns: 1fr; } }
.sig-box {
  background: #fff; border-radius: var(--radius); padding: 12px;
  box-shadow: var(--c-shadow); display: flex; flex-direction: column; gap: 10px;
}
.sig-box .sig-label { font-weight: 700; color: var(--c-primary); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sig-box .sig-area {
  position: relative;
  border: 2px dashed var(--c-border);
  border-radius: 8px;
  background: #fdfdfd;
  height: 180px;
  touch-action: none;
}
.sig-box .sig-area canvas {
  display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair;
}
.sig-box .sig-area .sig-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; color: #b8c2cf; font-style: italic; font-size: 14px;
}
.sig-box .sig-area.has-sig .sig-placeholder { display: none; }
.sig-box .sig-area.has-sig { border-style: solid; border-color: var(--c-ok); background: #fff; }
.sig-box .sig-actions { display: flex; gap: 8px; }
.sig-box .sig-actions input { flex: 1; padding: 8px 10px; font-size: 13px; border: 1px solid var(--c-border); border-radius: 6px; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--c-primary-d); color: #fff;
  padding: 12px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--c-shadow-lg); z-index: 200;
  animation: toast 3s forwards;
  max-width: 90vw; text-align: center;
}
.toast.err { background: var(--c-accent); }
.toast.ok  { background: var(--c-ok); }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 30px); }
  10%,90% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 30px); }
}

/* Modal */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(20, 37, 64, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
  animation: fadein .15s;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: #fff; border-radius: 14px;
  width: 100%; max-width: 480px; max-height: 90vh;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column;
}
.modal h2 { margin: 0; padding: 18px 20px 12px; font-size: 17px; color: var(--c-primary); border-bottom: 1px solid var(--c-border-2); }
.modal .body { padding: 16px 20px; overflow-y: auto; }
.modal .actions { padding: 12px 20px; border-top: 1px solid var(--c-border-2); display: flex; justify-content: flex-end; gap: 10px; }

/* misc */
.empty-state { text-align: center; padding: 40px 20px; color: var(--c-text-mute); }
.empty-state .ic { font-size: 44px; margin-bottom: 10px; opacity: .5; }
.divider { height: 1px; background: var(--c-border-2); margin: 16px 0; }
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Filters bar */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: end;
  background: #fff; padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--c-shadow); margin-bottom: 16px;
}
.filters .field { display: flex; flex-direction: column; gap: 4px; }
.filters .field label { font-size: 11px; text-transform: uppercase; color: var(--c-text-mute); font-weight: 600; }
.filters .field select, .filters .field input { padding: 8px 10px; font-size: 14px; border: 1px solid var(--c-border); border-radius: 6px; background: #fff; }

/* Print */
@media print {
  .topbar, .sidebar, .report-toolbar, .btn { display: none !important; }
  body { background: #fff; }
}
