:root {
  --bg: #e9e4d8;
  --panel: #2f3640;
  --panel-2: #3a4250;
  --ink: #232830;
  --muted: #6b7280;
  --line: rgba(0, 0, 0, .12);
  --accent: #ffd45e;
  --danger: #d64545;
  --radius: 10px;
  --shadow: 0 6px 14px rgba(0, 0, 0, .18);
}

* { box-sizing: border-box; }

/* The hidden attribute is only a UA-level `display: none`, so any class rule
   that sets display beats it. Anything toggled with `hidden` must stay hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* Only the sidebar carries the mark now. */
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  background: var(--accent);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .12);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-wrap { flex: 1; display: flex; justify-content: center; }

#search {
  width: min(420px, 100%);
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .1);
  color: #fff;
}
#search::placeholder { color: rgba(255, 255, 255, .55); }
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: rgba(255, 255, 255, .2); }

.burger, .burger::before, .burger::after {
  content: "";
  display: block;
  width: 18px; height: 2px;
  background: #fff;
  border-radius: 2px;
  position: relative;
}
.burger::before { top: -6px; position: absolute; }
.burger::after { top: 6px; position: absolute; }

.bell svg { display: block; }
.bell:hover svg { transform: rotate(-8deg); }
.bell svg { transition: transform .12s ease; }

.badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

/* -------------------------------------------------------------- layout */

.layout { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
  width: 240px;
  flex: none;
  padding: 14px 12px 24px;
  background: var(--panel-2);
  color: #e7eaf0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transition: margin-left .18s ease;
}
.layout.collapsed .sidebar { margin-left: -240px; }

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 4px 14px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
}
.side-brand:hover { background: rgba(255, 255, 255, .08); }
.side-brand .brand-mark { width: 30px; height: 30px; border-radius: 7px; }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.side-brand-text strong { font-size: 16px; }
.side-brand-sub {
  font-size: 11px;
  color: #93a0b4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #aeb6c4;
  margin-bottom: 8px;
}

.mini-btn {
  border: 1px solid rgba(255, 255, 255, .2);
  background: transparent;
  color: #e7eaf0;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.mini-btn:hover { background: rgba(255, 255, 255, .12); }

.board-tree { list-style: none; margin: 0; padding: 0; }

.board-tree button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #e7eaf0;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.board-tree button:hover { background: rgba(255, 255, 255, .1); }
.board-tree button.active { background: var(--accent); color: #33291a; font-weight: 600; }
.board-tree button.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.board-tree .kids { list-style: none; margin: 0; padding-left: 12px; }

.side-link {
  width: 100%;
  display: flex;
  justify-content: space-between;
  border: 0;
  background: transparent;
  color: #e7eaf0;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.side-link:hover { background: rgba(255, 255, 255, .1); }
.side-link.active { background: rgba(255, 255, 255, .16); font-weight: 600; }

.count {
  background: rgba(255, 255, 255, .16);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 12px;
}

.side-status {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, .1);
}

.side-conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #cdd4e0;
}
.side-conn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ccf7f;
  box-shadow: 0 0 0 3px rgba(76, 207, 127, .2);
  flex: none;
}
.side-conn.offline { color: #ffb3b3; }
.side-conn.offline .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(214, 69, 69, .25); }

