*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f6f7fb;
  color: #1f2937;
}

.container {
  max-width: 1240px;
  margin: 24px auto;
  padding: 0 16px 32px;
}

.notes-layout {
  display: grid;
  grid-template-columns: 245px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  transition: grid-template-columns 0.22s ease, gap 0.22s ease;
}

.notes-layout.notes-layout-collapsed {
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
}

.filter-bar {
  position: sticky;
  top: 20px;
  transition: width 0.22s ease;
}

.filter-bar.filter-bar-collapsed {
  width: 44px;
}

.filter-bar-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid #dbe3f0;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
  transition: padding 0.22s ease, border-radius 0.22s ease, box-shadow 0.22s ease;
}

.filter-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.filter-bar-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.filter-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-toggle-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-bar-title {
  margin: 0;
  font-size: 1rem;
  color: #0f172a;
}

.filter-count {
  font-size: 0.78rem;
  color: #64748b;
}

.filter-bar-help {
  margin: 0 0 12px;
  color: #64748b;
  font-size: 0.88rem;
  line-height: 1.5;
}

.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-tag,
.filter-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-tag {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
}

.filter-tag:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.filter-tag-active {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1d4ed8;
}

.filter-tag-default {
  background: #f3f4f6;
  color: #4b5563;
}

.filter-tag-default.filter-tag-active {
  background: #e2e8f0;
  border-color: #94a3b8;
  color: #334155;
}

.filter-clear-btn,
.filter-toggle-btn,
.filter-collapsed-count {
  padding: 0;
  background: transparent;
  color: #2563eb;
  font-size: 0.85rem;
}

.filter-clear-btn {
  border-radius: 999px;
  padding: 6px 10px;
  color: #94a3b8;
}

.filter-collapsed-count {
  display: none;
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #2563eb;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 2px #ffffff;
}

.filter-clear-btn:hover,
.filter-toggle-btn:hover {
  color: #1d4ed8;
}

.filter-clear-btn:disabled {
  cursor: default;
  opacity: 1;
  color: #94a3b8;
}

.filter-clear-btn-active {
  background: #eff6ff;
  color: #2563eb;
}

.filter-toggle-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #2563eb;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.filter-toggle-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
}

.filter-bar-content {
  display: block;
  margin-top: 2px;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.filter-bar.filter-bar-collapsed .filter-bar-inner {
  align-items: center;
  padding: 10px 4px;
  border-radius: 999px;
}

.filter-bar.filter-bar-collapsed .filter-bar-header {
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.filter-bar.filter-bar-collapsed .filter-bar-heading,
.filter-bar.filter-bar-collapsed .filter-clear-btn {
  display: none !important;
}

.filter-bar:not(.filter-bar-collapsed) .filter-collapsed-count {
  display: none !important;
}

.filter-bar.filter-bar-collapsed .filter-bar-content {
  opacity: 0;
  transform: translateX(-6px);
  pointer-events: none;
  display: none !important;
}

.filter-bar.filter-bar-collapsed .filter-bar-actions {
  width: 100%;
  align-items: center;
  justify-content: center;
}

.filter-bar.filter-bar-collapsed .filter-toggle-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.notes-main {
  min-width: 0;
}

.notes-empty-state {
  padding: 18px;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  background: #f8fafc;
  color: #64748b;
  text-align: center;
}

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

.page-title {
  margin: 0;
}

.auth-area,
.logged-in-area,
.form-actions,
.login-actions,
.note-actions,
.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logged-in-area {
  display: none;
}

.sync-badge {
  color: #4caf50;
  font-weight: 500;
}

.note-form-shell {
  margin-bottom: 20px;
  border: 1px solid #d1d5db;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  overflow: hidden;
}

.note-form-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: #ffffff;
  color: #0f172a;
  text-align: left;
  transition: color 0.2s ease;
}

.note-form-trigger:hover {
  background: #ffffff;
}

.note-form-trigger-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.note-form-trigger-copy strong {
  font-size: 1rem;
}

.note-form-trigger-copy span {
  color: #64748b;
  font-size: 0.92rem;
  line-height: 1.45;
}

.note-form-trigger-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  color: #2563eb;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.note-form-trigger:hover .note-form-trigger-icon {
  background: #eff6ff;
  border-color: #93c5fd;
}

#note-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px 16px;
  max-height: 1400px;
  opacity: 1;
  overflow: hidden;
  background: #ffffff;
  transition: max-height 0.24s ease, opacity 0.18s ease, padding-top 0.24s ease, padding-bottom 0.24s ease;
}

.note-form-shell-collapsed #note-form {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

