/* =============================================
   STICKIES — shared handoff board
   ============================================= */

:root {
  --bg: #fafaf7;
  --ink: #1f2024;
  --muted: #6b6f76;
  --line: #e8e6df;
  --line-strong: #d4d0c5;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --shadow-hover: 0 4px 8px rgba(0,0,0,.08), 0 12px 28px rgba(0,0,0,.10);

  --red: #ffb3b3;
  --red-ink: #7a1f1f;
  --yellow: #fff3a8;
  --yellow-ink: #6b5a00;
  --green: #b5e6b5;
  --green-ink: #1f5a1f;
  --grey: #d9d9d4;
  --grey-ink: #555;

  --radius: 6px;
  --gap: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }

/* =============================================
   LOGIN
   ============================================= */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #faf8f3 0%, #efece4 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,.08);
}
.login-header { text-align: center; margin-bottom: 24px; }
.login-icon { font-size: 40px; display: block; }
.login-header h1 { margin: 8px 0 4px; font-size: 24px; font-weight: 700; }
.login-header p { color: var(--muted); margin: 0; font-size: 14px; }

#loginForm { display: flex; flex-direction: column; gap: 10px; }
#loginForm input {
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
}
#loginForm input:focus { outline: 2px solid #cdb98a; outline-offset: -1px; }

