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

:root {
  --primary: #4A7C59;
  --primary-dark: #2D5A3D;
  --primary-light: #EBF4EE;
  --oak: #7B5B3A;
  --bg: #F5F2EC;
  --card: #FFFFFF;
  --sidebar-bg: #FAFAF7;
  --text: #252525;
  --text-muted: #9A9A9A;
  --text-checked: #C0C0C0;
  --border: #E4DDD0;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  --radius: 14px;
  --indent: 28px;
  --cb-size: 20px;
  --sidebar-w: 220px;
  --header-h: 52px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Brand ── */
.brand-logo { display: inline-flex; align-items: baseline; }
.brand-logo .brand-oak { color: var(--oak); font-weight: 800; font-size: 1.9rem; letter-spacing: -0.5px; }
.brand-logo .brand-ay  { color: var(--primary); font-weight: 800; font-size: 1.9rem; letter-spacing: -0.5px; }
.brand-logo.small .brand-oak,
.brand-logo.small .brand-ay { font-size: 1.3rem; }

/* ── Auth ── */
#auth-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-wrap { width: 100%; max-width: 380px; text-align: center; }
.brand-tagline { color: var(--text-muted); font-size: 0.875rem; margin: 6px 0 28px; }

.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-card);
  text-align: left;
}
.auth-card h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; }
.auth-card input {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.9rem; font-family: inherit; color: var(--text);
  background: #FAFAF8; outline: none; transition: border-color 0.15s;
}
.auth-card input:focus { border-color: var(--primary); background: #fff; }
.auth-card input::placeholder { color: var(--text-muted); }
.auth-card button[type=submit] {
  padding: 11px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 600;
  font-family: inherit; cursor: pointer; margin-top: 4px;
  transition: background 0.15s;
}
.auth-card button[type=submit]:hover { background: var(--primary-dark); }
.auth-switch { text-align: center; margin-top: 14px; font-size: 0.82rem; color: var(--text-muted); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* ── Header ── */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 0.82rem; color: var(--text-muted); }

.btn-ghost {
  background: none; border: 1.5px solid var(--border);
  padding: 5px 12px; border-radius: 6px; font-size: 0.8rem;
  font-family: inherit; cursor: pointer; color: var(--text-muted);
  transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--primary-light); color: var(--primary); }

/* ── App layout ── */
.app-body {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px 8px;
  transition: margin-left 0.2s ease;
}
.sidebar.hidden { margin-left: calc(-1 * var(--sidebar-w)); }

.new-list-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.82rem; font-family: inherit;
  border-radius: 8px; text-align: left; margin-bottom: 4px;
  transition: background 0.15s, color 0.15s;
}
.new-list-btn:hover { background: var(--primary-light); color: var(--primary); }
.new-list-btn svg { flex-shrink: 0; stroke: currentColor; }

.list-nav { display: flex; flex-direction: column; gap: 1px; }

.list-item {
  display: flex; align-items: center;
  padding: 7px 10px; border-radius: 8px;
  cursor: pointer; color: var(--text-muted);
  font-size: 0.85rem; gap: 6px;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.list-item:hover { background: var(--border); color: var(--text); }
.list-item:hover .list-del { opacity: 1; }
.list-item.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }

.list-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; flex-shrink: 0; opacity: 0.6;
}
.list-item.active .list-dot { opacity: 1; }

.list-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list-rename-input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 0.85rem; font-family: inherit; color: var(--text);
  padding: 0; min-width: 0;
}

.list-del {
  opacity: 0; background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px 4px; border-radius: 4px;
  font-size: 1rem; line-height: 1; flex-shrink: 0;
  transition: opacity 0.15s, color 0.15s;
}
.list-del:hover { color: #D04040; }

/* ── Main ── */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 80px;
}

.note-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: visible;
  max-width: 660px;
  margin: 0 auto;
}

.note-header {
  padding: 16px 20px 0;
  border-bottom: 1px solid var(--border);
}
.note-title {
  font-size: 1rem; font-weight: 600; color: var(--text);
  outline: none; padding: 0 0 13px; min-height: 38px;
}
.note-title:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted); font-weight: 400; pointer-events: none;
}

/* ── Todo list ── */
.todo-list {
  padding: 6px 0;
  min-height: 40px;
  position: relative; /* for drop-line */
}