.note-form-shell:not(.note-form-shell-collapsed) .note-form-trigger {
  border-bottom: 1px solid #e5e7eb;
}

.note-form-shell:not(.note-form-shell-collapsed) .note-form-trigger-icon {
  transform: rotate(45deg);
}

.form-help {
  margin: 0;
  color: #6b7280;
  font-size: 0.95rem;
}

.tag-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tag-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tag-picker-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: #374151;
}

.tag-picker-help {
  font-size: 0.85rem;
  color: #6b7280;
}

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

.tag-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #f8fafc;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tag-option:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.tag-option input {
  margin: 0;
}

.tag-option-text {
  font-size: 0.9rem;
  font-weight: 500;
}

textarea.has-content {
  min-height: 60vh;
}

input[type="text"],
input[type="password"],
textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 12px;
  border: 1px solid #bbb;
  border-radius: 8px;
  font-size: 1.05rem;
  background: #fff;
}

#title {
  font-size: 1.3rem;
  font-weight: 600;
}

textarea {
  resize: vertical;
  min-height: 220px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

button {
  font-size: 0.9rem;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

button:hover {
  opacity: 0.94;
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.btn-primary {
  background: #4caf50;
  color: #fff;
}

.btn-primary:hover {
  background: #45a049;
}

.btn-danger {
  background: #f44336;
  color: #fff;
}

.btn-danger:hover {
  background: #da190b;
}

.btn-secondary {
  background: #9ca3af;
  color: #fff;
}

.btn-secondary:hover {
  background: #6b7280;
}

.btn-auth {
  background: #2563eb;
  color: #fff;
}

.btn-auth:hover {
  background: #1d4ed8;
}

.btn-note {
  background: #e3f2fd;
  color: #1976d2;
}

.btn-note:hover {
  background: #1976d2;
  color: #fff;
}

.btn-expand,
#show-more,
#show-less {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.btn-expand:hover,
#show-more:hover,
#show-less:hover {
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#show-more,
#show-less {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
}

.login-dialog {
  display: none;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid #c7d2fe;
  border-radius: 12px;
  background: #eef2ff;
}

.login-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.login-password {
  width: min(240px, 100%);
}

.login-error {
  color: #f44336;
  display: none;
}

.note {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.note:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.note-header:hover {
  background: #f5f5f5;
}

.note-heading {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
}

.note-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.1rem;
  color: #333;
  word-break: break-word;
}

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

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.82rem;
  font-weight: 600;
}

.tag-chip-actionable {
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.tag-chip-actionable:hover {
  background: #bfdbfe;
  color: #1e40af;
}

.tag-chip-actionable:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22);
}

.tag-chip-default {
  background: #e5e7eb;
  color: #4b5563;
}

.tag-chip-default.tag-chip-actionable:hover {
  background: #d1d5db;
  color: #374151;
}

.tag-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: currentColor;
  font-size: 0.85rem;
  line-height: 1;
}

.tag-chip-remove:hover {
  background: rgba(255, 255, 255, 0.95);
}

.note-content {
  display: none;
  margin-top: 12px;
  padding: 16px;
  background: #fafafa;
  border-radius: 8px;
  border-left: 4px solid #667eea;
}

.note-content.expanded {
  display: block;
}

.note-tag-editor-host {
  display: none;
  margin-top: 12px;
}

.note-tag-editor-host:empty {
  margin-top: 0;
}

.note-tag-editor-host-open {
  display: block;
}

.note-tag-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #dbe3f0;
  border-radius: 12px;
  background: #f8fbff;
}

.note-tag-editor-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
}

.note-tag-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.note-meta {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 16px;
}

.note-updated {
  color: #6b7280;
  font-size: 0.85rem;
}

.note-actions {
  flex-shrink: 0;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: block;
}

.modal-content {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(90%, 900px);
  max-height: 80vh;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 32px;
  z-index: 1001;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-title {
  color: #111827;
  margin: 0 0 20px;
  padding-right: 80px;
  padding-bottom: 16px;
  border-bottom: 1px solid #dbe3f0;
  word-break: break-word;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.modal-edit-shell {
  display: flex;
  flex-direction: column;
}

.modal-edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-edit-form .tag-picker {
  padding: 0;
}

.modal-edit-actions {
  justify-content: flex-end;
}

.modal-edit-form textarea {
  min-height: 320px;
}

.markdown-body {
  color: #374151;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

#modal-body .markdown-body {
  margin-top: 4px;
  padding: 20px 22px;
  border-radius: 14px;
  background: #eef3f8;
  border: 1px solid #dde6f0;
}

#modal-body .markdown-body pre {
  background: #0f172a;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.16);
}

#modal-body .markdown-body :not(pre) > code {
  background: #dbe7f3;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  color: #111827;
  line-height: 1.3;
  margin: 1.2em 0 0.6em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0 0 1em;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.5rem;
}

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

