/* ===== RESET & ROOT ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0f;
  --bg2: #141417;
  --bg3: #1c1c21;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  --text: #e8e8ee;
  --text-muted: #6b6b7a;
  --text-dim: #9898aa;

  --green: #2ecc71;
  --green-bg: rgba(46,204,113,0.1);
  --yellow: #f1c40f;
  --yellow-bg: rgba(241,196,15,0.1);
  --red: #e74c3c;
  --red-bg: rgba(231,76,60,0.1);
  --orange: #e67e22;
  --orange-bg: rgba(230,126,34,0.1);
  --blue: #3498db;
  --blue-bg: rgba(52,152,219,0.1);
  --pink: #e91e8c;
  --pink-bg: rgba(233,30,140,0.08);

  --radius: 10px;
  --font-main: 'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== BACKGROUND GRID ===== */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13,13,15,0.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  gap: 20px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-yl {
  background: linear-gradient(135deg, var(--pink), #ff6b9d);
  color: white;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 18px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -1px;
  box-shadow: 0 4px 20px rgba(233,30,140,0.3);
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  min-width: 60px;
}

.stat:hover {
  border-color: var(--pink);
  background: var(--pink-bg);
}

.stat-num {
  font-size: 20px;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
}

.stat-num.green { color: var(--green); }
.stat-num.yellow { color: var(--yellow); }
.stat-num.red { color: var(--red); }
.stat-num.orange { color: var(--orange); }
.stat-num.blue { color: var(--blue); }

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 3px;
  background: rgba(255,255,255,0.05);
  width: 100%;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--pink), #ff6b9d);
  transition: width 0.5s ease;
  box-shadow: 0 0 8px rgba(233,30,140,0.4);
}

/* ===== TOOLBAR ===== */
.toolbar {
  position: sticky;
  top: 93px;
  z-index: 99;
  background: rgba(13,13,15,0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
}

.filter-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.filter-btn.active {
  background: var(--pink);
  border-color: var(--pink);
  color: white;
}

.section-filter select,
.search-wrap input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.section-filter select:focus,
.search-wrap input:focus {
  border-color: var(--pink);
}

.search-wrap input {
  width: 220px;
}

.search-wrap input::placeholder { color: var(--text-muted); }

/* ===== MAIN TASK LIST ===== */
main {
  position: relative;
  z-index: 1;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 1100px;
  margin: 0 auto;
}

/* ===== SECTION HEADER ===== */
.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 0 8px;
}

.section-divider-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.section-divider-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== TASK CARD ===== */
.task-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 36px 1fr auto auto auto;
  align-items: center;
  gap: 14px;
  transition: all 0.15s;
  cursor: default;
}

.task-card:hover {
  border-color: var(--border-hover);
  background: var(--bg3);
}

.task-card.has-note {
  border-left: 3px solid var(--pink);
}

.task-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
}

.task-desc {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
}

.task-desc.done {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* ===== STATUS SELECT ===== */
.status-select {
  appearance: none;
  border: none;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 12px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.status-select.da_fare {
  background: var(--red-bg);
  color: var(--red);
}

.status-select.in_corso {
  background: var(--yellow-bg);
  color: var(--yellow);
}

.status-select.fatto {
  background: var(--green-bg);
  color: var(--green);
}

.status-select.bloccato {
  background: var(--orange-bg);
  color: var(--orange);
}

.status-select.programmazione {
  background: var(--blue-bg);
  color: var(--blue);
}

/* ===== NOTE BUTTON ===== */
.note-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.note-btn:hover {
  border-color: var(--pink);
  color: var(--pink);
  background: var(--pink-bg);
}

.note-btn.has-note {
  color: var(--pink);
  border-color: rgba(233,30,140,0.3);
  background: var(--pink-bg);
}

/* ===== UPDATED TIMESTAMP ===== */
.task-updated {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== INLINE NOTE PREVIEW ===== */
.note-snippet {
  grid-column: 2 / -1;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  padding: 8px 12px;
  border-left: 2px solid rgba(233,30,140,0.3);
  line-height: 1.5;
  margin-top: -4px;
}

.note-snippet p { margin: 0; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border-hover);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  transform: translateY(10px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-task-id {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--pink);
  font-weight: 500;
  flex-shrink: 0;
  padding-top: 2px;
}

.modal-task-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close:hover { color: var(--text); background: var(--bg3); }

.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px 10px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--pink); border-bottom-color: var(--pink); }

.modal-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#note-editor {
  flex: 1;
  background: var(--bg3);
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  padding: 20px 24px;
  resize: none;
  outline: none;
  min-height: 280px;
}

