:root {
  --bg: #0a0a0a;
  --card: #141414;
  --card-active: #1c1c1c;
  --border: #262626;
  --text: #eaeaea;
  --muted: #8a8f98;
  --accent: #579bfc;
  --chip-bg: #1c1c1c;
  --danger: #df2f4a;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --card-active: #eef1f6;
    --border: #e2e5eb;
    --text: #14161a;
    --muted: #666e7a;
    --chip-bg: #eef1f6;
  }
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.view { min-height: 100vh; }

/* Login */
.login-card {
  max-width: 320px;
  margin: 20vh auto 0;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-card h1 { margin: 0; }
.subtitle { color: var(--muted); margin: 0 0 8px; }
.login-card input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  font-size: 16px;
}
.login-card button {
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
}
.error { color: var(--danger); font-size: 14px; }

/* App */
.app-header {
  padding: 16px 16px 4px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 { font-size: 20px; margin: 0; }
.app-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 2px 0 0;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

/* Category filter (Work / Personal / All) */
.category-filter {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
}
.category-btn {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.category-btn.active {
  background: var(--chip-bg);
  color: var(--text);
  border-color: var(--accent);
}

/* Status cards (tabs) */
.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px 8px;
  overflow-x: auto;
}
.tab-card {
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--tab-accent, var(--border));
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab-card.active {
  background: var(--card-active);
  box-shadow: inset 0 0 0 1px var(--tab-accent, var(--border));
}
.tab-card .count {
  font-size: 13px;
  font-weight: 700;
  color: var(--tab-accent, var(--muted));
  background: var(--chip-bg);
  padding: 2px 8px;
  border-radius: 999px;
}

.theme-filter-row {
  padding: 0 16px 12px;
}
.theme-filter {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--theme-filter-color, var(--text));
  font-size: 14px;
  font-weight: 600;
}

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 10px;
  border-bottom: 2px solid var(--tab-accent, var(--border));
  margin: 0 16px 12px;
}
.section-header .title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
}
.section-header .count-badge {
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
}

.task-list {
  padding: 0 16px 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.task-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.drag-handle {
  color: var(--muted);
  font-size: 14px;
  flex: 0 0 auto;
  cursor: grab;
  user-select: none;
}
.task-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}
.task-name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}
.task-name.done {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 400;
}
.task-edit-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  letter-spacing: 1px;
}
.task-delete-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  flex: 0 0 auto;
}
.task-delete-x:hover {
  color: var(--danger);
}
.task-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  margin-left: 46px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.task-meta .theme-label {
  font-weight: 600;
}
.task-id-badge {
  font-weight: 700;
  color: var(--muted);
  opacity: 0.7;
}
.task-edit-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  margin-left: 46px;
}
.task-edit-panel select,
.task-edit-panel input[type="text"] {
  flex: 1;
  min-width: 120px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
}
.task-edit-panel .task-name-input {
  flex-basis: 100%;
  min-height: 56px;
  resize: none;
  font-size: 16px;
  line-height: 1.4;
  font-family: inherit;
  overflow: hidden;
}
.task-edit-panel .link-btn {
  flex-basis: 100%;
  text-align: left;
  margin: -4px 0 0;
}
.task-edit-panel .delete-btn {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

.ghost-add-btn {
  width: 100%;
  padding: 14px;
  margin-top: 4px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.ghost-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 28px;
  line-height: 56px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
}

/* Undo toast */
.undo-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 20px;
  max-width: 480px;
  margin: 0 auto;
  background: var(--card-active);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.undo-toast span { font-size: 14px; }
.undo-toast button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.dialog {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dialog h2 { margin: 0; }
.dialog input, .dialog select {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  font-size: 15px;
}
.dialog label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.dialog-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
}
#add-cancel { background: var(--chip-bg); color: var(--text); }
#add-form button[type="submit"] { background: var(--accent); color: white; }

.connection-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 15px;
}
.connection-row button {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
  align-self: center;
}
.link-btn:hover {
  color: var(--accent);
}