.markdown-body a:hover {
  color: #1d4ed8;
}

.markdown-body blockquote {
  margin-left: 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid #c7d2fe;
  background: #eef2ff;
  color: #4338ca;
}

.markdown-body :not(pre) > code {
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  background: #e5e7eb;
  color: #111827;
  font-size: 0.95em;
}

.code-block-shell {
  position: relative;
}

.markdown-body pre {
  padding: 0;
  border-radius: 10px;
  overflow-x: auto;
  background: #f8fafc;
}

.markdown-body pre code {
  display: block;
  padding: 16px;
  padding-right: 96px;
  min-width: max-content;
  line-height: 1.6;
}

.code-copy-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  padding: 5px 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
  font-size: 0.78rem;
  line-height: 1.2;
  backdrop-filter: blur(4px);
}

.code-copy-button:hover {
  background: rgba(30, 41, 59, 0.94);
}

.code-copy-button-success {
  background: rgba(22, 163, 74, 0.9);
  color: #f0fdf4;
}

.code-copy-button-error {
  background: rgba(220, 38, 38, 0.9);
  color: #fef2f2;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid #d1d5db;
  margin: 1.25rem 0;
}

.markdown-empty {
  color: #9ca3af;
  font-style: italic;
}

@media (max-width: 900px) {
  .container {
    padding: 0 12px 24px;
  }

  .notes-layout,
  .notes-layout.notes-layout-collapsed {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .filter-bar,
  .filter-bar.filter-bar-collapsed {
    position: static;
    width: auto;
  }

  .filter-bar-inner,
  .filter-bar.filter-bar-collapsed .filter-bar-inner {
    padding: 14px;
    border-radius: 14px;
  }

  .filter-bar-header,
  .filter-bar.filter-bar-collapsed .filter-bar-header {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    gap: 10px;
  }

  .filter-bar-actions,
  .filter-bar.filter-bar-collapsed .filter-bar-actions {
    width: auto;
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    gap: 10px;
  }

  .filter-toggle-btn {
    display: none;
  }

  .filter-bar-heading,
  .filter-bar.filter-bar-collapsed .filter-bar-heading {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .filter-bar.filter-bar-collapsed .filter-bar-title {
    writing-mode: initial;
    transform: none;
    letter-spacing: normal;
    font-size: 1rem;
    color: #0f172a;
  }

  .filter-bar.filter-bar-collapsed .filter-count {
    display: inline !important;
  }

  .filter-bar.filter-bar-collapsed .filter-clear-btn {
    display: inline-flex !important;
  }

  .filter-bar.filter-bar-collapsed .filter-bar-content {
    display: block !important;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .filter-collapsed-count {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .page-header,
  .note-header,
  .note-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .filter-bar-header {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    gap: 10px;
  }

  .note-header {
    gap: 14px;
  }

  .note-heading {
    width: 100%;
    gap: 8px;
  }

  .page-title {
    font-size: 1.6rem;
  }

  .note-form-trigger {
    padding: 14px;
    align-items: flex-start;
  }

  #note-form,
  .note,
  .note-content {
    padding: 12px;
  }

  .note {
    margin-bottom: 12px;
  }

  .note-actions,
  .form-actions,
  .login-actions,
  .note-tag-editor-actions,
  .filter-options {
    flex-wrap: wrap;
  }

  .form-actions,
  .note-actions,
  .note-tag-editor-actions {
    width: 100%;
  }

  .note-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 2px;
  }

  .note-actions button {
    width: 100%;
    justify-content: center;
  }

  .form-actions button,
  .note-tag-editor-actions button {
    flex: 1 1 calc(50% - 4px);
  }

  .filter-options,
  .tag-picker-options,
  .tag-list {
    gap: 6px;
  }

  .note-title {
    font-size: 1rem;
  }

  .filter-tag,
  .tag-option,
  .tag-chip {
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .tag-picker-header {
    align-items: flex-start;
    flex-direction: column;
  }

  textarea {
    min-height: 220px;
  }

  textarea.has-content {
    min-height: 50vh;
  }

  .modal-content {
    width: calc(100% - 20px);
    padding: 20px 14px;
  }

  .modal-title {
    padding-right: 48px;
    margin-bottom: 16px;
    padding-bottom: 12px;
  }

  #modal-body .markdown-body {
    padding: 16px 14px;
  }
}