.todo-item {
  display: flex;
  align-items: flex-start;
  position: relative;
  padding: 1px 8px 1px 12px;
  transition: background 0.1s;
  touch-action: pan-y; /* allow vertical scroll; horizontal captured for drag */
}
.todo-item:hover { background: #FAFAF8; }
.todo-item:hover .grip { opacity: 1; }
.todo-item:hover .delete-btn { opacity: 1; }
.todo-item.dragging { opacity: 0.35; }
.todo-item.drag-over { background: var(--primary-light); }

/* Depth indentation */
.todo-item[data-depth="0"] { padding-left: 12px; }
.todo-item[data-depth="1"] { padding-left: calc(12px + var(--indent) * 1); }
.todo-item[data-depth="2"] { padding-left: calc(12px + var(--indent) * 2); }
.todo-item[data-depth="3"] { padding-left: calc(12px + var(--indent) * 3); }
.todo-item[data-depth="4"] { padding-left: calc(12px + var(--indent) * 4); }
.todo-item[data-depth="5"] { padding-left: calc(12px + var(--indent) * 5); }
.todo-item[data-depth="6"] { padding-left: calc(12px + var(--indent) * 6); }
.todo-item[data-depth="7"] { padding-left: calc(12px + var(--indent) * 7); }

/* Depth guide lines */
.todo-item[data-depth="1"]::before { left: calc(12px + var(--indent) * 1 - 14px); }
.todo-item[data-depth="2"]::before { left: calc(12px + var(--indent) * 2 - 14px); }
.todo-item[data-depth="3"]::before { left: calc(12px + var(--indent) * 3 - 14px); }
.todo-item[data-depth="4"]::before { left: calc(12px + var(--indent) * 4 - 14px); }
.todo-item[data-depth="5"]::before { left: calc(12px + var(--indent) * 5 - 14px); }
.todo-item[data-depth="6"]::before { left: calc(12px + var(--indent) * 6 - 14px); }
.todo-item[data-depth="7"]::before { left: calc(12px + var(--indent) * 7 - 14px); }
.todo-item[data-depth]:not([data-depth="0"])::before {
  content: ''; position: absolute; top: 0; bottom: 0;
  width: 1.5px; background: var(--border); border-radius: 1px;
}

/* ── Grip ── */
.grip {
  flex-shrink: 0;
  width: 16px;
  height: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  opacity: 0;
  color: var(--text-muted);
  border-radius: 3px;
  transition: opacity 0.15s, color 0.12s;
  user-select: none;
  margin-right: 4px;
}
.grip:active { cursor: grabbing; }
.grip:hover { color: var(--primary); }
.grip svg { display: block; width: 10px; height: 16px; }

/* ── Checkbox ── */
.cb {
  flex-shrink: 0;
  width: var(--cb-size);
  height: var(--cb-size);
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  transition: border-color 0.15s, background 0.15s;
  color: #fff;
}
.cb:hover { border-color: var(--primary); }
.cb.is-checked { background: var(--primary); border-color: var(--primary); }
.cb svg { width: 11px; height: 11px; display: block; }

/* ── Item text ── */
.item-text {
  flex: 1;
  min-height: 36px;
  padding: 7px 6px 7px 8px;
  font-size: 0.925rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
}
.item-text:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted); pointer-events: none;
}
.todo-item.is-checked .item-text {
  color: var(--text-checked);
  text-decoration: line-through;
}

/* ── Delete button ── */
.delete-btn {
  flex-shrink: 0;
  opacity: 0;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 6px;
  margin-top: 4px; transition: color 0.15s, background 0.15s, opacity 0.15s;
  display: flex; align-items: center;
}
.delete-btn:hover { color: #D04040; background: #FFF0F0; }
.delete-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Drop line ── */
.drop-line {
  position: absolute;
  height: 2px;
  background: var(--primary);
  right: 8px;
  display: none;
  pointer-events: none;
  border-radius: 2px;
  z-index: 50;
}
.drop-line::before {
  content: '';
  position: absolute;
  left: -4px; top: -3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

/* ── Add item button ── */
.add-item-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 10px 16px;
  background: none; border: none; border-top: 1px solid var(--border);
  cursor: pointer; color: var(--text-muted); font-size: 0.875rem;
  font-family: inherit; text-align: left; transition: color 0.15s, background 0.15s;
}
.add-item-btn:hover { color: var(--primary); background: var(--primary-light); }
.add-item-btn svg { flex-shrink: 0; stroke: currentColor; }

/* ── Empty state ── */
.empty-hint {
  text-align: center; padding: 24px 16px;
  color: var(--text-muted); font-size: 0.875rem;
}

/* ── Hints ── */
.hints {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  justify-content: center; margin-top: 14px;
  font-size: 0.72rem; color: var(--text-muted);
  max-width: 660px; margin-left: auto; margin-right: auto;
}
.hints kbd {
  display: inline-block; background: var(--card);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-family: inherit; font-size: 0.68rem;
  box-shadow: 0 1px 0 var(--border);
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #2C3040; color: #fff;
  padding: 10px 20px; border-radius: 8px; font-size: 0.875rem;
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 400px; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── No lists state ── */
.no-lists-hint {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted); font-size: 0.875rem;
  max-width: 660px; margin: 0 auto;
}
.no-lists-hint strong { display: block; margin-bottom: 6px; font-size: 1rem; }

/* ── Drag ghost ── */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  background: var(--card);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  border-left: 3px solid var(--primary);
  padding: 8px 16px;
  font-size: 0.925rem;
  color: var(--text);
  max-width: 380px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: rotate(-1.5deg);
  opacity: 0.9;
}

/* ── Sidebar backdrop (mobile tap-away) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 19;
  background: rgba(0,0,0,0.35);
}
.sidebar-backdrop.visible { display: block; }

/* ── Responsive ── */
@media (max-width: 600px) {
  :root { --sidebar-w: 200px; }
  .sidebar { position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 20; box-shadow: 2px 0 12px rgba(0,0,0,0.1); }
  .sidebar.hidden { margin-left: calc(-1 * var(--sidebar-w)); }
  .app-main { padding: 16px 12px 60px; }
  .hints { display: none; }
  /* grip always subtly visible on touch devices */
  .grip { opacity: 0.25; }
  .todo-item:hover .grip { opacity: 0.25; }
}

/* On desktop, backdrop never shows regardless of class */
@media (min-width: 601px) {
  .sidebar-backdrop { display: none !important; }
}
