/* Masterplan — Dark theme, mobile-first */

:root {
  --bg-primary: #111d38;
  --bg-secondary: #1c2b4a;
  --bg-card: #1e2d4d;
  --bg-hover: #243656;
  --bg-input: #162240;
  --text-primary: #f0f0f5;
  --text-secondary: #8899b4;
  --text-dim: #5a6b85;
  --accent: #E8956A;
  --accent-hover: #d9704c;
  --accent-dim: rgba(232, 149, 106, 0.15);
  --border: #2a3a5a;
  --success: #4ade80;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Futura', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

a {
  color: #60a5fa;
}

/* --- Header --- */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  max-width: 720px;
  margin: 0 auto;
  background: rgba(17, 29, 56, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-right {
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.header-title {
  font-size: 1.125rem;
  font-weight: 700;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn.primary {
  background: var(--accent);
  color: var(--bg-primary);
}

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

.icon-btn.active {
  color: var(--accent);
}

/* --- Menu Dropdown --- */
.menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 150;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.menu-dropdown a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s;
}

.menu-dropdown a:hover {
  background: var(--bg-hover);
}

.menu-dropdown a:last-child {
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
  padding-top: 0.75rem;
}

/* --- Main --- */
#main {
  padding: 0.5rem 0 6rem;
  max-width: 720px;
  margin: 0 auto;
}

/* --- Category Sections --- */
.category-section {
  margin: 0.5rem 0;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s;
  border-bottom: 1px solid transparent;
}

.category-header:hover {
  background: var(--bg-hover);
}

.category-header:active {
  background: var(--bg-secondary);
}

.category-emoji {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.category-name {
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
}

.category-count {
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--bg-secondary);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  min-width: 1.5rem;
  text-align: center;
}

.category-chevron {
  color: var(--text-dim);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.category-section.collapsed .category-chevron {
  transform: rotate(-90deg);
}

.category-tasks {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 2000px;
  opacity: 1;
}

.category-section.collapsed .category-tasks {
  max-height: 0;
  opacity: 0;
}

/* --- Task Items --- */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  border-bottom: 1px solid rgba(42, 58, 90, 0.4);
  cursor: pointer;
  transition: background 0.15s;
}

.task-item:hover {
  background: var(--bg-hover);
}

.task-item:active {
  background: var(--bg-secondary);
}

.task-checkbox {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  margin-top: 1px;
}

.task-checkbox:hover {
  border-color: var(--accent);
}

.task-item.done .task-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.task-checkbox svg {
  display: none;
}

.task-item.done .task-checkbox svg {
  display: block;
}

.task-content {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.task-item.done .task-title {
  color: var(--text-dim);
  text-decoration: line-through;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.25rem;
}

.task-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 500;
}

.badge-blocked {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.badge-subcategory {
  background: rgba(136, 153, 180, 0.15);
  color: var(--text-secondary);
}

.badge-notes {
  background: var(--accent-dim);
  color: var(--accent);
}

.badge-links {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
}

.badge-decision {
  background: rgba(250, 204, 21, 0.15);
  color: #facc15;
}

.badge-soft-blocked {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

/* Task image in detail view */
.task-detail-image {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-top: 0.375rem;
}

/* Hide done tasks when toggled off */
body.hide-done .task-item.done {
  display: none;
}

/* --- Dependency Chains --- */
.chain-card {
  margin: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.chain-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

.chain-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chain-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.chain-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
}

.chain-step.done .chain-step-num {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
}

.chain-step.done .chain-step-title {
  color: var(--text-dim);
  text-decoration: line-through;
}

.chain-step.current .chain-step-num {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.chain-step.current .chain-step-title {
  color: var(--accent);
  font-weight: 600;
}

.chain-connector {
  width: 1px;
  height: 12px;
  background: var(--border);
  margin-left: 11.5px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: opacity 0.2s;
}

.modal {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem;
  animation: slideUp 0.2s ease;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
  }
  .modal {
    border-radius: var(--radius);
    max-height: 85vh;
  }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.modal-close:hover {
  background: var(--bg-hover);
}

/* --- Forms --- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238899b4' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.btn {
  padding: 0.625rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
  flex: 1;
}

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

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

/* --- Task Detail View --- */
.task-detail {
  padding: 0 1rem;
}

.task-detail-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.task-detail-title {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
  flex: 1;
}

.detail-section {
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(42, 58, 90, 0.4);
}

.detail-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.375rem;
}

.detail-value {
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.detail-value a {
  color: #60a5fa;
  text-decoration: none;
}

.detail-value a:hover {
  text-decoration: underline;
}

.detail-value.claude-note {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0.75rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 0.375rem;
}

.blocker-list {
  list-style: none;
}

.blocker-list li {
  padding: 0.25rem 0;
  color: #f87171;
  font-size: 0.9rem;
}

.blocks-list li {
  color: var(--accent);
}

/* --- Toast --- */
#toast-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: toastIn 0.2s ease;
  pointer-events: auto;
  max-width: 90vw;
  text-align: center;
}

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

@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* --- Category Management --- */
.cat-manage-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid rgba(42, 58, 90, 0.4);
}

.cat-manage-item:active {
  background: var(--bg-secondary);
}

.cat-manage-emoji {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.cat-manage-name {
  flex: 1;
  font-size: 0.95rem;
  min-width: 0;
}

.cat-manage-count {
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.cat-manage-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.cat-manage-actions button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.cat-manage-actions button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.cat-manage-actions button.danger:hover {
  color: var(--danger);
}

.cat-manage-item.drag-over {
  border-top: 2px solid var(--accent);
  background: var(--accent-dim);
}

.cat-manage-item[draggable="true"] {
  touch-action: none;
}

.cat-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: 0.5rem;
}

.cat-add-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* --- Documents --- */
.doc-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(42, 58, 90, 0.4);
}

.doc-card:hover {
  background: var(--bg-hover);
}

.doc-card:active {
  background: var(--bg-secondary);
}

.doc-card-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

.doc-card-content {
  flex: 1;
  min-width: 0;
}

.doc-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}

.doc-card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-top: 0.15rem;
}

.doc-card-chevron {
  color: var(--text-dim);
  flex-shrink: 0;
}

/* --- Rendered Markdown --- */
.doc-rendered {
  padding: 0 1rem 3rem;
}

.doc-rendered h1.doc-h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 1.25rem 0 0.5rem;
  color: var(--accent);
}

