:root {
  /* Matches topbar vertical padding (10+10) + filter min-height (40) + border (1) = 61px, rounded up for breathing room. */
  --topbar-height: 64px;
}
* {
  box-sizing: border-box;
}
html, body {
  height: 100%;
}
body {
  margin: 0;
  padding-top: var(--topbar-height);
  font-family: system-ui, -apple-system, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  -webkit-font-smoothing: antialiased;
}
#root {
  height: 100%;
  max-width: 100%;
  margin: 0 auto;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.topbar-logo-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
}
.topbar-search-filter {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.icon-btn {
  background: none;
  border: none;
  color: #e2e8f0;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  font-size: 1.5rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  background: #334155;
}

/* Legendum button */
.legendum-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}
.legendum-linked {
  background: #334155;
  color: #e2e8f0;
}
.legendum-linked:hover {
  background: #475569;
}
.legendum-link {
  background: #3b82f6;
  color: white;
}
.legendum-link:hover {
  background: #2563eb;
}
.legendum-link:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.legendum-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  font-size: 11px;
  font-weight: 700;
}
.legendum-linked.low-credits {
  border: 2px solid #84cc16;
}
.legendum-linked .legendum-icon {
  background: #475569;
}

/* Lists */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
/* List filter (also `.topbar-search-filter` in the top bar) */
.list-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0 12px;
  min-height: 44px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.list-filter:focus-within {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}
.list-filter-icon {
  flex-shrink: 0;
  display: flex;
  color: #64748b;
}
.list-filter-input {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 10px 0;
  border: none;
  background: transparent;
  color: #e2e8f0;
  font-size: 16px;
  line-height: 1.3;
  outline: none;
}
.list-filter-input::placeholder {
  color: #64748b;
}
.list-filter-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}
.list-filter-clear {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 -4px 0 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.list-filter-clear:hover {
  background: #334155;
  color: #e2e8f0;
}
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #334155;
  cursor: pointer;
  background: #1e293b;
  min-height: 56px;
}
.list-item:active {
  background: #334155;
}
.list-item-content {
  flex: 1;
  min-width: 0;
}
.list-item-title {
  font-weight: 500;
  color: #e2e8f0;
}
.list-item-meta {
  font-size: 14px;
  color: #94a3b8;
  margin-top: 2px;
}

/* Free-form markdown blocks in todos.md (not task lines) */
.md-block {
  padding: 10px 16px 12px 20px;
  border-bottom: 1px solid #334155;
  font-size: 15px;
  line-height: 1.55;
  color: #e2e8f0;
}
.md-block p {
  margin: 0.5em 0;
}
.md-block p:first-child {
  margin-top: 0;
}
.md-block p:last-child {
  margin-bottom: 0;
}
.md-block h1,
.md-block h2,
.md-block h3,
.md-block h4 {
  font-size: 1.05em;
  font-weight: 600;
  margin: 0.65em 0 0.35em;
  color: #f1f5f9;
}
.md-block h1:first-child,
.md-block h2:first-child,
.md-block h3:first-child {
  margin-top: 0;
}
.md-block ul,
.md-block ol {
  margin: 0.35em 0;
  padding-left: 1.35em;
}
.md-block li {
  margin: 0.2em 0;
}
.md-block code {
  font-size: 0.9em;
  background: #1e293b;
  padding: 0.12em 0.4em;
  border-radius: 4px;
}
.md-block pre {
  background: #1e293b;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
  font-size: 14px;
}
.md-block pre code {
  background: none;
  padding: 0;
}
.md-block blockquote {
  margin: 0.4em 0;
  padding-left: 12px;
  border-left: 3px solid #475569;
  color: #cbd5e1;
}
.md-block .text-inline-link {
  color: #60a5fa;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.md-block .text-inline-link:hover {
  color: #93c5fd;
}

/* Draggable markdown row (no swipe actions) — align with .todo-row */
.md-sortable-inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  min-height: 48px;
  box-sizing: border-box;
}
.markdown-sortable-row .md-block {
  flex: 1;
  min-width: 0;
  border-bottom: none;
  padding: 0;
}
.markdown-sortable-row .drag-handle {
  margin-top: 2px;
}

