:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #617083;
  --line: #d8dee7;
  --blue: #0b5cad;
  --blue-strong: #084a8d;
  --green: #147d64;
  --amber: #9a5b08;
  --red: #b42318;
  --shadow: 0 12px 30px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar,
.toolbar,
.list-meta,
.card-header,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: clamp(1.7rem, 2.2vw, 2.35rem);
}

h2 {
  font-size: 1.1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.status-badge.server {
  border-color: rgba(20, 125, 100, 0.32);
  color: var(--green);
}

.status-badge.local {
  border-color: rgba(154, 91, 8, 0.34);
  color: var(--amber);
}

.button,
.icon-button,
.command-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 700;
}

.button .fa-solid,
.button .fa-regular,
.icon-button .fa-solid,
.icon-button .fa-regular,
.command-button .fa-solid,
.command-button .fa-regular {
  flex: 0 0 auto;
  font-size: 0.95rem;
  line-height: 1;
}

.button-primary {
  background: var(--blue);
  color: #fff;
}

.button-primary:hover {
  background: var(--blue-strong);
}

.button-secondary {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}

.button-secondary:hover {
  border-color: #a9b4c2;
}

.button-danger {
  color: var(--red);
}

.button-delete {
  background: var(--red);
  color: #fff;
}

.button-delete:hover {
  background: #8f1c13;
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.toolbar {
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.input-wrap {
  display: block;
}

.search-wrap {
  flex: 1 1 360px;
}

.token-wrap {
  flex: 0 1 260px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: 0;
}

.command-field {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.command-field:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(11, 92, 173, 0.14);
}

.command-prefix {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  border-right: 1px solid var(--line);
  background: #f1f4f8;
  color: var(--blue);
  font-weight: 800;
}

.command-field input {
  border: 0;
  border-radius: 0;
}

.command-field input:focus {
  box-shadow: none;
}

input {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

.CodeMirror {
  height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.45;
}

.CodeMirror * {
  font-weight: 400;
}

.CodeMirror .cm-rich-bold {
  font-weight: 700;
}

.CodeMirror .cm-rich-italic {
  font-style: italic !important;
  font-synthesis: style;
}

.CodeMirror .cm-rich-underline {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.CodeMirror-focused {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(11, 92, 173, 0.14);
}

.CodeMirror-gutters {
  border-right: 1px solid var(--line);
  background: #f1f4f8;
}

.CodeMirror-linenumber {
  color: #738195;
}

.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
  padding: 0 10px;
}

.field:has(#noteInput) .CodeMirror {
  height: 160px;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(11, 92, 173, 0.14);
}

.list-meta {
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.93rem;
  margin: 10px 0 12px;
}

.canned-list {
  display: grid;
  gap: 14px;
}

.canned-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.02);
  overflow: hidden;
}

.card-header {
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.command-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  text-align: left;
  overflow-wrap: anywhere;
}

.command-button:hover {
  text-decoration: underline;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.icon-button:hover {
  border-color: #a9b4c2;
}

.icon-button.danger {
  color: var(--red);
}

.editor-preview {
  margin: 0;
  overflow: hidden;
  background: #fff;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.91rem;
  font-weight: 400;
  line-height: 1.45;
}

.canned-content {
  padding: 10px 0;
}

.editor-preview-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: start;
}

.editor-preview-number {
  align-self: stretch;
  padding: 0 10px 0 6px;
  border-right: 1px solid var(--line);
  background: #f1f4f8;
  color: #738195;
  text-align: right;
  user-select: none;
}

.editor-preview-text {
  min-width: 0;
  padding: 0 14px 0 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.private-note {
  border-top: 1px solid var(--line);
  padding: 0 14px 14px;
}

.private-note summary {
  width: max-content;
  margin: 10px 0;
  color: var(--amber);
  font-weight: 700;
  cursor: pointer;
}

.note-body {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #3d4754;
}

.empty-state {
  border: 1px dashed #a9b4c2;
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  color: var(--muted);
  text-align: center;
}

.editor-dialog {
  width: min(760px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.confirm-dialog {
  width: min(440px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.52);
}

.confirm-form {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  padding: 22px;
}

.confirm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fee4e2;
  color: var(--red);
  font-size: 1rem;
}

.confirm-content h2 {
  margin: 2px 0 8px;
}

.confirm-content p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.confirm-content strong {
  color: var(--text);
  overflow-wrap: anywhere;
}

.confirm-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.editor-form {
  max-height: calc(100dvh - 24px);
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.field input,
.field textarea {
  color: var(--text);
  font-weight: 400;
}

.dialog-actions {
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.format-toolbar,
.save-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.format-toolbar .icon-button {
  width: 38px;
  min-height: 38px;
  background: var(--surface-soft);
}

.format-toolbar .icon-button:hover,
.format-toolbar .icon-button:focus-visible {
  border-color: var(--blue);
  color: var(--blue);
}

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  z-index: 20;
  min-width: 230px;
  max-width: calc(100% - 32px);
  transform: translate(-50%, -12px);
  border-radius: 8px;
  padding: 13px 18px;
  background: #17202a;
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .search-wrap {
    flex-basis: 100%;
  }

  .token-wrap {
    flex: 1 1 220px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    margin-bottom: 16px;
  }

  .toolbar {
    align-items: stretch;
  }

  .search-wrap {
    flex-basis: 100%;
  }

  .toolbar > .button {
    margin-left: auto;
  }

  .card-header {
    align-items: center;
    padding: 10px;
  }

  .card-actions {
    gap: 6px;
  }

  .card-actions .icon-button {
    width: 38px;
    min-height: 38px;
  }

  .editor-preview-row {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .editor-preview-number {
    padding-right: 7px;
  }

  .editor-preview-text {
    padding-right: 10px;
    padding-left: 8px;
  }

  .editor-form {
    padding: 14px;
  }

  .confirm-form {
    padding: 18px;
  }
}

@media (max-width: 480px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar > .button {
    width: 100%;
    margin-left: 0;
  }

  .dialog-actions {
    align-items: flex-end;
  }

  .save-actions {
    margin-left: auto;
  }
}

@media (max-width: 360px) {
  .app-shell {
    width: min(100% - 16px, 1180px);
  }

  .card-header {
    gap: 8px;
  }

  .card-actions .icon-button {
    width: 36px;
    min-height: 36px;
  }

  .dialog-actions {
    align-items: stretch;
  }

  .save-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .confirm-form {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 12px;
    padding: 16px;
  }

  .confirm-icon {
    width: 38px;
    height: 38px;
  }
}

@media (max-height: 760px) {
  .CodeMirror {
    height: clamp(180px, 32dvh, 230px);
  }

  .field:has(#noteInput) .CodeMirror {
    height: clamp(90px, 17dvh, 130px);
  }

  .editor-form {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .field {
    margin-bottom: 10px;
  }

  .dialog-actions {
    margin-top: 12px;
  }
}
