:root {
  color-scheme: dark;
  --bg: #151817;
  --chrome: #1d211f;
  --chrome-strong: #252a27;
  --surface: #fbf6ec;
  --surface-soft: #f0e8d8;
  --surface-ink: #20231f;
  --text: #f3efe5;
  --muted: #aab3a9;
  --muted-strong: #6c746d;
  --border: rgba(243, 239, 229, 0.12);
  --dark-border: rgba(32, 35, 31, 0.14);
  --teal: #38d7bd;
  --teal-dark: #176f63;
  --amber: #e6a93e;
  --red: #ee726d;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(56, 215, 189, 0.08), transparent 28%),
    radial-gradient(circle at 72% 14%, rgba(230, 169, 62, 0.08), transparent 24%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 22px 16px;
  background: rgba(20, 23, 21, 0.92);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  color: #fffdf7;
  font-size: 17px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--teal), #b7ffe6);
  color: #10201d;
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(56, 215, 189, 0.18);
}

.rail-nav {
  display: grid;
  gap: 7px;
}

.nav-item,
.ghost-button,
.primary-button,
.icon-button,
.text-button,
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  height: 42px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

.nav-item.active,
.nav-item:hover {
  background: var(--chrome-strong);
  color: var(--text);
  border-color: var(--border);
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.rail-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.sync-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
}

.pulse,
.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(56, 215, 189, 0.12);
}

.rail-footer small {
  color: var(--muted);
  font-size: 12px;
}

.rail-upgrade {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  margin-top: 10px;
  padding: 0 12px;
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(56, 215, 189, 0.18), rgba(56, 215, 189, 0.06));
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-decoration: none;
  border: 1px solid rgba(56, 215, 189, 0.35);
  -webkit-tap-highlight-color: transparent;
}
.rail-upgrade:hover {
  background: rgba(56, 215, 189, 0.22);
  color: #b7ffe6;
}

.topbar-upgrade {
  display: none;
  text-decoration: none;
  color: var(--teal);
  border-color: rgba(56, 215, 189, 0.35);
  background: rgba(56, 215, 189, 0.1);
}
.topbar-upgrade:hover { color: #b7ffe6; background: rgba(56, 215, 189, 0.18); }

.workspace {
  display: grid;
  grid-template-rows: 70px minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  background: rgba(29, 33, 31, 0.82);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
}

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(460px, 46vw);
  height: 42px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111412;
  color: var(--muted);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  height: 42px;
  background: #111412;
  color: var(--muted);
  border-color: var(--border);
}

.ghost-button {
  height: 42px;
  padding: 0 13px;
  background: #111412;
  color: var(--text);
  border-color: var(--border);
}

.primary-button {
  height: 42px;
  padding: 0 15px;
  background: var(--teal);
  color: #10201d;
}

.content-grid {
  display: grid;
  grid-template-columns: 280px minmax(390px, 1fr) 380px;
  gap: 1px;
  min-height: 0;
  background: var(--border);
}

.notes-panel,
.editor-panel,
.detail-panel {
  min-width: 0;
  min-height: 0;
  background: var(--chrome);
}

.notes-panel,
.detail-panel {
  padding: 18px;
  overflow: auto;
}

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

h2 {
  margin: 0;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-heading span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.note-list,
.snippet-list,
.queue-list {
  display: grid;
  gap: 9px;
}

.note-card,
.snippet-card,
.queue-card {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  text-align: left;
}

.note-card {
  display: grid;
  gap: 7px;
  padding: 13px;
}

.note-card.active {
  border-color: rgba(56, 215, 189, 0.45);
  background: rgba(56, 215, 189, 0.09);
}

.note-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.note-card strong {
  overflow: hidden;
  color: #fffdf7;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #cfd7ce;
  font-family: var(--mono);
  font-size: 11px;
}

.editor-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--surface);
  color: var(--surface-ink);
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--dark-border);
}

.editor-header > div:first-child {
  display: grid;
  gap: 7px;
  min-width: 0;
  width: 100%;
}

.editor-header label {
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

#noteTitle {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--surface-ink);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
}

.saved-state {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.editor-tabs {
  display: flex;
  gap: 7px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--dark-border);
}

.tab {
  height: 30px;
  padding: 0 11px;
  background: transparent;
  color: #70776e;
  border-color: var(--dark-border);
}

.tab.active {
  background: #20231f;
  color: #fffaf0;
}

#editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 22px 26px 32px;
  border: 0;
  outline: 0;
  resize: none;
  background:
    linear-gradient(90deg, rgba(32, 35, 31, 0.06) 1px, transparent 1px) 0 0 / 58px 58px,
    var(--surface);
  color: #242720;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.74;
  tab-size: 2;
}

.detail-panel {
  display: grid;
  grid-template-rows: minmax(260px, 1fr) auto auto;
  gap: 18px;
}

.preview-block,
.snippet-block,
.queue-block {
  min-width: 0;
}

.settings-block {
  min-width: 0;
}

.preview {
  min-height: 260px;
  max-height: 42vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111412;
  color: #e9ede5;
}

.preview h1,
.preview h2,
.preview h3 {
  margin: 0 0 10px;
  color: #fffdf7;
  line-height: 1.15;
}

.preview h1 {
  font-size: 24px;
}

.preview h2 {
  font-size: 18px;
  text-transform: none;
}

.preview p,
.preview li {
  color: #c8d0c7;
  font-size: 13px;
  line-height: 1.58;
}

.preview code,
.snippet-code {
  font-family: var(--mono);
}

.preview pre {
  overflow: auto;
  padding: 13px;
  border: 1px solid rgba(56, 215, 189, 0.2);
  border-radius: 8px;
  background: #0c0f0d;
}

