:root {
  color-scheme: dark;
  --background: #0f0f10;
  --sidebar: #1c1c1e;
  --panel: #242426;
  --panel-raised: #2c2c2e;
  --selected: #3a3a3c;
  --text: #f2f2f7;
  --secondary: #a1a1a8;
  --tertiary: #707078;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #d4b67b;
  --red: #c84a3c;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; }
body { margin: 0; overflow: hidden; color: var(--text); background: var(--background); }
button, input, textarea { font: inherit; }
button { color: inherit; }
textarea { color: inherit; }
[hidden] { display: none !important; }

.pairing-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px;
  background: radial-gradient(circle at 50% -20%, #34302a 0, var(--background) 48%);
}
.pairing-panel { width: min(100%, 460px); text-align: center; }
.pairing-logo { width: min(72%, 320px); height: auto; margin-bottom: 24px; }
.pairing-logo.small { width: min(56%, 240px); }
.pairing-panel h1 { margin: 0; font-size: 34px; letter-spacing: 0; }
.pairing-panel p { margin: 12px auto 24px; color: var(--secondary); font-size: 17px; line-height: 1.5; }
.qr-shell { width: 244px; height: 244px; margin: 0 auto; padding: 12px; border-radius: 18px; background: #fff; }
.qr-shell img { width: 100%; height: 100%; display: block; }
.pairing-status { min-height: 24px; margin-top: 18px; color: var(--secondary); }
.primary-button, .secondary-button {
  min-height: 44px;
  margin-top: 18px;
  padding: 0 18px;
  border: 0;
  border-radius: 9px;
  font-weight: 650;
  cursor: pointer;
}
.primary-button { color: #171412; background: var(--accent); }
.secondary-button { background: var(--panel-raised); }

.app-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-columns: 260px minmax(350px, 440px) minmax(420px, 1fr);
  background: var(--background);
}
.sidebar, .list-pane, .detail-pane { min-width: 0; min-height: 0; }
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}
.brand-row { height: 76px; display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.brand-mark { width: 54px; height: 38px; object-fit: contain; }
.brand-row div { display: grid; gap: 2px; }
.brand-row strong { font-size: 18px; }
.brand-row span { color: var(--secondary); font-size: 12px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 12px 8px 24px; }
.nav-heading { padding: 20px 12px 8px; color: var(--secondary); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.nav-row {
  width: 100%; min-height: 42px; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 6px 10px; border: 0; border-radius: 7px; background: transparent; text-align: left; cursor: pointer;
}
.nav-row:hover { background: rgba(255,255,255,0.055); }
.nav-row.selected { background: var(--selected); }
.nav-row strong { color: var(--secondary); font-size: 13px; font-weight: 600; }
.nav-icon { color: var(--secondary); text-align: center; }
.sidebar-footer { display: grid; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.sidebar-footer span { overflow: hidden; color: var(--secondary); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer button { width: fit-content; padding: 0; border: 0; color: var(--secondary); background: transparent; cursor: pointer; }

.list-pane { display: flex; flex-direction: column; background: #202022; border-right: 1px solid var(--line); }
.list-toolbar { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.search-field { height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 13px; border-radius: 9px; background: #151516; }
.search-field span { color: var(--secondary); font-size: 25px; transform: translateY(-1px); }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 16px; }
.search-field input::placeholder { color: var(--tertiary); }
.list-heading-row { min-height: 54px; display: flex; align-items: end; justify-content: space-between; gap: 12px; padding-top: 13px; }
.list-heading-row h1 { margin: 0; font-size: 22px; }
.list-heading-row span { color: var(--secondary); font-size: 13px; }
.toolbar-actions { display: flex; align-items: center; gap: 7px; }
.toolbar-button {
  min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); background: var(--panel-raised); font-size: 13px; font-weight: 650; cursor: pointer;
}
.toolbar-button:hover { border-color: rgba(255,255,255,0.18); background: var(--selected); }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: var(--secondary); font-size: 22px; cursor: pointer; }
.icon-button:hover { background: var(--selected); color: var(--text); }
.save-list { flex: 1; min-height: 0; overflow-y: auto; }
.save-row {
  width: 100%; display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 14px; padding: 15px 16px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer;
}
.save-row:hover { background: rgba(255,255,255,0.035); }
.save-row.selected { background: var(--selected); }
.save-thumb { width: 78px; height: 64px; display: grid; place-items: center; overflow: hidden; border-radius: 7px; color: var(--secondary); background: #151516; font-size: 22px; }
.save-thumb img { width: 100%; height: 100%; object-fit: cover; }
.save-copy { min-width: 0; display: grid; align-content: center; gap: 5px; }
.save-copy strong, .save-copy p, .save-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-copy strong { font-size: 15px; }
.save-copy p { margin: 0; color: var(--secondary); font-size: 13px; }
.save-meta { color: var(--tertiary); font-size: 12px; }
.empty-state, .detail-placeholder { margin: auto; display: grid; justify-items: center; gap: 7px; padding: 28px; color: var(--secondary); text-align: center; }
.empty-state strong, .detail-placeholder strong { color: var(--text); font-size: 17px; }
.empty-state span { font-size: 14px; }
.load-more { margin: 12px; min-height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-raised); cursor: pointer; }

.detail-pane { position: relative; overflow-y: auto; background: var(--panel); }
.detail-placeholder { min-height: 100%; align-content: center; }
.detail-placeholder > span { color: var(--tertiary); font-size: 44px; }
.detail-placeholder p { max-width: 320px; margin: 0; line-height: 1.45; }
.detail-back { display: none; margin: 14px 18px 0; padding: 0; border: 0; color: #78b7ff; background: transparent; cursor: pointer; }
.detail-hero { position: relative; min-height: 220px; display: grid; align-items: end; overflow: hidden; background: #151516; }
.detail-hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.72; }
.detail-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 10%, rgba(20,20,22,0.35) 50%, var(--panel) 100%); }
.detail-title { position: relative; z-index: 1; padding: 40px 30px 24px; }
.detail-title .eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.detail-title h1 { max-width: 840px; margin: 8px 0 0; font-size: clamp(28px, 3vw, 42px); line-height: 1.08; }
.detail-body { max-width: 920px; display: grid; gap: 18px; padding: 12px 30px 60px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.detail-actions a { min-height: 40px; display: inline-flex; align-items: center; padding: 0 14px; border-radius: 8px; color: #171412; background: var(--accent); font-weight: 700; text-decoration: none; }
.detail-button {
  min-height: 40px; display: inline-flex; align-items: center; padding: 0 14px; border: 1px solid var(--line);
  border-radius: 8px; font-weight: 700; cursor: pointer;
}
.detail-button.primary { border-color: transparent; color: #171412; background: var(--accent); }
.detail-button.secondary { background: var(--panel-raised); }
.detail-button.destructive { border-color: rgba(255, 69, 58, 0.45); color: #ff6961; background: rgba(255, 69, 58, 0.1); }
.detail-button:hover { filter: brightness(1.08); }
.detail-button:disabled { opacity: 0.55; cursor: default; }
.shared-label { min-height: 40px; display: inline-flex; align-items: center; color: var(--secondary); }
.detail-section { padding-top: 18px; border-top: 1px solid var(--line); }
.detail-section h2 { margin: 0 0 9px; font-size: 17px; }
.detail-section p { margin: 0; color: #d1d1d6; font-size: 16px; line-height: 1.55; white-space: pre-wrap; }
.detail-section ul { margin: 0; padding-left: 22px; color: #d1d1d6; line-height: 1.55; }
.pills { display: flex; flex-wrap: wrap; gap: 7px; }
.pill { padding: 5px 9px; border-radius: 999px; color: var(--secondary); background: var(--panel-raised); font-size: 12px; }
.detail-facts { display: flex; flex-wrap: wrap; gap: 18px; color: var(--secondary); font-size: 13px; }
.code-copy p { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; }
.resource-list { display: grid; gap: 8px; }
.resource-row {
  display: grid; gap: 3px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); background: rgba(255,255,255,0.025); text-decoration: none;
}
.resource-row:hover { background: rgba(255,255,255,0.055); }
.resource-row span { color: var(--secondary); font-size: 13px; line-height: 1.4; }

.comments-section { display: grid; gap: 12px; }
.comments-section h2 { margin-bottom: 0; }
.comment-list { display: grid; gap: 8px; }
.comment-card { display: grid; gap: 6px; padding: 12px 13px; border-radius: 8px; background: var(--panel-raised); }
.comment-card p, .comment-empty { margin: 0; color: #d1d1d6; line-height: 1.48; white-space: pre-wrap; }
.comment-card span { color: var(--tertiary); font-size: 12px; }
.comment-empty { color: var(--secondary); font-size: 14px; }
.note-composer { display: grid; gap: 9px; margin-top: 4px; }
.note-composer textarea {
  width: 100%; resize: vertical; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  outline: 0; background: #19191b; line-height: 1.45;
}
.note-composer textarea:focus { border-color: var(--accent); }
.note-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.note-controls label { color: var(--secondary); font-size: 13px; }
.note-controls input { accent-color: var(--accent); }
.form-status { min-height: 18px; margin: 0; color: var(--secondary); font-size: 13px; }

.idea-dialog {
  width: min(760px, calc(100vw - 40px)); max-height: calc(100dvh - 40px); padding: 0; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.14); border-radius: 13px; color: var(--text); background: var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.idea-dialog::backdrop { background: rgba(0,0,0,0.68); backdrop-filter: blur(4px); }
.idea-dialog form { max-height: calc(100dvh - 40px); display: flex; flex-direction: column; }
.idea-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px 16px; border-bottom: 1px solid var(--line); }
.idea-dialog header h2 { margin: 3px 0 0; font-size: 24px; }
.idea-dialog .eyebrow { color: var(--accent); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.idea-form-fields { display: grid; gap: 15px; padding: 20px 22px; overflow-y: auto; }
.idea-form-fields label { display: grid; gap: 7px; color: var(--secondary); font-size: 13px; font-weight: 650; }
.idea-form-fields label > span { font-weight: 400; }
.idea-form-fields input, .idea-form-fields textarea {
  width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 8px; outline: 0;
  color: var(--text); background: #19191b; font-weight: 400; line-height: 1.45;
}
.idea-form-fields textarea { resize: vertical; }
.idea-form-fields input:focus, .idea-form-fields textarea:focus { border-color: var(--accent); }
.idea-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.idea-dialog > form > .form-status { padding: 0 22px; }
.idea-dialog footer { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 22px 20px; border-top: 1px solid var(--line); }
.idea-dialog footer .primary-button, .idea-dialog footer .secondary-button { margin: 0; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 240px minmax(0, 1fr); }
  .detail-pane { position: fixed; z-index: 4; top: 0; right: 0; bottom: 0; left: 240px; transform: translateX(100%); transition: transform 180ms ease-out; }
  body.detail-open .detail-pane { transform: translateX(0); }
  .detail-back { display: block; }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100dvh; grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: 280px; }
  .brand-row { height: 62px; }
  .sidebar nav { display: flex; gap: 6px; overflow-x: auto; padding: 8px; }
  .nav-heading, #category-list { display: contents; }
  .nav-row { width: auto; min-width: max-content; grid-template-columns: 20px auto auto; }
  .sidebar-footer { display: none; }
  .list-pane { min-height: calc(100dvh - 280px); border-right: 0; }
  .detail-pane { left: 0; }
  .detail-title, .detail-body { padding-left: 20px; padding-right: 20px; }
  .pairing-view { padding: 20px; }
  .idea-form-grid { grid-template-columns: 1fr; }
  .idea-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .idea-dialog form { max-height: calc(100dvh - 20px); }
  .note-controls { align-items: stretch; flex-direction: column; }
  .note-controls .detail-button { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .detail-pane { transition: none; }
}
