:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-subtle: #f9fafb;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-soft: #eff6ff;
  --danger: #dc2626;
  --success: #059669;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Menlo', monospace;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-subtle); }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

a { color: inherit; }
button, input, textarea { font: inherit; }

button, .button-link {
  border: 0;
  border-radius: 2px;
  background: var(--brand);
  color: #fff;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: all 150ms ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-family: var(--mono);
}

button:hover, .button-link:hover {
  opacity: 0.88;
  transform: none;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.ghost:hover {
  border-color: #9ca3af;
  color: var(--text);
}

/* Shell */
.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.topbar h1 {
  margin: 0;
  font-size: 1rem;
  font-family: var(--mono);
  letter-spacing: -0.01em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-side {
  display: flex;
  gap: 8px;
  align-items: center;
}

.brand-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--brand);
  border-radius: 50%;
  flex-shrink: 0;
}

.brand-accent { color: var(--brand); }

/* Muted helpers */
.subtle, .hint, .meta-line, code {
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
}

/* Layout */
.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 50px);
}

.capture-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 24px 0;
}

/* Card */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 20px;
}

/* Flex helpers */
.card-title-row, .inline-actions, .inline-form, .page-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.inline-form { align-items: stretch; }

/* Labels */
label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-family: var(--mono);
}

/* Inputs */
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 2px;
  padding: 0.65rem 0.8rem;
  color: var(--text);
  font-size: 0.875rem;
  transition: border-color 150ms ease;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
}

textarea { resize: vertical; }

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  background: var(--bg);
  box-shadow: none;
  overflow-y: auto;
  min-height: calc(100vh - 50px);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 600;
}

#noteCount { padding: 8px 16px 0; }

.sidebar-filters {
  padding: 12px 16px 4px;
  border-bottom: 1px solid var(--border);
}

.sidebar-filters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tag-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
  line-height: 1.2;
}

.filter-chip:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
  opacity: 1;
}

.filter-chip.active {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* Note list */
.note-list {
  display: flex;
  flex-direction: column;
  margin-top: 0;
}

.note-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  box-shadow: none;
  transition: all 150ms ease;
}

.note-item:hover {
  background: var(--bg-subtle);
  transform: none;
  box-shadow: none;
}

.note-item.active {
  background: var(--brand-soft);
  border-left-color: var(--brand);
  box-shadow: none;
}

.note-item-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 12px;
  width: 100%;
}

.note-item h3 {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  font-weight: 500;
  color: var(--text);
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-width: 0;
}

.note-date {
  font-size: 0.6875rem;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
  text-align: right;
}

.note-item.active h3 { color: #1e40af; }
.note-item.active .note-date { color: var(--brand); }

/* Detail */
.detail {
  padding: 24px 32px;
  min-height: calc(100vh - 50px);
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: var(--bg);
  overflow-y: auto;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  margin: 4px 0 8px;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--brand);
  font-family: var(--mono);
  margin: 0;
}

/* Detail actions */
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: flex-end;
}

.detail-link, .tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 2px;
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--mono);
  text-decoration: none;
  box-shadow: none;
  gap: 0.25rem;
}

.detail-link.danger {
  color: var(--danger);
}

.detail-link.danger:hover {
  border-color: rgba(220, 38, 38, 0.18);
  color: var(--danger);
}

.detail-link:hover, .tab:hover {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--brand);
  transform: none;
  opacity: 1;
}

.detail-link:disabled {
  color: #d1d5db;
  background: transparent;
  border-color: transparent;
  cursor: not-allowed;
  opacity: 1;
}

.detail-link-icon {
  font-size: 0.75rem;
  line-height: 1;
}

.note-tags-section {
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-subtle);
}

.note-tags-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.note-tags-header .eyebrow {
  margin: 0;
  color: var(--muted);
}

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 24px;
  margin-bottom: 12px;
}

.tag-empty {
  display: inline-flex;
  align-items: center;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.22rem 0.3rem 0.22rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.75rem;
  font-family: var(--mono);
}

.tag-pill-label {
  line-height: 1.2;
}

.tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
}

.tag-remove:hover {
  color: var(--danger);
  background: rgba(220, 38, 38, 0.08);
  opacity: 1;
}

.tag-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  justify-content: flex-start;
  margin-bottom: 16px;
}

.tab.active {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: var(--brand);
}

/* Content panels */
.preview-panel, .markdown-panel {
  min-height: 420px;
  padding: 20px;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: var(--bg);
  overflow: auto;
}

.preview-panel img { max-width: 100%; border-radius: 2px; }

.preview-panel pre, .markdown-panel {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.preview-panel blockquote {
  margin-left: 0;
  padding-left: 16px;
  border-left: 2px solid var(--brand);
  color: var(--muted);
}

.preview-panel table { width: 100%; border-collapse: collapse; }
.preview-panel th, .preview-panel td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 0.875rem;
}

