:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232736;
  --border: #2e3344;
  --text: #e8eaf2;
  --text-dim: #9aa0b4;
  --primary: #4f46e5;
  --primary-hover: #6366f1;
  --danger: #dc2626;       /* fundo de botão destrutivo: 4.83:1 com texto branco */
  --danger-text: #f87171;  /* texto de erro: ≥6:1 sobre as superfícies escuras */
  --success: #22c55e;
  --focus: #818cf8;        /* anel de foco: ≥3:1 sobre bg e surface */
  --border-input: #566180; /* limite de campo: ≥3:1 sobre as superfícies (WCAG 1.4.11) */
  --radius: 14px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.view {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh; /* fallback para navegadores sem dvh */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 16px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 16px)
    calc(env(safe-area-inset-left) + 16px);
}

/* ===== Home ===== */
.app-header { text-align: center; margin: 8px 0 24px; }
.app-header h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: 6px 0 0; color: var(--text-dim); font-size: 0.85rem; }

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

.workspace-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.workspace-card:active { background: var(--surface-2); }
.workspace-card .ws-icon { font-size: 1.4rem; }
.workspace-card .ws-info { flex: 1; min-width: 0; }
.workspace-card .ws-name {
  display: block; /* ellipsis e overflow não funcionam em inline */
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-card .ws-meta {
  display: block;
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-top: 2px;
}

.home-actions {
  margin-top: auto;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  margin: 40px 0;
  line-height: 1.6;
}

/* ===== Botões ===== */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); }
.btn-ghost:active { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:active { filter: brightness(1.15); }
.btn-round {
  border-radius: 50%;
  width: 52px;
  height: 52px;
  padding: 0;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.05rem;
  width: 42px;
  height: 42px;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }

.mini-btn {
  background: none;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 6px;
  color: var(--text-dim);
}

/* ===== Workspace ===== */
/* Altura fixa na viewport: só .task-area rola; cabeçalho, abas e o
   formulário de nova tarefa ficam sempre visíveis. */
#view-workspace { height: 100vh; height: 100dvh; }

.ws-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-shrink: 0;
}
.ws-title {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 0;
}
.list-tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.tab-add { color: var(--text); }

.task-area { flex: 1; overflow-y: auto; min-height: 0; }

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 6px 0 10px;
}
.list-name {
  flex: 1;
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.task-item .task-check {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  accent-color: var(--success);
  cursor: pointer;
}
.task-item .task-text {
  flex: 1;
  font-size: 0.98rem;
  word-break: break-word;
  cursor: pointer;
}
.task-item.done .task-text {
  text-decoration: line-through;
  color: var(--text-dim);
}
.task-item .task-del {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

.task-form {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 14px;
  flex-shrink: 0;
}
.task-form input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  color: var(--text);
  padding: 14px 16px;
  font-size: 1rem;
  min-width: 0;
}
.task-form input:focus { outline: 2px solid var(--focus); border-color: transparent; }

/* ===== Modais ===== */
.modal {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: min(92vw, 380px);
  margin: auto;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.65); }
.modal h3 { margin: 0 0 16px; }
.modal label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.modal input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
}
.modal input:focus { outline: 2px solid var(--focus); border-color: transparent; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.modal-actions .btn { padding: 11px 16px; font-size: 0.92rem; }

.confirm-message { color: var(--text-dim); font-size: 0.92rem; line-height: 1.5; margin: 0; }

.warn { font-size: 0.78rem; color: #fbbf24; margin: 4px 0; }
.error { font-size: 0.85rem; color: var(--danger-text); margin: 8px 0 0; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  max-width: 90vw;
  /* sempre no DOM (live region); visibilidade via opacidade para o anúncio funcionar */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
