/* TaskBoard — stylesheet */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde1e7;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --nav-bg: #1e293b;
  --nav-text: #cbd5e1;
  --radius: 6px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

body { font-family: Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  display: flex; align-items: center; gap: 1.5rem;
  background: var(--nav-bg); padding: 0 1.5rem; height: 52px;
  position: sticky; top: 0; z-index: 100;
}
.nav-brand a { color: #fff; font-size: 1.1rem; font-weight: bold; text-decoration: none; }
.nav-links { display: flex; gap: 1rem; flex: 1; }
.nav-links a { color: var(--nav-text); text-decoration: none; padding: 4px 8px; border-radius: var(--radius); }
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,0.1); color: #fff; }
.nav-user { display: flex; align-items: center; gap: 0.75rem; color: var(--nav-text); }
.nav-user a { color: var(--nav-text); }

/* ── Container ──────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* ── Page header ────────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; gap: 1rem; }
.page-header h2 { font-size: 1.4rem; }
.page-header h2 small { font-size: 0.9rem; font-weight: normal; color: var(--text-muted); }
.back-link { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; }
.header-actions { display: flex; gap: 0.5rem; }

/* ── Cards ──────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card h3 { margin-bottom: 1rem; font-size: 1rem; }
.card h4 { margin-bottom: 0.75rem; font-size: 0.9rem; color: var(--text-muted); }

/* ── KPI grid ───────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; box-shadow: var(--shadow); border-top: 4px solid #94a3b8; }
.kpi-card.kpi-blue  { border-top-color: var(--primary); }
.kpi-card.kpi-orange{ border-top-color: #f97316; }
.kpi-card.kpi-yellow{ border-top-color: var(--warning); }
.kpi-card.kpi-green { border-top-color: var(--success); }
.kpi-card.kpi-gray  { border-top-color: #94a3b8; }
.kpi-card.kpi-red   { border-top-color: var(--danger); }
.kpi-value { font-size: 2rem; font-weight: bold; }
.kpi-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.section-title { font-size: 1rem; margin-bottom: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Badges ─────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 0.75rem; font-weight: bold; }
.priority-bassa   { background: #f1f5f9; color: #64748b; }
.priority-media   { background: #dbeafe; color: #1d4ed8; }
.priority-alta    { background: #fef3c7; color: #b45309; }
.priority-critica { background: #fee2e2; color: #b91c1c; }
.status-aperto   { background: #e0f2fe; color: #0369a1; }
.status-in_corso { background: #dcfce7; color: #15803d; }
.status-chiuso   { background: #f1f5f9; color: #475569; }
.status-sospeso  { background: #f3e8ff; color: #6b21a8; }
.badge-project { background: #f0fdf4; color: #166534; }
.role-admin    { background: #fee2e2; color: #b91c1c; }
.role-ingegnere{ background: #dbeafe; color: #1e40af; }
.role-viewer   { background: #f1f5f9; color: #475569; }

/* ── Tables ─────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th, .data-table td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8fafc; font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.overdue { color: var(--danger); font-weight: bold; }
.th-sort a { display: flex; align-items: center; gap: 4px; color: var(--text-muted); text-decoration: none; white-space: nowrap; }
.th-sort a:hover { color: var(--text); }
.th-sort-active a { color: var(--primary); }
.sort-icon { font-size: 0.75rem; opacity: 0.6; }
.th-sort-active .sort-icon { opacity: 1; }

/* ── Progress bar ───────────────────────────────────────── */
.progress-bar { background: #e5e7eb; border-radius: 99px; height: 8px; overflow: hidden; min-width: 60px; }
.progress-bar-lg { height: 14px; margin-top: 0.4rem; }
.progress-fill { background: var(--primary); height: 100%; transition: width 0.3s; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { display: inline-block; padding: 6px 14px; border-radius: var(--radius); border: 1px solid transparent; font-family: Arial, sans-serif; font-size: 0.875rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn-secondary{ background: #f1f5f9; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e2e8f0; text-decoration: none; }
.btn-success  { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger   { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost    { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: #f1f5f9; text-decoration: none; }
.btn-full { width: 100%; text-align: center; padding: 10px; }
.btn-sm { padding: 3px 8px; font-size: 0.8rem; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0.75rem; }
.form-group label { font-size: 0.85rem; font-weight: bold; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: Arial, sans-serif; font-size: 0.9rem; background: var(--surface);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.card-form { max-width: 800px; }

/* ── Filter bar ─────────────────────────────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; align-items: flex-end; }
.filter-bar input, .filter-bar select { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.875rem; background: var(--surface); min-width: 120px; }

/* ── Task detail ─────────────────────────────────────────── */
.detail-grid { display: grid; gap: 1rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.description { padding: 0.75rem; background: #f8fafc; border-radius: var(--radius); border-left: 3px solid var(--primary); margin-bottom: 1rem; white-space: pre-wrap; }
.progress-section { margin-bottom: 1rem; }
.info-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.info-table th { width: 140px; text-align: left; padding: 6px 0; font-size: 0.85rem; color: var(--text-muted); }
.info-table td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.log-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.log-entry { border-left: 3px solid var(--border); padding: 0.5rem 0.75rem; }
.log-meta { display: flex; justify-content: space-between; margin-bottom: 2px; }
.log-time { font-size: 0.8rem; color: var(--text-muted); }
.log-note { white-space: pre-wrap; }
.log-form { display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 1rem; }
.log-form textarea { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-family: Arial, sans-serif; font-size: 0.9rem; resize: vertical; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-danger   { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning  { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info     { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Login page ──────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: 360px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-sub { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* ── Admin ───────────────────────────────────────────────── */
.admin-grid { display: grid; gap: 1rem; }
.inline-form .form-row { margin-bottom: 0.75rem; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: 1.5rem; }

/* ── Modal ───────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-content { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; width: 420px; max-width: 95vw; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal-content h3 { margin-bottom: 1rem; }

/* ── Error page ──────────────────────────────────────────── */
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 5rem; color: var(--text-muted); }
.error-page p { font-size: 1.2rem; margin: 1rem 0 2rem; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-msg { color: var(--text-muted); font-style: italic; padding: 1rem 0; }

/* ── Calendar ────────────────────────────────────────────── */
.cal-scroll { overflow-x: auto; }
.cal-table { border-collapse: separate; border-spacing: 2px; min-width: 100%; background: #4b5563; box-shadow: var(--shadow); border-radius: var(--radius); }
.cal-table th, .cal-table td { border: none; padding: 0; vertical-align: top; }
.cal-table thead th { background: #f8fafc; text-align: center; padding: 6px 4px; font-size: 0.75rem; color: var(--text-muted); font-weight: bold; white-space: nowrap; }
.cal-week-label { font-size: 0.7rem; color: var(--text-muted); }
.cal-week-dates { font-size: 0.8rem; color: var(--text); }
.cal-user-col { min-width: 140px; width: 140px; position: sticky; left: 0; z-index: 2; background: #f8fafc; }
.cal-week-col { min-width: 220px; width: 220px; }
.cal-nodate-col { min-width: 220px; background: #fafaf0; }
.cal-current-week { background: #eff6ff !important; border-bottom: 3px solid var(--primary) !important; }
.cal-current-col { background: #f0f7ff !important; }
.cal-user-cell { padding: 8px 10px; position: sticky; left: 0; background: #f8fafc; z-index: 1; border-right: 2px solid var(--border); }
.cal-user-name { font-weight: bold; font-size: 0.875rem; margin-bottom: 2px; }
.cal-user-role { font-size: 0.72rem; color: var(--text-muted); }
.cal-cell { padding: 5px 0; min-height: 40px; vertical-align: top; }
.cal-nodate-cell { background: #fafaf0; }
.cal-task { display: flex; align-items: center; gap: 5px; padding: 4px 7px; margin-bottom: 3px; border-radius: 4px; font-size: 0.8rem; text-decoration: none; color: inherit; border-left: 3px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-task:hover { filter: brightness(0.94); text-decoration: none; }
.cal-task-hours { font-size: 0.7rem; color: var(--text-muted); margin-left: 3px; }
/* span styles — margin negativi coprono il border-spacing:2px della tabella */
.cal-task.span-only  { margin: 0 5px 3px; border-radius: 4px; }
.cal-task.span-start { margin: 0 -2px 3px 5px; border-radius: 4px 0 0 4px; border-right: none; padding-right: 4px; }
.cal-task.span-mid   { margin: 0 -2px 3px -2px; border-radius: 0; border-left: none; border-right: none; padding-left: 4px; padding-right: 4px; }
.cal-task.span-end   { margin: 0 5px 3px -2px; border-radius: 0 4px 4px 0; border-left: none; padding-left: 4px; }
/* priority-based colors (calendar) */
.cal-task.cal-p-bassa    { background: #f1f5f9; border-left-color: #64748b; }
.cal-task.cal-p-media    { background: #dbeafe; border-left-color: #1d4ed8; }
.cal-task.cal-p-alta     { background: #fef3c7; border-left-color: #b45309; }
.cal-task.cal-p-critica  { background: #fee2e2; border-left-color: #b91c1c; }
.cal-task-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-dot-aperto   { background: #0ea5e9; }
.status-dot-in_corso { background: #16a34a; }
.status-dot-sospeso  { background: #a855f7; }
.status-dot-chiuso   { background: #94a3b8; }
.cal-legend { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); }
.cal-swatch { display: inline-block; width: 18px; height: 12px; border-radius: 3px; border-left: 3px solid; }
.cal-swatch.cal-p-bassa   { background: #f1f5f9; border-left-color: #64748b; }
.cal-swatch.cal-p-media   { background: #dbeafe; border-left-color: #1d4ed8; }
.cal-swatch.cal-p-alta    { background: #fef3c7; border-left-color: #b45309; }
.cal-swatch.cal-p-critica { background: #fee2e2; border-left-color: #b91c1c; }
.cal-task[draggable="true"] { cursor: grab; }
.cal-task.dragging { opacity: 0.4; }
.cal-cell.drop-target { background: #bfdbfe !important; outline: 2px dashed var(--primary); }
.cal-cestino.drop-target { background: #fee2e2 !important; border-color: #ef4444; outline: 2px dashed #ef4444; }
/* time form */
.time-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.time-form input { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.875rem; }
.hours-ratio { font-size: 0.85rem; color: var(--text-muted); }
.hours-over { color: var(--danger); font-weight: bold; }

/* ── Cestino task non assegnati ──────────────────────────── */
.cal-cestino { margin-top: 2rem; border: 2px dashed var(--border); border-radius: var(--radius); padding: 1rem; background: #fafaf0; }
.cal-cestino-title { font-size: 0.85rem; font-weight: bold; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.75rem; }
.cestino-tasks { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ── Calendario ingegnere 3 colonne ─────────────────────── */
.cal-table-inge { min-width: unset; width: 100%; }
.cal-table-inge thead th { text-align: left; padding: 8px 12px; }
.inge-col-week  { width: 160px; }
.inge-col-tasks { }
.inge-col-ore   { width: 150px; }
.inge-week-cell { padding: 10px 12px; vertical-align: top; background: #f8fafc; border-right: 2px solid var(--border); white-space: nowrap; }
.inge-week-range { font-size: 0.85rem; font-weight: bold; color: var(--text); }
.inge-week-year  { font-size: 0.72rem; color: var(--text-muted); }
.cal-week-now    { font-size: 0.72rem; color: var(--primary); font-weight: bold; margin-top: 3px; }
.inge-task-cell  { padding: 4px 8px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.inge-ore-cell   { padding: 4px 10px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.inge-week-last td { border-bottom: 2px solid var(--border) !important; }
.cal-current-row td { background: #f0f7ff !important; }
.ore-form { display: flex; align-items: center; gap: 4px; }
.ore-input { width: 58px; padding: 4px 6px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem; text-align: center; }
.btn-ore-save { background: var(--primary); color: #fff; border: none; border-radius: var(--radius); padding: 4px 8px; font-size: 0.8rem; cursor: pointer; }
.btn-ore-save:hover { background: var(--primary-hover); }
.ore-msg { font-size: 0.8rem; min-width: 16px; }
.inge-new-task-cell { padding: 5px 8px !important; }
.btn-new-task-inline { display: inline-block; font-size: 0.78rem; color: var(--primary); border: 1px dashed var(--primary); border-radius: var(--radius); padding: 2px 10px; text-decoration: none; opacity: 0.7; }
.btn-new-task-inline:hover { opacity: 1; background: #eff6ff; }

/* ── Grafici ─────────────────────────────────────────────── */
.chart-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; }
.chart-label { min-width: 120px; font-size: 0.85rem; color: var(--text-muted); text-align: right; }
.chart-bar-outer { flex: 1; background: #f1f5f9; border-radius: 4px; height: 24px; overflow: visible; position: relative; }
.chart-bar-fill { height: 100%; border-radius: 4px; display: flex; align-items: center; min-width: 4px; transition: width 0.4s; }
.chart-bar-val { color: #fff; font-size: 0.8rem; font-weight: bold; padding-left: 6px; }
.chart-bar-val-out { font-size: 0.8rem; font-weight: bold; color: var(--text); margin-left: 4px; }
.chart-pct { min-width: 42px; font-size: 0.8rem; color: var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .navbar { flex-wrap: wrap; height: auto; padding: 0.5rem 1rem; gap: 0.5rem; }
  .nav-links { flex-wrap: wrap; gap: 0.5rem; }
  .page-header { flex-direction: column; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 0.4rem 0.5rem; }
  .filter-bar { flex-direction: column; }
  .filter-bar input, .filter-bar select { width: 100%; }
}