/* Empty state */
.empty-state {
  display: grid;
  place-items: center;
  min-height: 52vh;
  text-align: center;
}

.empty-state-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 360px;
}

.empty-state h2 {
  margin-bottom: 0.25rem;
  font-size: 1rem;
  color: var(--muted);
}

.empty-state p {
  color: var(--muted);
  font-size: 0.8125rem;
  font-family: var(--mono);
}

/* Status */
.success { color: var(--success); }
.error { color: var(--danger); }

/* Toast */
.toast {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 50;
  max-width: 400px;
  padding: 0.6rem 1rem;
  border-radius: 2px;
  background: var(--text);
  color: #fff;
  font-size: 0.8125rem;
  font-family: var(--mono);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 150ms ease, transform 150ms ease;
}

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

/* Back to top */
.back-to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 2px;
  font-size: 0.875rem;
  font-family: var(--mono);
  background: var(--text);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: all 150ms ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.back-to-top.visible {
  opacity: 0.6;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover { opacity: 1; }

/* Responsive */
@media (max-width: 980px) {
  .capture-grid, .workspace {
    grid-template-columns: 1fr;
  }

  .topbar { flex-wrap: wrap; }
  .topbar-side { width: 100%; justify-content: flex-end; }

  .inline-form { display: grid; }

  .shell { padding: 0 10px; }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: auto;
  }

  .detail {
    padding: 16px;
    min-height: auto;
  }

  .detail-header { flex-direction: column; }
  .tag-form { grid-template-columns: 1fr; }

  .toast {
    top: 8px;
    right: 8px;
    left: 8px;
    max-width: none;
  }
}

/* Extra mobile optimization for 6.7" phones (~412px) */
@media (max-width: 480px) {
  .shell { padding: 0 6px; }
  .capture-grid {
    gap: 12px;
    padding: 16px 0;
  }

  .card {
    padding: 16px;
  }

  .topbar {
    gap: 8px;
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 0.85rem;
    line-height: 1.4;
  }

  .topbar-side {
    width: 100%;
    gap: 6px;
    justify-content: stretch;
  }

  .topbar-side .button-link,
  .inline-form > button,
  .inline-actions > button,
  .inline-actions > .button-link,
  #refreshNotes,
  #saveTags {
    min-height: 44px;
    padding: 0.6rem 0.8rem;
    font-size: 0.8rem;
  }

  .topbar-side .button-link {
    width: 100%;
  }

  .card-title-row,
  .inline-actions,
  .note-tags-header,
  .detail-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .inline-actions > * {
    width: 100%;
  }

  .sidebar {
    padding: 0;
  }

  .sidebar-header,
  .sidebar-filters {
    padding-left: 12px;
    padding-right: 12px;
  }

  #noteCount {
    padding-left: 12px;
    padding-right: 12px;
  }

  .note-item {
    padding: 10px 12px;
  }

  .note-item-main {
    grid-template-columns: 1fr;
    row-gap: 4px;
  }

  .note-item h3 {
    font-size: 0.8rem;
  }

  .note-date {
    text-align: left;
    white-space: normal;
    font-size: 0.65rem;
  }

  .detail {
    padding: 12px 0 16px;
  }

  .detail-header {
    gap: 12px;
    margin-bottom: 16px;
    padding: 0 12px 16px;
  }

  .detail-header h2 {
    font-size: 1rem;
  }

  .detail-actions {
    width: 100%;
    gap: 6px;
  }

  .detail-actions > * {
    flex: 1 1 calc(50% - 3px);
    justify-content: center;
    min-height: 40px;
    padding: 0.5rem 0.6rem;
    font-size: 0.72rem;
  }

  .note-tags-section,
  .preview-panel,
  .markdown-panel {
    margin-left: 12px;
    margin-right: 12px;
    padding: 14px;
  }

  .preview-panel,
  .markdown-panel {
    min-height: 280px;
  }

  .tabs {
    gap: 6px;
    margin-bottom: 12px;
    padding: 0 12px;
    overflow-x: auto;
  }

  .tab {
    min-height: 40px;
    padding: 0.5rem 0.6rem;
    white-space: nowrap;
  }

  .tag-pill {
    font-size: 0.68rem;
    padding: 0.2rem 0.3rem 0.2rem 0.5rem;
  }

  .tag-remove {
    width: 24px;
    height: 24px;
    min-height: 24px;
  }

  input[type="text"], input[type="url"], textarea {
    font-size: 16px; /* Prevents mobile browsers from auto-zooming on focus */
    min-height: 44px;
  }

  textarea {
    min-height: 120px;
  }

  .back-to-top {
    width: 40px;
    height: 40px;
  }
}
