/* Theme Tokens */
:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #cbd5e1; /* slightly darker than --border for buttons */
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06);
  --text: #111827;
  --muted: #6b7280;
  --link: #2563eb;
  --code-bg: #f2f2f2;
  --danger-border: #c66;
  --danger-bg: #fee;
  --danger-bg-hover: #fdd;
}

/* Base Reset */
html, body {
  padding: 0;
  margin: 0;
}

body {
  font-family: 'SF Pro Text', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.container {
  max-width: 1120px;
  margin: 2rem auto;
  padding: 0 1rem;
}

h1 {
  margin-bottom: 0.25rem;
  font-size: 1.75rem;
}

.page-header { margin: 0 0 0.75rem; }
.tab-nav {
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
}
.tab-link {
  text-decoration: none;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 600;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, font-size 0.15s ease, border-color 0.15s ease;
}
.tab-link:hover { color: var(--text); }
.tab-link.active {
  color: var(--text);
  font-size: 1.75rem;
  font-weight: 700;
  border-color: var(--border-strong);
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.checklist-item {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}
.checklist input[type="checkbox"] {
  appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: #fff;
  position: relative;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.checklist input[type="checkbox"]:focus-visible {
  outline: 2px solid #cbd5e1;
  outline-offset: 2px;
}
.checklist input[type="checkbox"]:checked {
  background: #fff;
  border-color: #2563eb;
}
.checklist input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  height: 70%;
  transform: translate(-50%, -50%);
  border-radius: 3px;
  background: #2563eb;
}
.checklist-add .checklist-item { color: var(--muted); }
.checklist-add .checklist-item .checklist-note { cursor: pointer; }
.checklist-add input[type="checkbox"] { border-color: var(--border); }
.todo-add-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 40%;
  margin-top: 0.4rem;
}
.todo-add-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.todo-add-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-start;
}
.checklist-text { display: flex; flex-direction: column; gap: 0.15rem; }
.checklist-title { font-weight: 600; margin-top: 0.1rem; }
.todo-add-label { font-style: italic; }
.checklist-note { font-size: 0.95rem; }
.checklist li.done .checklist-title,
.checklist li.done .checklist-note,
.checklist li.done .checklist-meta { color: var(--muted); }
.checklist li.done { opacity: 0.8; }
.todo-item.editing .checklist-item { display: none; }
.checklist-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.1rem;
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.9rem;
  background: #eef2ff;
  color: #111827;
  border: 1px solid #e5e7eb;
}
.pill.due { background: #ecfeff; border-color: #bae6fd; color: #0f172a; }
.pill.due.due-over { background: #fef2f2; border-color: #fecdd3; color: #7f1d1d; }
.pill.people { background: #f8fafc; border-color: #e2e8f0; }
.pill.priority { font-weight: 600; }
.pill.priority-low { background: #ecfdf3; border-color: #bbf7d0; color: #0f5132; }
.pill.priority-medium { background: #eef2ff; border-color: #c7d2fe; color: #312e81; }
.pill.priority-high { background: #fff7ed; border-color: #fed7aa; color: #7c2d12; }
.pill.priority-urgent { background: #fef2f2; border-color: #fecdd3; color: #7f1d1d; }

/* Typography */
.muted {
  color: var(--muted);
}

/* Placeholder text for empty editable cells */
.placeholder {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9em;
}

code {
  background: var(--code-bg);
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
}

/* Components */

.card, section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}

.actions { margin-top: 0.75rem; }
.title-row { display: flex; align-items: center; gap: 0.2rem; }
.btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border-strong);
  background: linear-gradient(#ffffff, #f7f9fb);
  border-radius: 6px;
  cursor: pointer;
  margin-right: 0.5rem;
}
.btn:hover { background: #f1f5f9; }

/* Shared icon button behavior */
.btn-icon, .btn-icon-sm {
  /* Always visible but muted by default */
  opacity: 0.55;
  pointer-events: auto;
  transition: opacity 0.15s ease-in-out, color 0.15s ease-in-out, background 0.15s ease-in-out;
  margin-left: 0.15rem;
  /* Common button box */
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface);
  line-height: 0;
  color: var(--muted);
}

/* Icon buttons should be borderless even if combined with .btn */
.btn.btn-icon, .btn.btn-icon-sm { border: 0; }

.btn-icon { width: 1.6rem; height: 1.6rem; }
.btn-icon .icon { width: 1.15rem; height: 1.15rem; }
.btn-icon .icon, .btn-icon-sm .icon { display: block; }
.btn-icon:hover, .btn-icon-sm:hover { background: #f8fafc; }
/* Unmute icon on direct hover/focus */
.btn-icon:hover, .btn-icon:focus,
.btn-icon-sm:hover, .btn-icon-sm:focus {
  opacity: 1;
  color: var(--text);
  pointer-events: auto;
}
.btn-danger { border-color: var(--danger-border); background: var(--danger-bg); }
.btn-danger:hover { background: var(--danger-bg-hover); }

.list { padding-left: 1.25rem; margin: 0.5rem 0 0 0; }
.list a { text-decoration: none; color: var(--link); }
.list a:hover { text-decoration: underline; }
.btn-icon-sm { width: 1.3rem; height: 1.3rem; }
.btn-icon-sm .icon { width: 0.85rem; height: 0.85rem; }

.project-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: linear-gradient(180deg, #fdfdfd, #f8fafc);
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
}

.project-card:visited {
  color: var(--text);
}

.project-card:hover,
.project-card:focus-visible {
  border-color: #9ca3af;
  background: #f1f5f9;
}

.project-card .edit-btn {
  margin-left: auto;
}

.project-name { font-weight: 600; }

.project-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.project-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.project-card-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.project-editor {
  border-top: 1px dashed var(--border);
  padding-top: 0.65rem;
}

.project-editor-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.project-editor-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 0.75rem;
  align-items: start;
}

.project-editor-label {
  color: var(--muted);
  font-size: 0.9rem;
  padding-top: 0.35rem;
}

.tag-editor {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-pill, .filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #e5e7eb;
  color: #111827;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.9rem;
}
.tag-pill { padding: 0.2rem 0.6rem; }
.tag-pill.tag-pill-small {
  padding: 0.12rem 0.5rem;
  font-size: 0.85rem;
}
.filter-chip { padding: 0.15rem 0.55rem; }

.tag-remove,
.filter-chip button {
  border: none;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  padding: 0 0.15rem;
  font-size: 0.95rem;
  line-height: 1;
}

.tag-remove:hover,
.filter-chip button:hover { color: #111827; }

.tag-note { font-size: 0.85rem; }
.tag-placeholder { font-size: 0.95rem; }
.tag-input { max-width: 340px; }

.project-editor-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

/* Keep icons visible inside task tables at all times */
table.gridjs-table .btn-icon { vertical-align: middle; }

/* Markdown Reset inside table cells */
.md { padding: 0; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
/* Keep lists readable without adding top padding */
.md ul, .md ol { margin-top: 0; margin-bottom: 0; padding-left: 1.2rem; }
/* Avoid extra top space for common blocks */
.md p, .md pre, .md blockquote { margin-top: 0; }

/* Grid.js Overrides */
.gridjs *,.gridjs :after,.gridjs :before { box-sizing: border-box; }
.gridjs thead .gridjs-th { vertical-align: middle; }

/* Center header text and sort icon vertically in sortable columns */
.gridjs thead th.gridjs-th .gridjs-th-content { line-height: 24px; }
.gridjs thead button.gridjs-sort-asc,
.gridjs thead button.gridjs-sort-desc { background-position-y: center !important; }

/* Prevent header labels from being ellipsized (allow wrapping) */
.gridjs thead th.gridjs-th { white-space: normal; position: relative; }
.gridjs thead th.gridjs-th .gridjs-th-content {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  padding-right: 0;
  display: block;
  margin-right: 17px; /* reserve space for sort icon */
}
/* Place sort icon absolutely to the right, centered vertically */
.gridjs thead th.gridjs-th button.gridjs-sort {
  float: none !important;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

/* Reduce horizontal padding in Grid.js header/body cells */
table.gridjs-table th.gridjs-th,
table.gridjs-table td.gridjs-td { padding: 12px; }

/* Hide the trailing actions column header cell entirely for tasks grid */
.tasks-grid-container .gridjs thead tr th:last-child { display: none !important; }

/* Make trailing actions column fit icon width tightly for tasks grid */
.tasks-grid-container table.gridjs-table td.gridjs-td:last-child {
  width: 1%;
  white-space: nowrap;
  padding-left: 6px;
  padding-right: 6px;
}

/* Make Grid.js search box a bit shorter */
.gridjs input.gridjs-input {
  padding: 6px 10px;
  line-height: 1.3;
}

/* Inline editable cells */
td.gridjs-td.editable-cell { cursor: text; }
td.gridjs-td.editable-cell:hover { background: #f8fafc; }
.inline-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

/* Multiline editor for markdown */
.inline-input.multiline { min-height: 120px; line-height: 1.35; resize: vertical; }
.md-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  padding: 0.5rem; /* keep content from touching the border */
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden; /* prevent inner toolbar from spilling */
}
/* Group the markdown editor actions visibly and separate from textarea */
.md-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  border-bottom: 0; /* no divider under toolbar */
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  background: var(--surface);
  align-items: center;
  flex-wrap: wrap;            /* allow controls to wrap within editor width */
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Ensure editor controls have breathing room inside the bordered box */
.md-editor .inline-input.multiline { margin: 0; }
.md-editor .md.preview { margin: 0; }
.btn.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.9rem; }

/* (Removed demo drawer styles; using inline editing only) */

/* Add Task panel */
.add-task-panel { margin-top: 0.5rem; padding-top: 0.5rem; }

/* Project tag filter */
.filter-controls {
  margin: 0.5rem 0 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.filter-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}
.filter-row .btn { margin-right: 0; }
.filter-input-wrapper {
  position: relative;
  display: inline-flex;
  flex-direction: column;
}
.filter-input {
  max-width: 280px;
}
.filter-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 2;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.15rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.filter-suggestion {
  padding: 0.35rem 0.5rem;
  cursor: pointer;
}
.filter-suggestion:hover,
.filter-suggestion.active {
  background: #f1f5f9;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 1.4rem;
}
.filter-chips .small {
  font-size: 0.9rem;
}
.form-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  column-gap: 0.75rem;
  row-gap: 0.5rem;
  align-items: start;
}
.form-grid .label { color: var(--muted); padding-top: 0.35rem; }
.form-grid .field { width: 100%; }
.form-grid .field .inline-input { width: 100%; }
.add-task-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; }
