:root {
  --bg: #121212;
  --bg-sidebar: #1a1a1a;
  --bg-main: #171717;
  --bg-hover: #242424;
  --bg-active: #2c2c2c;
  --border: #2e2e2e;
  --text: #e8e8e8;
  --text-dim: #9a9a9a;
  --text-faint: #6a6a6a;
  --accent: #dc4c3e;
  --accent-hover: #e05a4c;
  --green: #95ef63;
  --red: #ff6b6b;
  --radius: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
button:focus { outline: 1px solid var(--accent); }

.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-active); }
.btn-danger { background: #3a1d1d; color: var(--red); border: 1px solid #5a2a2a; }
.btn-danger:hover { background: #4a2525; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* ---------- Layout ---------- */
#app { display: flex; height: 100vh; }
#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: width 0.2s ease;
}
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-main);
}

/* ---------- Sidebar ---------- */
.sidebar-header { padding: 16px 16px 8px; }
.logo-row { display: flex; align-items: center; gap: 10px; }
.app-title { font-size: 18px; font-weight: 700; }
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text); }
#sidebar-toggle-mobile { display: none; }
.sidebar-nav { padding: 8px 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-active); color: var(--text); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }
.nav-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-faint);
  background: var(--bg-hover);
  border-radius: 10px;
  padding: 1px 8px;
}
.nav-item.active .nav-count { background: var(--bg-active); }

.sidebar-section { padding: 8px 8px; }
.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 6px 10px 4px;
}
.sidebar-project, .sidebar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  position: relative;
}
.sidebar-project:hover, .sidebar-label:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-project.active, .sidebar-label.active { background: var(--bg-active); color: var(--text); }
.proj-dot, .label-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.proj-name, .label-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-count, .label-count { font-size: 12px; color: var(--text-faint); }
.proj-files-btn {
  background: none; border: none;
  color: var(--text-faint);
  padding: 2px;
  display: flex;
  border-radius: 4px;
  opacity: 0.8;
  transition: opacity 0.1s;
}
.sidebar-project:hover .proj-files-btn { opacity: 1; }
.proj-files-btn:hover { color: var(--text); background: var(--bg-active); }

.sidebar-add-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-top: 2px;
}
.sidebar-add-btn:hover { background: var(--bg-hover); color: var(--text); }

.sidebar-footer { margin-top: auto; padding: 8px; border-top: 1px solid var(--border); }
.sidebar-footer-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  background: none; border: none;
  color: var(--text-faint);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
}
.sidebar-footer-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- Sidebar collassata ---------- */
#app.sidebar-collapsed #sidebar { width: 56px; }
#app.sidebar-collapsed .sidebar-header { padding: 16px 8px 8px; }
#app.sidebar-collapsed .logo-row { justify-content: center; gap: 0; }
#app.sidebar-collapsed .app-title { display: none; }
#app.sidebar-collapsed .sidebar-nav { padding: 8px 6px; }
#app.sidebar-collapsed .nav-item { justify-content: center; padding: 8px 0; gap: 0; }
#app.sidebar-collapsed .nav-item span { display: none; }
#app.sidebar-collapsed .nav-count { display: none; }
#app.sidebar-collapsed .sidebar-section { padding: 8px 6px; }
#app.sidebar-collapsed .sidebar-section-title { display: none; }
#app.sidebar-collapsed .sidebar-project,
#app.sidebar-collapsed .sidebar-label { justify-content: center; padding: 8px 0; gap: 0; }
#app.sidebar-collapsed .proj-name,
#app.sidebar-collapsed .label-name { display: none; }
#app.sidebar-collapsed .proj-count,
#app.sidebar-collapsed .label-count { display: none; }
#app.sidebar-collapsed .proj-files-btn { display: none; }
#app.sidebar-collapsed .sidebar-add-btn { justify-content: center; padding: 8px 0; }
#app.sidebar-collapsed .sidebar-add-btn span { display: none; }
#app.sidebar-collapsed .sidebar-footer-btn { justify-content: center; padding: 8px 0; }
#app.sidebar-collapsed .sidebar-footer-btn span { display: none; }

/* ---------- Topbar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 8px;
  border-bottom: 1px solid var(--border);
}
#view-title { font-size: 20px; font-weight: 700; }
.add-section-btn { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; padding: 3px 10px; font-size: 12px; }
.search-input { width: 240px; }
#filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
#filter-bar select {
  width: auto;
  min-width: 130px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg-hover);
}
#filter-bar select:hover { border-color: var(--accent); }
#filter-bar .btn { flex-shrink: 0; }

/* ---------- Content ---------- */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 40px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.quick-add-row { margin-bottom: 16px; }
.quick-add {
  display: flex;
  align-items: center;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 10px;
  transition: border-color 0.15s;
}
.quick-add:focus-within { border-color: var(--accent); }
.quick-add-btn {
  background: none; border: none;
  color: var(--accent);
  padding: 4px;
  display: flex;
  border-radius: 4px;
}
.quick-add-btn:hover { background: var(--bg-active); }
#quick-add-input { background: transparent; border: none; padding: 8px 6px; }
#quick-add-input:focus { border: none; outline: none; }