.side-foot { margin: 6px 0 0; font-size: 11px; color: #93a0b4; }

.content { flex: 1; padding: 18px; min-width: 0; }

.view-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.view-head h2 { margin: 0; font-size: 20px; }
.view-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.crumbs button {
  border: 0; background: none; color: var(--muted);
  cursor: pointer; padding: 0; text-decoration: underline;
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--panel);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn:hover { filter: brightness(1.15); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.ghost:hover { background: rgba(0, 0, 0, .06); }
.btn.danger { color: var(--danger); border-color: rgba(214, 69, 69, .4); }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.empty { color: var(--muted); }

/* --------------------------------------------------------------- notes */

.notes {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

.note {
  --note-bg: #ffe680;
  background: var(--note-bg);
  border-radius: 3px;
  padding: 10px 12px 12px;
  box-shadow: var(--shadow);
  width: 240px;
  min-height: 150px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: rotate(-.4deg);
  transition: box-shadow .12s ease;
  cursor: grab;
  /* Native corner handle; the card stores whatever size you drag it to. */
  resize: both;
  overflow: auto;
  min-width: 180px;
  max-width: 900px;
  max-height: 900px;
}
.note:nth-child(even) { transform: rotate(.5deg); }
.note:hover { box-shadow: 0 10px 20px rgba(0, 0, 0, .22); }
.note.dragging { opacity: .45; }
.note.drop-before { box-shadow: -4px 0 0 var(--panel), var(--shadow); }

.note.min {
  min-height: 0;
  height: auto !important;
  resize: horizontal;
}
.note.min .note-body,
.note.min .note-foot,
.note.min .note-due,
.note.min .note-meta,
.note.min .note-image { display: none; }

/* attached image */
.note-image {
  margin: 0;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(0, 0, 0, .06);
  cursor: zoom-in;
  flex: none;
}
.note-image img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
}

.note.drop-image { outline: 3px dashed rgba(0, 0, 0, .45); outline-offset: -4px; }
.note.uploading { opacity: .6; }

.note.done .note-name { text-decoration: line-through; opacity: .6; }

.note-head { display: flex; align-items: flex-start; gap: 6px; }

.note-name {
  flex: 1;
  font-weight: 700;
  font-size: 15px;
  border: 0;
  background: transparent;
  outline: none;
  min-width: 0;
  padding: 2px 0;
}

.note-btn {
  border: 0;
  background: rgba(0, 0, 0, .07);
  border-radius: 5px;
  width: 22px; height: 22px;
  line-height: 1;
  cursor: pointer;
  color: rgba(0, 0, 0, .6);
  flex: none;
}
.note-btn:hover:not(:disabled) { background: rgba(0, 0, 0, .16); }
.note-btn:disabled { opacity: .35; cursor: not-allowed; }

.lock-btn svg { display: block; margin: 0 auto; }
.lock-btn.on { background: rgba(0, 0, 0, .55); color: #fff; }
.lock-btn.on:hover:not(:disabled) { background: rgba(0, 0, 0, .7); }

.note-meta {
  font-size: 11px;
  color: rgba(0, 0, 0, .45);
  margin-top: -4px;
  flex: none;
}

/* locked notes read as fixed, not broken */
.note.locked { box-shadow: 0 0 0 2px rgba(0, 0, 0, .45), var(--shadow); cursor: default; }
.note.locked .note-name,
.note.locked .note-body { cursor: default; }
.note.locked .note-status:disabled,
.note.locked .swatch:disabled { opacity: .55; cursor: not-allowed; }
.note.locked .note-due input:disabled { opacity: .6; }

.note-body {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 14px;
  line-height: 1.45;
  min-height: 60px;
  width: 100%;
}

/* due date */
.note-due { display: flex; align-items: center; gap: 5px; flex: none; }
.note-due label { font-size: 11px; color: rgba(0, 0, 0, .55); }
.note-due input {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid rgba(0, 0, 0, .18);
  border-radius: 6px;
  background: rgba(255, 255, 255, .5);
  color: inherit;
}
.note-due input:focus { outline: 2px solid rgba(0, 0, 0, .35); outline-offset: 1px; }

.note.overdue .note-due input { border-color: var(--danger); background: rgba(255, 214, 214, .85); }
.note.due-soon .note-due input { border-color: #c99700; background: rgba(255, 234, 184, .85); }

.due-flag {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}
.due-flag.overdue { background: var(--danger); color: #fff; }
.due-flag.soon { background: #ffcf4d; color: #6b4a00; }

.note-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.note-status {
  border: 1px solid rgba(0, 0, 0, .18);
  border-radius: 999px;
  background: rgba(255, 255, 255, .45);
  font-size: 12px;
  padding: 2px 6px;
}

.swatches { display: flex; gap: 4px; margin-left: auto; }
.swatch {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .2);
  cursor: pointer;
  padding: 0;
}
.swatch[aria-pressed="true"] { outline: 2px solid rgba(0, 0, 0, .55); outline-offset: 1px; }

.c-yellow { --note-bg: #ffe680; }
.c-pink   { --note-bg: #ffb3c6; }
.c-blue   { --note-bg: #a8d8ff; }
.c-green  { --note-bg: #b8e986; }
.c-orange { --note-bg: #ffc48c; }
.c-purple { --note-bg: #d3b7ff; }

/* ----------------------------------------------------- all boards page */

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  align-items: start;
}

.board-card {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .07);
  transition: transform .12s ease, box-shadow .12s ease;
}
.board-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.board-card.child { border-left: 4px solid var(--accent); }

.board-card-name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.board-card-name .parent-of { font-size: 11px; color: var(--muted); font-weight: 400; }

.board-card-counts { display: flex; gap: 6px; flex-wrap: wrap; }

.pill {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .06);
  color: var(--ink);
}
.pill.todo { background: #e3e8f0; }
.pill.doing { background: #cfe6ff; }
.pill.done { background: #d7f0cd; }
.pill.overdue { background: #ffd6d6; color: #8a1f1f; font-weight: 600; }
.pill.soon { background: #ffeab8; color: #7a5300; font-weight: 600; }

.board-card-empty { color: var(--muted); font-size: 13px; }

.board-card-swatches { display: flex; gap: 3px; }
.board-card-swatches span {
  width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, .12);
}

/* ---------------------------------------------------------- list views */

.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.rows li {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.rows li.unread { border-left: 4px solid var(--danger); }
.rows .meta { color: var(--muted); font-size: 12px; }
.rows .spacer { margin-left: auto; }
.rows.log li { font-size: 13px; padding: 7px 10px; }

.sub-head {
  margin: 26px 0 4px;
  font-size: 14px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.sub-head:first-of-type { margin-top: 10px; }

.table-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.table-tools input[type="search"] {
  flex: 1 1 240px;
  max-width: 340px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.sort-btn {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-transform: inherit;
  letter-spacing: inherit;
}
.sort-btn:hover { text-decoration: underline; }
.sort-btn.active { color: var(--ink); font-weight: 700; }
.sort-btn.active[data-dir="asc"]::after { content: " \2191"; }
.sort-btn.active[data-dir="desc"]::after { content: " \2193"; }

.table-scroll { overflow-x: auto; margin-bottom: 8px; }

.job-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 14px;
  min-width: 860px;
}
.job-table th, .job-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.job-table th { background: rgba(0, 0, 0, .04); font-size: 12px; text-transform: uppercase; color: var(--muted); }
.job-table tbody tr:last-child td { border-bottom: 0; }
.job-table tbody tr:hover { background: rgba(0, 0, 0, .03); }
.job-table .note-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.job-table .swatch-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  margin-right: 7px; border: 1px solid rgba(0, 0, 0, .15); vertical-align: middle;
}
.job-table input[type="datetime-local"], .job-table select {
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.job-table tr.overdue td { background: rgba(255, 214, 214, .5); }
.job-table tr.due-soon td { background: rgba(255, 234, 184, .45); }
.job-table tr.locked .note-cell a { color: var(--muted); }
.job-table .note-btn { background: rgba(0, 0, 0, .06); }
.job-table .empty-row td { color: var(--muted); text-align: center; white-space: normal; }

.job-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.job-form input, .job-form select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.job-form input[name="name"] { flex: 1 1 180px; }
.job-form input[name="noteText"] { flex: 1 1 220px; }

/* --------------------------------------------------------------- misc */

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }

/* ---------------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }

.login-card {
  width: min(360px, 100%);
  transform: rotate(-1deg);
  padding: 24px;
  cursor: default;
  resize: none;
  overflow: visible;
  min-height: 0;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 16px; color: rgba(0, 0, 0, .6); font-size: 14px; }

.login-card form { display: grid; gap: 10px; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, .25);
  border-radius: 8px;
  background: rgba(255, 255, 255, .7);
}
.login-error { margin: 14px 0 0 !important; color: #8a1f1f !important; font-weight: 600; }

/* ------------------------------------------------------- expanded note */

.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }

.modal.note {
  position: relative;
  width: min(720px, 100%);
  max-width: none;
  max-height: calc(100vh - 40px);
  height: auto;
  transform: none;
  resize: none;
  cursor: default;
  overflow: auto;
  padding: 16px 18px 18px;
  gap: 12px;
}
.modal.note:hover { box-shadow: var(--shadow); }

.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-head .note-name { font-size: 20px; }

.modal.note .note-body { min-height: 180px; font-size: 15px; }

.modal-image { position: relative; }
.modal-image img {
  display: block;
  width: 100%;
  max-height: 45vh;
  object-fit: contain;
  border-radius: 4px;
  background: rgba(0, 0, 0, .08);
}
.modal-image .btn { position: absolute; top: 8px; right: 8px; background: rgba(255, 255, 255, .9); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--panel);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-size: 14px;
}

/* ------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  .brand h1 { display: none; }
  .search-wrap { justify-content: flex-start; }

  .sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    z-index: 25;
    overflow-y: auto;
    box-shadow: var(--shadow);
  }
  .layout.collapsed .sidebar { margin-left: -240px; }

  .content { padding: 14px 12px 40px; }
  /* No corner-drag on touch: cards take the full column width instead. */
  .notes { display: block; }
  .note {
    transform: none;
    width: auto !important;
    max-width: none;
    height: auto !important;
    resize: none;
    margin-bottom: 14px;
  }
  .modal-wrap { padding: 10px; }
  .modal.note { max-height: calc(100vh - 20px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