/* Swipe row */
.row-wrap {
  list-style: none;
  margin: 0;
  overflow: hidden;
  border-bottom: 1px solid #334155;
}
.row-slider {
  display: flex;
  width: 100%;
  transition: transform 0.15s ease-out;
  touch-action: pan-y;
}
.row-main {
  flex: 1;
  min-width: 100%;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.row-edit {
  flex-shrink: 0;
  width: 72px;
  padding: 0 8px;
  border: none;
  border-radius: 0;
  background: #3b82f6;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.row-edit:hover {
  background: #60a5fa;
}
.row-edit:active {
  background: #2563eb;
}
.row-delete {
  flex-shrink: 0;
  width: 72px;
  padding: 0 8px;
  border: none;
  border-radius: 0;
  background: #dc2626;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.row-delete:hover {
  background: #ef4444;
}
.row-delete:active {
  background: #b91c1c;
}

/* Screens */
.offline-banner {
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.4;
  color: #fde68a;
  background: #422006;
  border-bottom: 1px solid #78350f;
}
.screen {
  padding-bottom: 24px;
}
.screen--detail {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-bottom: 0;
}
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #334155;
}
.screen-header-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.header-icon-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #94a3b8;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.header-icon-btn:hover {
  color: #e2e8f0;
  border-color: #475569;
}
.header-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.header-icon-btn:disabled:hover {
  color: #94a3b8;
  border-color: #334155;
}
.header-doc-history {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.header-history-arrow {
  position: relative;
  top: 1px;
  display: block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  background-color: currentColor;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}
.header-history-arrow--undo {
  mask-image: url("/undo-arrow.svg");
  -webkit-mask-image: url("/undo-arrow.svg");
}
.header-history-arrow--redo {
  mask-image: url("/redo-arrow.svg");
  -webkit-mask-image: url("/redo-arrow.svg");
}
.history-error-banner {
  padding: 8px 16px;
  font-size: 13px;
  line-height: 1.4;
  color: #fecaca;
  background: #450a0a;
  border-bottom: 1px solid #7f1d1d;
}
.screen-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.back-btn {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #475569;
  background: #334155;
  color: #e2e8f0;
}
.back-btn:hover {
  background: #475569;
}

/* Forms */
.form {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 16px;
}
.input::placeholder {
  color: #64748b;
}
.btn {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: #3b82f6;
  color: white;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: #334155;
  color: #e2e8f0;
}
.btn-danger {
  background: #dc2626;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #3b82f6;
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 5;
}
.fab:active {
  background: #2563eb;
}

/* Login */
.login-screen {
  max-width: 400px;
  margin: 0 auto;
  padding: 24px 16px;
  text-align: center;
}
.login-screen h1 {
  font-size: 24px;
  margin-bottom: 8px;
}
.login-screen p {
  color: #94a3b8;
  margin-bottom: 24px;
}
.login-logo {
  width: 96px;
  height: 96px;
  border-radius: 20px;
  margin-bottom: 16px;
}

/* Todo item */
.todo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 48px;
}
.todo-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid #475569;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  color: #3b82f6;
}
.todo-checkbox.checked {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}
.todo-text {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  word-break: break-word;
}
.todo-text.done {
  text-decoration: line-through;
  color: #64748b;
}
.todo-text .text-inline-link {
  color: #60a5fa;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.todo-text.done .text-inline-link {
  color: #94a3b8;
}
.todo-text code {
  font-size: 0.9em;
  background: #1e293b;
  padding: 0.12em 0.4em;
  border-radius: 4px;
}
.freeform-line .text-inline-link {
  color: #60a5fa;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.todo-text-edit {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  background: #1e293b;
  color: inherit;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 2px 4px;
  outline: none;
}

/* Free-form text line */
.freeform-line {
  padding: 4px 16px;
  color: #94a3b8;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 24px;
}

/* Drag handle */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  flex-shrink: 0;
  cursor: grab;
  color: #475569;
  touch-action: none;
}
.drag-handle:active {
  cursor: grabbing;
}
.drag-handle svg {
  width: 14px;
  height: 14px;
}
.drag-handle--static {
  cursor: default;
  color: #334155;
  opacity: 0.45;
  pointer-events: none;
}

/* Dragging overlay */
.drag-overlay {
  background: #1e293b;
  border: 1px solid #3b82f6;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0.95;
}