/* ---------- Tasks ---------- */
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}
.task-row:hover { background: var(--bg-hover); }
.task-row.dragging { opacity: 0.4; }
.task-row.drag-over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.task-row.completed .task-content { text-decoration: line-through; color: var(--text-faint); }
.task-row.high-prio .task-content { color: #fff; font-weight: 500; }

.task-check {
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.task-check:hover .check-icon circle { stroke: var(--accent); }
.check-icon { display: block; }
.check-icon.filled circle { fill: var(--accent); stroke: var(--accent); }

.task-body { flex: 1; min-width: 0; }
.task-content { word-wrap: break-word; overflow-wrap: anywhere; }
.task-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.prio-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
}
.prio-badge.p1 { background: #dc4c3e33; color: #ff8a80; }
.prio-badge.p2 { background: #ff9d0033; color: #ffcc80; }
.prio-badge.p3 { background: #039be533; color: #81d4fa; }
.prio-badge.p4 { background: #6a6a6a33; color: #bdbdbd; }
.due-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.due-badge.overdue { color: var(--red); }
.recur-badge { color: var(--green); font-size: 13px; }
.file-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-dim);
}
.tag-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--tag-color, #95ef63) 25%, transparent);
  color: var(--tag-color, #95ef63);
}
.sub-toggle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
}
.sub-toggle:hover { color: var(--text); background: var(--bg-active); }
.subtasks { margin-left: 28px; }

.task-add-sub {
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 2px;
  border-radius: 4px;
  display: flex;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
}
.task-row:hover .task-add-sub { opacity: 1; }
.task-add-sub:hover { color: var(--text); background: var(--bg-active); opacity: 1; }
#task-add-sub-btn { margin-right: auto; }
.task-parent-hint {
  font-size: 12px;
  color: var(--accent);
  background: #dc4c3e1a;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 12px;
}

/* Data e ora: naturale + picker */
.due-pickers { display: flex; gap: 8px; }
.due-pickers input[type="text"] { flex: 1; min-width: 0; }
.due-pickers input[type="date"],
.due-pickers input[type="time"] { width: auto; flex-shrink: 0; color-scheme: dark; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 6px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
.section-name { font-size: 13px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.section-header-clickable { cursor: pointer; user-select: none; }
.section-header-clickable:hover .section-name { color: var(--text); }
.section-title-group { display: flex; align-items: center; min-width: 0; }
.section-title-group .section-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-caret { color: var(--text-faint); font-size: 11px; margin-right: 6px; width: 12px; text-align: center; }
.section-count {
  margin-left: 8px;
  background: var(--bg-active);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}
.section-count.zero { opacity: 0; pointer-events: none; }
.section-add {
  background: none; border: none;
  color: var(--text-faint);
  display: flex;
  padding: 2px;
  border-radius: 4px;
}
.section-add:hover { color: var(--text); background: var(--bg-active); }

/* ---------- Empty state ---------- */
#empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 0;
}
.empty-icon { margin-bottom: 12px; color: var(--text-faint); opacity: 0.5; }

/* ---------- Modali ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none;
  color: var(--text-dim);
  display: flex;
  padding: 4px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--bg-active); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
textarea { resize: vertical; }

/* ---------- Responsive: mobile ---------- */
@media (max-width: 768px) {
  /* Sidebar = drawer */
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px !important;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  #app.sidebar-collapsed #sidebar { transform: translateX(-100%); }
  #app:not(.sidebar-collapsed) #sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  #app:not(.sidebar-collapsed)::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 150;
  }
  #sidebar-toggle-mobile { display: flex; flex-shrink: 0; }

  /* Topbar */
  #topbar { flex-wrap: wrap; padding: 10px 12px 0; gap: 8px 10px; }
  #view-title { font-size: 18px; flex-shrink: 0; }
  .topbar-actions { order: 10; flex: 1 1 100%; min-width: 0; }
  .search-input { width: 100%; flex: none; padding: 8px 12px; }

  /* Filtri: riga scrollabile orizzontalmente */
  #filter-bar {
    order: 20;
    flex-basis: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 8px 4px 12px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #filter-bar::-webkit-scrollbar { display: none; }
  #filter-bar select { min-width: 100px; flex-shrink: 0; padding: 7px 8px; }
  #filter-bar .btn { flex-shrink: 0; }
  #filter-bar.fade-right {
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 26px), transparent);
    mask-image: linear-gradient(to right, black calc(100% - 26px), transparent);
  }
  #filter-bar.fade-right.at-end { -webkit-mask-image: none; mask-image: none; }

  /* Contenuto */
  #content { padding: 12px 14px 40px; max-width: none; }
  .quick-add-row { margin-bottom: 8px; }
  .quick-add { min-height: 44px; }
  .task-row { padding: 10px 8px; }
  .task-add-sub { opacity: 1; }
  .task-check svg { width: 20px; height: 20px; }
  .section-header { padding: 12px 8px 6px; }
  .form-row { flex-direction: column; gap: 0; }
  .due-pickers { flex-direction: column; }
}

/* color picker */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: white; box-shadow: 0 0 0 2px var(--bg-main), 0 0 0 4px white; }

/* labels in modal */
.label-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  margin: 0 6px 6px 0;
  background: var(--bg-hover);
  transition: background 0.1s;
}
.label-check:hover { background: var(--bg-active); }
.label-check input { width: auto; margin: 0; }
.label-check .label-dot { width: 8px; height: 8px; }

/* files */
.files-list { margin-top: 14px; }
#project-files-panel {
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
}
.project-files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.project-files-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-dim);
}
.project-files-upload {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.project-files-upload input[type="file"] {
  max-width: 260px;
  padding: 6px;
  font-size: 13px;
}
.task-files-upload {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.task-files-upload input[type="file"] {
  flex: 1;
  padding: 6px;
  font-size: 13px;
}
.task-files-upload .btn { flex-shrink: 0; }
.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg-hover);
}
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-meta { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.file-actions { display: flex; gap: 6px; }
.files-empty { color: var(--text-faint); text-align: center; padding: 20px 0; }

/* scrollbar */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* responsive */
/* (vecchia media query sostituita il 05/08/2026 dalla sezione "Responsive: mobile" sopra) */
