*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }

.item-title { user-select: text; }

@media (hover: none) {
  * { scrollbar-width: none; }
  *::-webkit-scrollbar { display: none; }
}

html {
  overscroll-behavior: none;
}

body {
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #37352f;
  background: #fff;
  overscroll-behavior: none;
  min-height: 100dvh;
}

#app {
  padding: 9px 0 0;
}
@media (max-width: 600px) {
  #app { padding: 0; }
}


/* ── Header ── */
header {
  margin-bottom: 21px;
  padding: 9px 0;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 100;
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.content {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 40px 16px;
}

@media (max-width: 600px) {
  .header-inner { padding: 0 16px; }
  .content { padding: 0 16px; }
}

.site-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #37352f;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sync-status {
  font-size: 12px;
  color: rgba(55,53,47,0.4);
  margin-right: 6px;
}
.sync-status.error { color: #e03e3e; }

.btn-new, .btn-gear {
  background: rgba(55,53,47,0.04);
  border: none;
  cursor: pointer;
  font-family: inherit;
  height: 32px;
  padding: 0 14px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.btn-new {
  font-size: 13px;
  font-weight: 500;
  color: rgba(55,53,47,0.65);
}
.btn-gear {
  color: rgba(55,53,47,0.4);
  padding: 0;
  width: 32px;
  font-size: 16px;
  line-height: 1;
}
.btn-new:hover, .btn-gear:hover { background: rgba(55,53,47,0.08); color: #37352f; }

/* ── Add form ── */
.add-form {
  border: 1px solid rgba(55,53,47,0.12);
  border-radius: 6px;
  padding: 16px 18px;
  margin-bottom: 20px;
}

.status-picker {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}

.spick {
  background: rgba(55,53,47,0.08);
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 4px;
  color: rgba(55,53,47,0.5);
  transition: background 0.1s, color 0.1s;
}
.spick:hover { background: rgba(55,53,47,0.14); color: #37352f; }
.spick.sel   { background: #37352f; color: #fff; }

.add-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.add-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: inherit;
  color: #37352f;
  background: transparent;
  padding: 6px 0;
}
.add-input::placeholder { color: rgba(55,53,47,0.3); }

.add-btns { display: flex; gap: 6px; margin-top: 16px; }

.btn-submit {
  background: #37352f;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  transition: background 0.1s;
}
.btn-submit:hover { background: #555450; }

.btn-dismiss {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: rgba(55,53,47,0.5);
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  transition: background 0.1s, color 0.1s;
}
.btn-dismiss:hover { background: rgba(55,53,47,0.08); color: #37352f; }

/* ── Sections ── */
.section { margin-bottom: 20px; }

.page-end {
  text-align: center;
  color: rgba(55,53,47,0.2);
  font-size: 20px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  margin-left: -6px;
  margin-right: -6px;
  margin-bottom: 2px;
  border-radius: 4px;
  cursor: default;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgba(55,53,47,0.5);
}

.section-count {
  font-size: 11px;
  color: rgba(55,53,47,0.3);
}

.section-empty {
  padding: 12px 6px;
  margin-left: -6px;
  margin-right: -6px;
  font-size: 13px;
  color: rgba(55,53,47,0.3);
}

.section.section-drag-over {
  outline: 2px dashed rgba(55,53,47,0.25);
  outline-offset: 7px;
  border-radius: 6px;
}

/* ── Items ── */
.item {
  display: flex;
  align-items: center;
  padding: 3px 6px;
  margin-left: -6px;
  margin-right: -6px;
  border-radius: 4px;
  min-height: 34px;
  gap: 6px;
}
.item:hover { background: rgba(55,53,47,0.04); }

.item.dragging { opacity: 0.4; }
.item { position: relative; isolation: isolate; }
.item.drag-over-top::before,
.item.drag-over-bottom::after {
  content: '';
  position: absolute;
  left: 6px; right: 0;
  height: 2px;
  background: #37352f;
  border-radius: 0;
}
.item.drag-over-top::before    { top: -1px; }
.item.drag-over-bottom::after  { bottom: -1px; }

.item-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.item-title {
  font-size: 14px;
  color: #37352f;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.item-title.is-truncated {
  text-overflow: clip;
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(to right, black calc(100% - 16px), transparent 100%);
}
.item-title[contenteditable] { flex: 1; outline: none; cursor: text; border-bottom: 1.5px solid rgba(55,53,47,0.3); }
.btn-title-edit {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: rgba(55,53,47,0.25);
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  margin-left: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}
.btn-title-edit:hover { background: rgba(55,53,47,0.08); color: #37352f; }
.btn-title-done {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: rgba(55,53,47,0.4);
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  margin-left: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}
.btn-title-done:hover { background: rgba(55,53,47,0.08); color: #37352f; }

.btn-expand {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  color: rgba(55,53,47,0.4);
  padding: 0;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  font-family: inherit;
  border-radius: 3px;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
}
.btn-expand:hover { color: #37352f; background: rgba(55,53,47,0.06); }

.title-popup {
  position: fixed;
  background: #fff;
  border: 1px solid rgba(55,53,47,0.15);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  color: #37352f;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 1000;
  user-select: text;
  word-break: break-word;
}

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

.item-del {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: rgba(55,53,47,0.4);
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.item-del:hover { background: rgba(235,87,87,0.1); color: #e03e3e; }
.item-del.pending { color: #e03e3e; width: auto; padding: 0 6px; }

.drag-handle {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(55,53,47,0.3);
  cursor: grab;
  user-select: none;
  font-size: 13px;
  line-height: 1;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }

/* ── Setup ── */
.setup-card {
  border: 1px solid rgba(55,53,47,0.12);
  border-radius: 6px;
  padding: 28px;
}

.setup-head {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
  color: #37352f;
}

.setup-desc {
  font-size: 13px;
  color: rgba(55,53,47,0.55);
  line-height: 1.65;
  margin-bottom: 24px;
}

.field { margin-bottom: 16px; }

.field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgba(55,53,47,0.5);
  display: block;
  margin-bottom: 6px;
}

.field input {
  display: block;
  width: 100%;
  border: 1px solid rgba(55,53,47,0.16);
  border-radius: 4px;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  color: #37352f;
  background: #fff;
  padding: 7px 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: rgba(35,131,226,0.5);
  box-shadow: 0 0 0 3px rgba(35,131,226,0.18);
}
.field input::placeholder { color: rgba(55,53,47,0.3); }

.setup-btns {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-connect {
  background: #37352f;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  transition: background 0.1s;
}
.btn-connect:hover { background: #555450; }

.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: rgba(55,53,47,0.5);
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  transition: background 0.1s, color 0.1s;
}
.btn-back:hover { background: rgba(55,53,47,0.08); color: #37352f; }

.setup-msg {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.5;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: rgba(55,53,47,0.4);
}

/* ── Tags ── */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
}

.tag-cloud-label {
  font-size: 11px;
  color: rgba(55,53,47,0.35);
  margin-right: 2px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(55,53,47,0.08);
  color: rgba(55,53,47,0.65);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}
.tag:hover  { background: rgba(55,53,47,0.14); color: #37352f; }
.tag.active { background: #37352f; color: #fff; }

.item-tags {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.item-tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 3px;
  background: rgba(55,53,47,0.07);
  color: rgba(55,53,47,0.55);
  white-space: nowrap;
}
.item-tag.active { background: #37352f; color: #fff; }

.btn-tag-edit {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: rgba(55,53,47,0.25);
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}
.btn-tag-edit:hover { background: rgba(55,53,47,0.08); color: #37352f; }

@media (hover: hover) {
  .item { margin-left: -28px; padding-left: 28px; }
  .item:hover { background: none; }
  .item:hover:not(.drag-over-top):not(.drag-over-bottom)::after {
    content: '';
    position: absolute;
    left: 22px; right: 0; top: 0; bottom: 0;
    background: rgba(55,53,47,0.04);
    border-radius: 4px;
    z-index: -1;
  }
  .item.drag-over-top::before,
  .item.drag-over-bottom::after { left: 28px; }
  .item-btns, .drag-handle { display: none; }
  .item:hover .item-btns, .item.del-pending .item-btns { display: flex; }
  .item:hover .drag-handle, .item.del-pending .drag-handle { display: inline; }
  .item.del-pending:not(.drag-over-top):not(.drag-over-bottom)::after {
    content: '';
    position: absolute;
    left: 22px; right: 0; top: 0; bottom: 0;
    background: rgba(55,53,47,0.04);
    border-radius: 4px;
    z-index: -1;
  }
}
@media (hover: none) {
  header { background: #fff; border-bottom: 1px solid rgba(55,53,47,0.1); }
  .item-btns, .drag-handle { display: none; }
  .item.touch-sel .item-btns { display: flex; }
  .item.touch-sel .drag-handle { display: inline-flex; position: static; transform: none; top: auto; }
  .item.touch-sel { touch-action: none; }
}

.tag-edit-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-edit-label {
  font-size: 11px;
  color: rgba(55,53,47,0.35);
  flex-shrink: 0;
}

.item:has(.tag-edit-input) .item-title-wrap { display: none; }
.item:has(.tag-edit-input) .tag-edit-wrap { flex: 1; }

.tag-edit-input {
  flex: 1;
  border: none;
  outline: none;
  border-bottom: 1.5px solid rgba(55,53,47,0.3);
  background: none;
  font-size: 14px;
  font-family: inherit;
  color: #37352f;
  padding: 2px 0;
}

.btn-tag-save {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: rgba(55,53,47,0.4);
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}
.btn-tag-save:hover { background: rgba(55,53,47,0.08); color: #37352f; }

.add-tags-input-row {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.add-tags-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 12px;
  font-family: inherit;
  color: #37352f;
  background: transparent;
  padding: 0;
}
.add-tags-input::placeholder { color: rgba(55,53,47,0.25); }

.add-tags-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 0;
  margin-bottom: 0;
  cursor: text;
}