.doc-rendered h2.doc-h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 1.25rem 0 0.5rem;
  color: var(--text-primary);
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.doc-rendered h3.doc-h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1rem 0 0.375rem;
  color: var(--text-primary);
}

.doc-rendered h4.doc-h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
  color: var(--text-secondary);
}

.doc-rendered .doc-p {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
  margin: 0.375rem 0;
}

.doc-rendered .doc-list {
  margin: 0.375rem 0 0.375rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.doc-rendered .doc-list li {
  margin: 0.2rem 0;
}

.doc-rendered .doc-hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.doc-rendered .doc-code {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  margin: 0.5rem 0;
  color: var(--text-secondary);
}

.doc-rendered code {
  background: var(--bg-input);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--accent);
}

.doc-rendered pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

.doc-rendered strong {
  color: var(--text-primary);
  font-weight: 600;
}

.doc-rendered a {
  color: #60a5fa;
  text-decoration: none;
}

.doc-rendered a:hover {
  text-decoration: underline;
}

.doc-table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.doc-table th {
  text-align: left;
  padding: 0.5rem 0.625rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
}

.doc-table td {
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: top;
}

.doc-table tr:hover td {
  background: var(--bg-hover);
}

/* --- Utilities --- */
.hidden { display: none !important; }

/* --- Back button for detail views --- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}

.empty-state p {
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

/* --- Quick add bar --- */
.quick-add {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.75rem 1rem;
  background: rgba(17, 29, 56, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: none;
  gap: 0.5rem;
  z-index: 90;
}

.quick-add.active {
  display: flex;
}

.quick-add input {
  flex: 1;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.quick-add input:focus {
  border-color: var(--accent);
}

.quick-add select {
  padding: 0.625rem 0.5rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  max-width: 140px;
}

.quick-add button {
  padding: 0.625rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