/* Inline add input */
.add-todo-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #334155;
  background: #1e293b;
  z-index: 10;
}
.add-todo-bar .input {
  flex: 1;
}
.add-todo-bar .btn {
  flex-shrink: 0;
  padding: 12px 16px;
}

/* Webhook URL copy */
.webhook-url {
  font-size: 12px;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}
.webhook-url:hover {
  color: #94a3b8;
}
.copied-badge {
  font-size: 11px;
  color: #22c55e;
}

/* Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dialog {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #334155;
}
.dialog-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 6px;
}
.dialog-close:hover {
  background: #334155;
  color: #e2e8f0;
}
.dialog-body {
  padding: 20px;
}
.dialog-section {
  margin-bottom: 20px;
}
.dialog-section:last-child {
  margin-bottom: 0;
}
.dialog-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: #94a3b8;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.dialog-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.dialog-section-head h3 {
  margin: 0;
}
.dialog-copy-hint {
  font-size: 12px;
  font-weight: 500;
  color: #4ade80;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.dialog-section p {
  font-size: 14px;
  color: #cbd5e1;
  margin: 0 0 8px;
  line-height: 1.5;
}
.dialog-section code {
  background: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: #38bdf8;
}
.dialog-code {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px 14px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: #e2e8f0;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
  line-height: 1.6;
}
/* Install curl line: scroll text only; copy icon fixed in corner (does not pan with overflow) */
button.dialog-code-install-wrap {
  appearance: none;
  font: inherit;
  text-align: left;
  padding: 0;
  margin: 0;
}
.dialog-code-install-wrap {
  position: relative;
  display: block;
  width: 100%;
  box-sizing: border-box;
  cursor: pointer;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.dialog-code-install-wrap:hover {
  border-color: #475569;
}
.dialog-code-install-wrap:focus {
  outline: none;
}
.dialog-code-install-wrap:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}
.dialog-code-install-wrap.dialog-code--flash {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
}
.dialog-code-install-scroll {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 38px 12px 14px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: #e2e8f0;
  white-space: pre;
  line-height: 1.6;
  margin: 0;
}
.dialog-code-install-icon {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  line-height: 0;
  color: #64748b;
  pointer-events: none;
  padding: 0;
  transition: color 0.15s ease;
}
.dialog-code-install-wrap:hover .dialog-code-install-icon {
  color: #94a3b8;
}
.dialog-code-install-wrap.dialog-code--flash .dialog-code-install-icon {
  color: #4ade80;
}

/* List count */
.cat-count {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: #64748b;
  flex-shrink: 0;
  margin-left: 8px;
  white-space: nowrap;
  display: inline-flex;
  gap: 6px;
}
.cat-count-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}
.cat-count-letter {
  font-size: 9px;
  letter-spacing: 0.5px;
  color: #475569;
  margin-bottom: 2px;
}

/* Fifo detail screen */
.fifo-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px;
  border-bottom: 1px solid #1e293b;
}
.fifo-detail-titles {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fifo-detail-name {
  background: none;
  border: none;
  color: #e2e8f0;
  font-size: 18px;
  font-weight: 600;
  text-align: left;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fifo-webhook-copy {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  cursor: pointer;
  max-width: 100%;
}
.fifo-webhook-copy:hover { color: #cbd5e1; }
.fifo-webhook-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-chips {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  border-bottom: 1px solid #1e293b;
}
.chip {
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip--active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}
.chip-count {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.item-row {
  list-style: none;
  padding: 10px 16px;
  border-bottom: 1px solid #1e293b;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.item-row:hover { background: #0b1426; }
.item-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}
.item-pos { color: #64748b; }
.item-age { margin-left: auto; }
.item-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.item-status--todo { background: #1e3a8a; color: #bfdbfe; }
.item-status--lock { background: #78350f; color: #fed7aa; }
.item-status--done { background: #14532d; color: #bbf7d0; }
.item-status--fail { background: #7f1d1d; color: #fecaca; }
.item-status--skip { background: #334155; color: #cbd5e1; }
.item-body {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
}
.item-reason {
  font-style: italic;
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
  word-break: break-word;
}
.dialog-reason {
  margin-top: 12px;
  padding: 10px 12px;
  background: #1e293b;
  border-left: 3px solid #64748b;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: #cbd5e1;
}
.dialog-reason-label {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 6px;
}
