:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e2e2e6;
  --text: #1c1c1f;
  --text-muted: #6b6b74;
  --accent: #4f46e5;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --done-bg: #f0f0f2;
  --overdue: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1f1f24;
    --border: #303038;
    --text: #ececef;
    --text-muted: #9a9aa2;
    --accent: #818cf8;
    --accent-contrast: #16161a;
    --danger: #f87171;
    --done-bg: #26262c;
    --overdue: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.main-nav {
  display: flex;
  gap: 4px;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 0;
}

.main-nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
}

.main-nav a:hover {
  background: var(--done-bg);
}

.main-nav a.active {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

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

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 22px;
  margin: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar input[type="text"] {
  flex: 1 1 180px;
}

#category-filter,
#client-filter {
  flex: 0 1 160px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}

input[type="text"],
input[type="datetime-local"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.btn-icon {
  background: transparent;
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 15px;
}

.btn-icon:hover {
  background: var(--done-bg);
  color: var(--text);
}

.btn-icon.danger:hover {
  color: var(--danger);
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.task-item.done {
  background: var(--done-bg);
}

.task-checkbox {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-weight: 600;
  word-break: break-word;
}

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

.task-description {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.task-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 12px;
}

.badge {
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--done-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge.due-date.overdue {
  color: var(--overdue);
  border-color: currentColor;
}

.badge-client {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border-color: transparent;
  font-weight: 500;
}

.task-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 48px;
  font-size: 14px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.legend .status-dot {
  margin-left: 10px;
}

.legend .status-dot:first-child {
  margin-left: 0;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.verde {
  background: #22c55e;
}

.status-dot.arancione {
  background: #f59e0b;
}

.status-dot.rosso {
  background: #ef4444;
}

.client-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.client-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.client-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
}

.client-link:hover {
  background: var(--done-bg);
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}

.back-link:hover {
  color: var(--text);
}

.section-title {
  font-size: 15px;
  color: var(--text-muted);
  margin: 24px 0 10px;
}

.client-notes {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(480px, 92vw);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
}

.dialog-form h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.form-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

@media (max-width: 480px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    flex-direction: column;
  }

  #category-filter,
  #client-filter {
    flex: 1 1 auto;
  }
}
