/* Personal Research Dashboard - dark theme (default), vanilla CSS, no build step. */

/* ------------------------------------------------------------------ */
/* Design tokens                                                       */
/* ------------------------------------------------------------------ */

:root {
  color-scheme: dark;

  --bg: #111318;            /* page background */
  --surface: #1a1d25;       /* panels, sections */
  --surface-hover: #22262f;
  --border: #2b303c;
  --text: #e7e9ee;
  --text-muted: #98a0b3;
  --accent: #5b9cff;
  --accent-hover: #7aaeff;
  --accent-soft: rgba(91, 156, 255, 0.14);
  --success: #58b775;
  --warning: #d9a53f;
  --danger: #e5534b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ------------------------------------------------------------------ */
/* Header + quick capture                                              */
/* ------------------------------------------------------------------ */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.01em;
}

#quick-capture-form {
  display: flex;
  gap: 0.5rem;
  flex: 1 1 320px;
  max-width: 480px;
}

#quick-capture {
  flex: 1;
}

/* ------------------------------------------------------------------ */
/* Panels (sections)                                                   */
/* ------------------------------------------------------------------ */

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------------ */
/* Forms, inputs, buttons                                              */
/* ------------------------------------------------------------------ */

input[type="text"],
input[type="search"],
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
}

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

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

button {
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

button.danger:hover {
  background: rgba(229, 83, 75, 0.15);
}

button.ghost {
  background: transparent;
}

/* ------------------------------------------------------------------ */
/* Watchlist panel                                                     */
/* ------------------------------------------------------------------ */

#triggers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#triggers-list a {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 3px solid var(--warning);
  color: var(--text);
  text-decoration: none;
  font-size: 0.93rem;
}

#triggers-list a:hover {
  background: rgba(91, 156, 255, 0.24);
}

#triggers-list .trigger-topic {
  color: var(--text-muted);
  font-size: 0.76rem;
}

/* ------------------------------------------------------------------ */
/* Filters                                                             */
/* ------------------------------------------------------------------ */

#filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

#search {
  flex: 1 1 220px;
}

/* ------------------------------------------------------------------ */
/* Topics grid                                                         */
/* ------------------------------------------------------------------ */

#topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.9rem;
}

.topic-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.topic-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.topic-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.topic-card .topic-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.badge {
  font-size: 0.74rem;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge.status-active {
  color: var(--success);
  border-color: rgba(88, 183, 117, 0.5);
  background: rgba(88, 183, 117, 0.12);
}

.badge.status-archived {
  color: var(--text-muted);
}

.badge.status-completed {
  color: var(--accent);
  border-color: rgba(91, 156, 255, 0.5);
  background: var(--accent-soft);
}

.badge.trigger-count {
  color: var(--warning);
  border-color: rgba(217, 165, 63, 0.5);
}

#no-results {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ */
/* Inbox (shower thoughts)                                             */
/* ------------------------------------------------------------------ */

#thoughts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.thought-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
}

.thought-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.thought-timestamp {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.thought-actions {
  margin-left: auto;
  display: flex;
  gap: 0.4rem;
}

.thought-actions button {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

.thought-content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
}

/* ------------------------------------------------------------------ */
/* Empty states and toasts                                             */
/* ------------------------------------------------------------------ */

.empty-state {
  color: var(--text-muted);
  font-style: italic;
}

.hidden {
  display: none !important;
}

#toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  max-width: 320px;
  font-size: 0.9rem;
}

.toast-success {
  border-color: var(--success);
}

/* ------------------------------------------------------------------ */
/* Modals (promote-to-existing dialog)                                 */
/* ------------------------------------------------------------------ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal select {
  width: 100%;
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal input[type="text"] {
  width: 100%;
}

/* Date pickers (trigger editor, task 16) share the dark form styling. */
input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
}

.trigger-list li.highlighted {
  outline: 2px solid var(--warning);
  background: rgba(217, 165, 63, 0.12);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

[aria-busy="true"] {
  opacity: 0.6;
}

/* ------------------------------------------------------------------ */
/* Topic detail view                                                   */
/* ------------------------------------------------------------------ */

#topic-view {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#topic-view header {
  align-items: center;
}

#back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
}

#back-link:hover {
  color: var(--accent);
}

#topic-content {
  margin: 0;
}

#topic-title {
  margin: 0 0 0.5rem;
}

#topic-meta {
  margin-bottom: 1rem;
}

#topic-meta .meta-timestamp {
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* req 7.6: breadcrumb back to the parent topic on sub-topic pages. */
#parent-breadcrumb {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
}

#parent-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

#parent-breadcrumb a:hover {
  text-decoration: underline;
}

/* req 7.3: sub-topics section on parent topic pages. */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.section-heading h2 {
  margin: 0;
}

#subtopics-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#subtopics-list a {
  display: block;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  color: var(--text);
  text-decoration: none;
  font-size: 0.93rem;
}

#subtopics-list a:hover {
  background: rgba(91, 156, 255, 0.24);
}

.trigger-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.trigger-list li {
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 3px solid var(--warning);
  font-size: 0.93rem;
}

/* req 8.7: out-of-date-range triggers stay visible but dimmed. Muted text
 * on --surface keeps ~6.5:1 contrast (WCAG AA) - dimming comes from the
 * neutral background and quiet accent, not from low-contrast text. */
.trigger-list li.trigger-inactive {
  background: var(--surface);
  border-left-color: var(--border);
  color: var(--text-muted);
  font-style: italic;
}

/* Markdown body (rendered HTML from marked.js, sanitized by DOMPurify) */
#topic-body {
  font-size: 0.95rem;
  line-height: 1.6;
  word-break: break-word;
}

#topic-body h1,
#topic-body h2,
#topic-body h3,
#topic-body h4 {
  margin: 1.2em 0 0.4em;
  line-height: 1.3;
}

#topic-body h1 {
  margin-top: 0;
  font-size: 1.3rem;
}

#topic-body h2 {
  font-size: 1.15rem;
}

#topic-body p {
  margin: 0.5em 0;
}

#topic-body ul,
#topic-body ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}

#topic-body code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.08em 0.35em;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.88em;
}

#topic-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  overflow-x: auto;
}

#topic-body pre code {
  border: none;
  padding: 0;
}

#topic-body blockquote {
  margin: 0.6em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

#topic-body table {
  border-collapse: collapse;
  margin: 0.7em 0;
  width: 100%;
}

#topic-body th,
#topic-body td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
}

#topic-body th {
  background: var(--bg);
}

#topic-body a {
  color: var(--accent);
}

/* ------------------------------------------------------------------ */
/* Edit panel                                                          */
/* ------------------------------------------------------------------ */

#edit-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#markdown-editor {
  width: 100%;
  min-height: 45vh;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}

textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
}

#triggers-editor {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.trigger-editor-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.trigger-editor-row input {
  flex: 1;
  min-width: 9rem;
}

.trigger-editor-row input[type="date"] {
  flex: 0 0 auto;
  width: 8.6rem;
  font-size: 0.88rem;
}

.trigger-editor-row button {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.edit-field label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.edit-field-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.edit-field-controls input {
  flex: 0 1 240px;
}

.field-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

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

/* ------------------------------------------------------------------ */
/* Small screens                                                       */
/* ------------------------------------------------------------------ */

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

  /* In a column flex container the flex-basis applies to height, which
     would stretch the inputs; restore natural sizing. */
  #quick-capture-form {
    max-width: none;
    flex-basis: auto;
  }

  #filters {
    flex-direction: column;
    align-items: stretch;
  }

  #search {
    flex-basis: auto;
  }
}
