:root {
  --bg: #000000;
  --sidebar-bg: #161616;
  --panel-bg: #111111;
  --border: #2a2a2a;
  --text: #f2f2f2;
  --text-dim: #8a8a8e;
  --accent: #3d8bff;
  --danger: #ff453a;
  --tab-active: #2c2c2e;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", Roboto, sans-serif;
}

/* ---------- login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  width: 320px;
  max-width: 90vw;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.login-card .subtitle {
  margin: 0 0 12px;
  color: var(--text-dim);
  font-size: 14px;
}

.login-card input {
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  color: var(--text);
  font-size: 16px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button {
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:hover {
  filter: brightness(1.1);
}

.login-card .error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

.login-card .switch-mode {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card .switch-mode a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 4px;
}

.login-card .switch-mode a:hover {
  text-decoration: underline;
}

/* ---------- app layout ---------- */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 12px;
}

.sidebar-header h2 {
  font-size: 17px;
  margin: 0;
}

.sidebar-header-actions {
  display: flex;
  gap: 2px;
}

.sidebar-search {
  padding: 0 8px 10px;
}

.import-status {
  margin: -6px 8px 10px;
  color: var(--text-dim);
  font-size: 12px;
}

.sidebar-search input {
  width: 100%;
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
}

.sidebar-search input:focus {
  outline: none;
  border-color: var(--accent);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  line-height: 1;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.08);
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.note-list li {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 15px;
  margin-bottom: 2px;
}

.note-list li:hover {
  background: rgba(255,255,255,0.06);
}

.note-list li.active {
  background: var(--tab-active);
  color: var(--text);
  font-weight: 600;
}

.note-list li.dragging {
  opacity: 0.4;
}

.note-list-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.note-list-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  padding: 2px 6px;
}

.note-list-time {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
  opacity: 0.7;
}

.note-list li.search-empty,
.note-list li.trash-empty {
  cursor: default;
  color: var(--text-dim);
}

.trash-item {
  flex-direction: row !important;
  align-items: center;
}

.trash-action {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 13px;
}

.trash-action:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.trash-action.trash-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.username-label {
  color: var(--text-dim);
  font-size: 13px;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  font-size: 14px;
}

.logout-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* ---------- content ---------- */
.content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
}

.hidden {
  display: none !important;
}

.note-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 20px 24px;
  overflow: hidden;
}

.note-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.back-btn {
  font-size: 26px;
}

.note-title-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  padding: 4px 6px;
}

.note-title-input:focus {
  outline: none;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
}

.note-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 20px;
  align-items: stretch;
}

.block-list {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding-bottom: 12px;
  padding-right: 4px;
}

@media (min-width: 960px) {
  .block-list.two-col {
    column-count: 2;
    column-gap: 24px;
  }
}

.empty-hint {
  color: var(--text-dim);
}

.block-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-radius: 8px;
  break-inside: avoid;
}

.block-control {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: transparent;
}

.block-row.checked .block-checkbox {
  background: var(--text-dim);
  border-color: var(--text-dim);
  color: #000;
}

.block-row.type-text .block-control {
  display: none;
}

.block-text {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 17px;
  padding: 4px 6px;
  font-family: inherit;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.block-text:focus {
  outline: none;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
}

.block-text.is-empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
}

.block-row.checked .block-text {
  color: var(--text-dim);
  text-decoration: line-through;
}

.block-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.block-toggle-type,
.block-delete {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  font-size: 15px;
}

.block-toggle-type {
  color: var(--text-dim);
}

.block-delete {
  color: var(--danger);
}

.block-row:hover .block-toggle-type,
.block-row:hover .block-delete {
  opacity: 0.7;
}

.block-toggle-type:hover,
.block-delete:hover {
  opacity: 1 !important;
}

/* right-hand action rail — a sibling of the (independently scrolling)
   block-list, so it never scrolls out of view no matter how long the note is */
.note-actions {
  flex-shrink: 0;
  width: 168px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

#columnsBtn {
  display: none;
}

@media (min-width: 960px) {
  #columnsBtn {
    display: flex;
  }
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}

.toolbar-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.toolbar-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

.toolbar-icon {
  font-size: 16px;
}

/* ---------- new-note type picker modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  width: 320px;
  max-width: 90vw;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.modal-card h3 {
  margin: 0;
  font-size: 18px;
}

.modal-card p {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 14px;
}

.modal-card input {
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font-size: 14px;
  text-align: left;
}

.modal-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-error {
  min-height: 16px;
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  text-align: left;
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  cursor: pointer;
}

.modal-option:hover {
  border-color: var(--accent);
}

.modal-cancel {
  margin-top: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
}

.modal-cancel:hover {
  color: var(--text);
}

/* ---------- floating rich-text format toolbar ---------- */
.format-toolbar {
  position: fixed;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 2px;
  background: #202022;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.format-toolbar button {
  background: none;
  border: none;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.format-toolbar button:hover {
  background: rgba(255,255,255,0.1);
}

.format-toolbar button.active {
  background: var(--accent);
  color: #fff;
}

.format-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.size-btn.size-sm {
  font-size: 12px;
}

.size-btn.size-md {
  font-size: 16px;
}

.size-btn.size-lg {
  font-size: 20px;
}

.color-btn {
  font-size: 20px !important;
  line-height: 1;
}

@media (max-width: 720px) {
  .app {
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    padding: max(16px, env(safe-area-inset-top)) 16px 16px;
    transition: transform 0.28s ease;
  }

  .sidebar-header h2 {
    font-size: 20px;
  }

  .note-list li {
    padding: 16px 14px;
    font-size: 16px;
  }

  .content {
    width: 100%;
  }

  .app.note-open .sidebar {
    transform: translateX(-100%);
  }

  .note-view {
    padding: max(8px, env(safe-area-inset-top)) 16px 24px;
    max-width: none;
  }

  .note-title-input {
    font-size: 20px;
  }

  .back-btn {
    font-size: 30px;
    padding: 4px 10px;
  }

  .block-row {
    padding: 10px 2px;
  }

  .block-checkbox {
    width: 26px;
    height: 26px;
  }

  .block-text {
    font-size: 16px;
  }

  .block-toggle-type,
  .block-delete {
    opacity: 0.6;
    font-size: 19px;
    padding: 8px 8px;
  }

  .logout-btn {
    padding: 14px 16px;
  }

  .note-body {
    flex-direction: column;
    gap: 0;
  }

  .note-actions {
    flex-direction: row;
    flex-wrap: wrap;
    width: auto;
    padding-left: 0;
    padding-top: 12px;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .note-actions .toolbar-btn {
    width: auto;
    flex: 1 1 auto;
    justify-content: center;
    padding: 14px 16px;
  }
}