.preview pre code {
  color: #b8f7e9;
  font-size: 12px;
  line-height: 1.6;
}

.preview .kw {
  color: #8fd8ff;
}

.preview .str {
  color: #ffd18c;
}

.preview :not(pre) > code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(56, 215, 189, 0.12);
  color: #9bf2df;
}

.text-button {
  min-height: 28px;
  padding: 0 9px;
  background: rgba(56, 215, 189, 0.1);
  color: var(--teal);
  border-color: rgba(56, 215, 189, 0.22);
  font-size: 12px;
}

.snippet-card {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.snippet-card strong,
.queue-card strong {
  color: #fffdf7;
  font-size: 13px;
}

.snippet-code {
  overflow: hidden;
  padding: 9px;
  border-radius: 7px;
  background: #111412;
  color: #b8f7e9;
  font-size: 11px;
  line-height: 1.45;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.queue-card {
  display: grid;
  gap: 5px;
  padding: 11px 12px;
}

.queue-card span {
  color: var(--muted);
  font-size: 12px;
}

.queue-card[data-state="ready"] {
  border-color: rgba(56, 215, 189, 0.34);
}

.queue-card[data-state="queued"] {
  border-color: rgba(230, 169, 62, 0.34);
}

.settings-form {
  display: grid;
  gap: 9px;
}

.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.settings-form input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: 0;
  background: #111412;
  color: var(--text);
  font-size: 12px;
  text-transform: none;
}

.field-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.input-with-toggle {
  position: relative;
}

.input-with-toggle input {
  padding-right: 38px;
}

.reveal-button {
  position: absolute;
  top: 50%;
  right: 4px;
  width: 32px;
  height: 32px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.reveal-button:hover { color: var(--text); }

.reveal-button svg {
  width: 16px;
  height: 16px;
}

.strength-meter {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}

.strength-bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.strength-bars span {
  height: 4px;
  border-radius: 999px;
  background: rgba(243, 239, 229, 0.08);
  transition: background 160ms ease;
}

.strength-meter[data-score="1"] .strength-bars span:nth-child(-n+1) { background: var(--red); }
.strength-meter[data-score="2"] .strength-bars span:nth-child(-n+2) { background: var(--amber); }
.strength-meter[data-score="3"] .strength-bars span:nth-child(-n+3) { background: #b6d96b; }
.strength-meter[data-score="4"] .strength-bars span { background: var(--teal); }

.strength-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  min-height: 12px;
}

.strength-meter[data-score="1"] .strength-label { color: var(--red); }
.strength-meter[data-score="2"] .strength-label { color: var(--amber); }
.strength-meter[data-score="3"] .strength-label { color: #b6d96b; }
.strength-meter[data-score="4"] .strength-label { color: var(--teal); }

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.auth-status {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  min-height: 14px;
}

.auth-status[data-tone="error"] { color: var(--red); }
.auth-status[data-tone="ok"] { color: var(--teal); }

.conflict-block {
  display: grid;
  gap: 8px;
}

.conflict-card {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid rgba(238, 114, 109, 0.4);
  border-radius: 8px;
  background: rgba(238, 114, 109, 0.06);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.conflict-card strong {
  color: #fffdf7;
  font-size: 13px;
}

.conflict-card span {
  color: var(--muted);
  font-size: 11px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 10, 9, 0.78);
  z-index: 50;
}

.modal[hidden] { display: none; }

.modal-card {
  width: min(720px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--chrome);
  box-shadow: var(--shadow);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

.conflict-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.conflict-grid article {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.conflict-grid h4 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.conflict-grid pre {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  padding: 10px;
  border-radius: 6px;
  background: #111412;
  color: #c8d0c7;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  .conflict-grid { grid-template-columns: 1fr; }
}

body[data-connection="online"] .pulse,
body[data-connection="online"] .dot {
  background: #72e15f;
  box-shadow: 0 0 0 5px rgba(114, 225, 95, 0.12);
}

.light-mode {
  color-scheme: light;
  --bg: #e9efe8;
  --chrome: #f7f4ec;
  --chrome-strong: #ebe5d9;
  --text: #20231f;
  --muted: #667066;
  --border: rgba(32, 35, 31, 0.14);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .brand span:last-child,
  .nav-item span,
  .rail-footer small {
    display: none;
  }

  .rail {
    align-items: center;
  }

  .nav-item {
    justify-content: center;
    width: 44px;
    padding: 0;
  }

  .sync-pill span:last-child {
    display: none;
  }

  .content-grid {
    grid-template-columns: 230px minmax(360px, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .preview-block {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    display: none;
  }

  .workspace {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .search {
    width: 100%;
  }

  .search input {
    font-size: 16px;
  }

  .topbar-upgrade {
    display: inline-flex;
  }

  .top-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  .ghost-button,
  .primary-button {
    flex: 1 1 calc(50% - 4px);
    min-height: 44px;
  }

  .icon-button {
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
  }

  .backup-button {
    min-width: 0;
  }

  .content-grid,
  .detail-panel {
    display: block;
  }

  .notes-panel,
  .editor-panel,
  .detail-panel {
    min-height: auto;
  }

  .notes-panel {
    max-height: 260px;
  }

  #noteTitle {
    font-size: 23px;
  }

  #editor {
    min-height: 440px;
    font-size: 16px;
  }

  .editor-tabs {
    gap: 8px;
  }

  .tab {
    height: 44px;
    padding: 0 14px;
  }

  .text-button {
    min-height: 40px;
    padding: 0 12px;
  }

  .settings-form input {
    height: 44px;
    font-size: 16px;
  }

  .detail-panel {
    padding: 14px;
  }

  .snippet-block,
  .queue-block {
    margin-top: 18px;
  }
}