.btn-primary {
  padding: 11px 14px;
  background: #1f2024;
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
}
.btn-primary:hover { background: #000; }
.btn-primary:disabled { opacity: .5; cursor: wait; }

.btn-secondary {
  padding: 10px 14px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.auth-message {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}
.auth-message.error { background: #ffe6e6; color: #7a1f1f; }
.auth-message.success { background: #e6f7e6; color: #1f5a1f; }

.login-forgot {
  text-align: center;
  margin: 14px 0 0;
  font-size: 12px;
}
.login-forgot a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dotted var(--line-strong);
}
.login-forgot a:hover { color: var(--ink); border-bottom-color: var(--ink); }

.login-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 0;
}

/* =============================================
   TOPBAR
   ============================================= */
.board-body {
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: 48px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { font-weight: 700; }

.board-picker {
  font: inherit;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  max-width: 180px;
}
.board-picker:hover { background: #f3f1ea; }
.board-picker:focus { outline: 2px solid #cdb98a; outline-offset: -1px; }

.user-chip {
  background: #1f2024;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  letter-spacing: .5px;
}
.user-chip:empty::before { content: '··'; opacity: .5; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
}
.btn-ghost:hover { background: #f3f1ea; }
.btn-ghost.danger { color: #a33; border-color: #f0c0c0; }
.btn-ghost.danger:hover { background: #ffe6e6; }

.btn-ghost-sm {
  background: transparent;
  border: 0;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--muted);
}
.btn-ghost-sm:hover { background: #f3f1ea; color: var(--ink); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

/* =============================================
   BOARD
   ============================================= */
.board-container {
  position: relative;
  overflow: auto;
  background: var(--bg);
  padding: 24px;
}

.board {
  display: grid;
  gap: var(--gap);
  transform-origin: top left;
  transition: transform .15s ease;
  margin: 0 auto;
  width: 100%;
  max-width: 1400px;
}

.cell {
  aspect-ratio: 1 / 1;
  position: relative;
  border-radius: var(--radius);
  background:
    linear-gradient(to right,  var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) top left / 100% 1px no-repeat,
    linear-gradient(to right,  var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) top right / 100% 1px no-repeat,
    linear-gradient(to bottom, var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) top left / 1px 100% no-repeat,
    linear-gradient(to bottom, var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) top right / 1px 100% no-repeat,
    linear-gradient(to left,   var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) bottom left / 100% 1px no-repeat,
    linear-gradient(to left,   var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) bottom right / 100% 1px no-repeat,
    linear-gradient(to top,    var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) bottom left / 1px 100% no-repeat,
    linear-gradient(to top,    var(--line-strong) 0, var(--line-strong) 14px, transparent 14px) bottom right / 1px 100% no-repeat;
  opacity: .9;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
}
.cell.drag-over { background-color: rgba(205,185,138,.18); outline: 2px dashed #cdb98a; outline-offset: -4px; }
.cell.drag-reject { animation: shake .25s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* =============================================
   STICKIES
   ============================================= */
.sticky {
  position: relative;
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  font-size: 13px;
  line-height: 1.3;
  transition: transform .12s ease, box-shadow .12s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  container-type: size;
  container-name: sticky;
}
.sticky:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.sticky:active { cursor: grabbing; }
.sticky.dragging { opacity: .4; }

.sticky.red    { background: var(--red);    color: var(--red-ink); }
.sticky.yellow { background: var(--yellow); color: var(--yellow-ink); }
.sticky.green  { background: var(--green);  color: var(--green-ink); }
.sticky.grey   { background: var(--grey);   color: var(--grey-ink); }

.sticky .title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sticky .title:empty::before { content: 'Untitled'; opacity: .5; font-weight: 600; }

.sticky .meta {
  margin-top: auto;
  font-size: 10px;
  opacity: .65;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex: 0 0 auto;
}

/* Sticky variants by mode */
.sticky.expanded {
  flex: 1 1 auto;
  min-height: 0;
}
.sticky.expanded .body-preview {
  font-size: 12px;
  opacity: .85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
}
.body-md .body-line {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.body-md .body-line:empty { min-height: 0.6em; }
.body-md .body-check {
  display: flex;
  align-items: flex-start;
  gap: 5px;
}
.body-md .body-check input[type="checkbox"] {
  margin: 3px 0 0 0;
  flex: 0 0 auto;
  cursor: pointer;
  width: 12px;
  height: 12px;
  accent-color: currentColor;
}
.body-md .body-check-text.done {
  text-decoration: line-through;
  opacity: .55;
}
.body-md .body-bullet {
  padding-left: 2px;
}
/* When the sticky has enough vertical room, body shows fully. When cramped,
   it clamps to fit. Container queries gate the behavior on height. */
@container sticky (max-height: 160px) {
  .sticky.expanded .body-preview {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }
}
@container sticky (min-height: 161px) and (max-height: 240px) {
  .sticky.expanded .body-preview {
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
  }
}
@container sticky (min-height: 241px) {
  .sticky.expanded .body-preview {
    display: block;
  }
}
.sticky.row {
  flex: 1 1 0;
  padding: 6px 8px;
  font-size: 12px;
  min-height: 0;
}
.sticky.row .title {
  font-size: 12px;
  -webkit-line-clamp: 1;
}
.sticky.row .body-preview { display: none; }
.sticky.row .meta { font-size: 9px; }

.sticky .child-badge {
  position: absolute;
  top: 4px; right: 6px;
  font-size: 10px;
  opacity: .6;
}

/* =============================================
   MINIMIZED STICKY
   ============================================= */
.sticky.minimized {
  container-type: normal;
  flex: 0 0 auto;
  padding: 5px 8px;
  min-height: 0;
  gap: 0;
}
.sticky.minimized .title {
  font-size: 12px;
  font-weight: 600;
  -webkit-line-clamp: 1;
  margin-bottom: 0;
}
.sticky.minimized .body-preview { display: none; }
.sticky.minimized .sticky-toggle {
  width: 16px;
  height: 16px;
  font-size: 10px;
  top: 3px;
  right: 3px;
}
.sticky.minimized .kid-count {
  position: static;
  font-size: 9px;
  opacity: .55;
}

/* Collapse/expand toggle in top-right of every sticky */
.sticky-toggle {
  position: absolute;
  top: 3px;
  right: 4px;
  background: rgba(0,0,0,.06);
  border: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1;
  color: inherit;
  opacity: .5;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.sticky-toggle:hover { opacity: 1; background: rgba(0,0,0,.12); }
.sticky.row .sticky-toggle { width: 16px; height: 16px; font-size: 10px; }

/* =============================================
   TASKS DROPDOWN (on sticky face)
   ============================================= */
.sticky-tasks {
  flex: 0 0 auto;
  font-size: 11px;
  border-top: 1px dashed rgba(0,0,0,.15);
  padding-top: 4px;
  margin-top: 4px;
}
.sticky-tasks summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 11px;
  opacity: .65;
  padding: 2px 0;
  list-style: none;
  user-select: none;
}
.sticky-tasks summary::-webkit-details-marker { display: none; }
.sticky-tasks summary::marker { display: none; content: ''; }
.sticky-tasks summary::before { content: '\25B8  '; }
.sticky-tasks[open] summary::before { content: '\25BE  '; }
.sticky-tasks summary:hover { opacity: 1; }

/* Child rows inside the tasks dropdown */
.sticky-children {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  overflow: hidden;
  flex: 0 0 auto;
}
.sticky-children li {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  padding: 2px 4px;
  border-radius: 3px;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sticky-children li:hover { background: rgba(0,0,0,.06); }
.sticky-children .kid-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.15);
  margin-top: 4px;
}
.sticky-children .kid-dot.red    { background: var(--red); }
.sticky-children .kid-dot.yellow { background: var(--yellow); }
.sticky-children .kid-dot.green  { background: var(--green); }
.sticky-children .kid-dot.grey   { background: var(--grey); }
.sticky-children .kid-title {
  flex: 1;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sticky-children .kid-more {
  font-size: 10px;
  opacity: .6;
  font-style: italic;
}

/* Row form: small count chip */
.sticky.row .kid-count {
  position: absolute;
  top: 3px;
  right: 24px;
  font-size: 9px;
  opacity: .65;
}

/* Tray (unplaced) */
.tray {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100vw - 24px);
  z-index: 4;
}
.tray.hidden { display: none; }
.tray-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.tray-hint {
  color: var(--muted);
  font-size: 11px;
  flex: 1;
}
.tray.collapsed .tray-items { display: none; }
.tray-items {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  max-width: 60vw;
}
.tray-items .sticky {
  width: 120px;
  height: 80px;
  flex: 0 0 auto;
}
.tray-items:empty::before {
  content: 'Drag stickies here to unplace, or click + New';
  font-size: 11px;
  color: var(--muted);
  padding: 6px 4px;
}

/* =============================================
   MODAL
   ============================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 16px 18px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.color-row { display: flex; gap: 6px; }
.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  background-clip: padding-box;
}
.color-dot.red { background-color: var(--red); }
.color-dot.yellow { background-color: var(--yellow); }
.color-dot.green { background-color: var(--green); }
.color-dot.grey { background-color: var(--grey); }
.color-dot.active { border-color: var(--ink); }

.editor-title {
  border: 0;
  border-bottom: 1px solid var(--line);
  font-size: 18px;
  font-weight: 700;
  padding: 6px 0;
  outline: none;
}
.editor-body {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 80px;
  outline: none;
}
.editor-body:focus, .editor-title:focus { border-color: #cdb98a; }

.children-section { border-top: 1px solid var(--line); padding-top: 8px; }
.children-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.children-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.children-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #faf8f3;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.children-list li:hover { background: #f3f0e6; }
.children-list .child-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
}
.children-list .child-title { flex: 1; }
.children-list .child-title:empty::before { content: 'Untitled'; opacity: .5; }
.children-list .child-meta { font-size: 10px; color: var(--muted); }
.children-list li .row-delete {
  background: transparent; border: 0; color: var(--muted); padding: 0 4px;
}
.children-list li .row-delete:hover { color: #a33; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.editor-meta { font-size: 11px; color: var(--muted); }
.footer-actions { display: flex; gap: 6px; }

/* Initials */
.initials-modal { max-width: 360px; text-align: center; }
.initials-modal h2 { margin: 0 0 4px; }
.initials-modal p { color: var(--muted); margin: 0 0 10px; font-size: 13px; }
.initials-input {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 4px;
  padding: 10px;
  width: 120px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  text-transform: uppercase;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 600px) {
  .topbar { padding: 0 8px; }
  .topbar .toggle { display: none; }
  .board-container { padding: 12px; }
  .tray-items { max-width: calc(100vw - 80px); }
  .modal { padding: 14px; }
}
