:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111827;
  background: #f3f4f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f3f4f6;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.card {
  background: white;
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 20px 40px rgb(17 24 39 / 10%);
}

h1 {
  margin: 0 0 8px;
  font-size: 32px;
}

.muted {
  color: #6b7280;
  margin: 0 0 18px;
}

.form {
  display: grid;
  gap: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  background: white;
}

textarea {
  min-height: 460px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: #111827;
}

button {
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: #111827;
  color: white;
  transition: 0.15s ease;
}

button:hover {
  opacity: 0.92;
}

button.secondary {
  background: #e5e7eb;
  color: #111827;
}

button.small {
  padding: 10px 12px;
  font-size: 14px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.top-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.category-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

#categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.category-button {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: #e5e7eb;
  color: #111827;
  cursor: pointer;
  font-weight: 600;
}

.category-button.active {
  background: #111827;
  color: white;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin: 16px 0 20px;
}

.notes-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.notes-sidebar {
  display: grid;
  gap: 12px;
  min-width: 0;
}

ul {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.note {
  display: grid;
  gap: 6px;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 12px;
  background: white;
}

.note.active {
  border-color: #111827;
  background: #f9fafb;
}

.note-open-button {
  padding: 0;
  background: transparent;
  color: #111827;
  text-align: left;
  border-radius: 0;
  font-size: 16px;
  font-weight: 800;
}

.note-meta {
  color: #6b7280;
  font-size: 13px;
}

.editor {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.editor-layout {
  display: block;
  min-width: 0;
}

.editor-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.markdown-preview {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 16px;
  overflow-x: auto;
  overflow-y: auto;
  background: white;
  min-height: 460px;
  max-height: 70vh;
  line-height: 1.7;
  word-break: break-word;
}

.markdown-preview * {
  max-width: 100%;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 {
  margin-top: 24px;
  margin-bottom: 12px;
  line-height: 1.25;
}

.markdown-preview h1:first-child,
.markdown-preview h2:first-child,
.markdown-preview h3:first-child,
.markdown-preview h4:first-child {
  margin-top: 0;
}

.markdown-preview p {
  line-height: 1.7;
  margin: 0 0 16px;
}

.markdown-preview ul,
.markdown-preview ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.markdown-preview li {
  margin-bottom: 6px;
}

.markdown-preview pre {
  background: #111827;
  color: white;
  padding: 14px;
  border-radius: 12px;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre;
}

.markdown-preview code {
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.markdown-preview pre code {
  white-space: pre;
  word-break: normal;
}

.markdown-preview blockquote {
  border-left: 4px solid #d1d5db;
  margin-left: 0;
  padding-left: 16px;
  color: #4b5563;
}

.markdown-preview table {
  border-collapse: collapse;
  width: 100%;
  overflow-x: auto;
  display: block;
}

.markdown-preview th,
.markdown-preview td {
  border: 1px solid #d1d5db;
  padding: 8px 12px;
}

.markdown-preview a {
  color: #2563eb;
}

.markdown-preview img {
  border-radius: 12px;
  display: block;
}

.danger-button {
  background: #dc2626;
}

.danger-button:hover {
  background: #b91c1c;
}

.password-wrapper {
  display: flex;
  gap: 8px;
}

.password-wrapper input {
  flex: 1;
}

#toggle-password {
  width: 56px;
  padding: 0;
}

.message {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: 20px;
  max-width: 720px;
  margin: 0 auto;
  background: #111827;
  color: white;
  padding: 14px 16px;
  border-radius: 14px;
  text-align: center;
  z-index: 1000;
}

.center {
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .notes-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app {
    padding: 12px;
  }

  .card {
    padding: 18px;
    border-radius: 20px;
  }

  h1 {
    font-size: 28px;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .editor-actions {
    flex-direction: column;
  }

  textarea,
  .markdown-preview {
    min-height: 360px;
  }
}