.note-preview {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  min-height: 280px;
  font-size: 14px;
  line-height: 1.7;
}

.note-preview.hidden { display: none; }
#note-editor.hidden { display: none; }

.note-preview h1,h2,h3 { margin: 0.5em 0; font-family: var(--font-main); }
.note-preview h1 { font-size: 18px; color: var(--pink); }
.note-preview h2 { font-size: 16px; }
.note-preview h3 { font-size: 14px; color: var(--text-dim); }
.note-preview p { margin: 0.4em 0; }
.note-preview code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--pink);
}
.note-preview pre {
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
}
.note-preview pre code { background: none; padding: 0; color: var(--text); }
.note-preview blockquote {
  border-left: 3px solid var(--pink);
  padding-left: 12px;
  color: var(--text-dim);
  margin: 0.5em 0;
}
.note-preview a { color: var(--pink); }
.note-preview ul, .note-preview ol {
  padding-left: 20px;
}
.note-preview li { margin: 0.2em 0; }
.note-preview strong { color: var(--text); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}

.modal-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.btn-cancel, .btn-save {
  padding: 8px 20px;
  border-radius: 8px;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-cancel:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.btn-save {
  background: var(--pink);
  border: 1px solid var(--pink);
  color: white;
  box-shadow: 0 4px 14px rgba(233,30,140,0.3);
}

.btn-save:hover {
  background: #d41880;
  box-shadow: 0 4px 20px rgba(233,30,140,0.5);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 14px;
}

/* ===== LOADING BAR ===== */
.loading-bar {
  height: 2px;
  background: linear-gradient(90deg, var(--pink), #ff6b9d, var(--pink));
  background-size: 200% 100%;
  animation: loading-anim 1.2s linear infinite;
  opacity: 0;
  transition: opacity 0.2s;
}

@keyframes loading-anim {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== SAVE STATUS ===== */
.save-status {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  transition: all 0.3s;
}

.save-status.ok {
  color: var(--green);
  background: var(--green-bg);
}

.save-status.warn {
  color: var(--orange);
  background: var(--orange-bg);
}

/* ===== MIGRATION BANNER ===== */
.migration-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: var(--bg2);
  border: 1px solid var(--pink);
  border-radius: 14px;
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(233,30,140,0.2);
  font-size: 13px;
  max-width: 600px;
  width: calc(100% - 40px);
  flex-wrap: wrap;
}

.migration-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ===== NEW TASK BUTTON ===== */
.btn-new-task {
  margin-left: auto;
  padding: 7px 18px;
  background: var(--pink);
  border: 1px solid var(--pink);
  border-radius: 20px;
  color: white;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  box-shadow: 0 3px 12px rgba(233,30,140,0.25);
}

.btn-new-task:hover {
  background: #d41880;
  box-shadow: 0 4px 18px rgba(233,30,140,0.45);
}

/* ===== FORM FIELDS ===== */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.field-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-row {
  display: flex;
  gap: 14px;
}

#new-task-desc {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 14px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

#new-task-desc:focus {
  border-color: var(--pink);
}

#new-task-sezione,
#new-task-stato {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  cursor: pointer;
}

#new-task-sezione:focus,
#new-task-stato:focus {
  border-color: var(--pink);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  .header-inner { padding: 14px 16px; }
  .toolbar { padding: 10px 16px; }
  main { padding: 16px; }
  .task-card {
    grid-template-columns: 28px 1fr;
    grid-template-rows: auto auto auto;
  }
  .status-select { grid-column: 2; }
  .note-btn { grid-column: 1; grid-row: 3; }
  .task-updated { display: none; }
  .search-wrap input { width: 140px; }
}
