:root {
  --bg: #f4f5f7;
  --text: #172b4d;
  --muted: #5e6c84;
  --list-bg: #ebecf0;
  --card-bg: #ffffff;
  --border: #dfe1e6;
  --accent: #0079bf;
  --danger: #c9372c;
  --radius: 8px;
  --shadow: 0 1px 0 rgba(9, 30, 66, .25);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); font-size: 14px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

/* ---------- generic controls ---------- */
.btn {
  border: 0; border-radius: 4px; padding: 7px 12px; background: rgba(9, 30, 66, .06);
  font-weight: 500; line-height: 1.2;
}
.btn:hover { background: rgba(9, 30, 66, .12); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(9, 30, 66, .08); }
.btn.block { display: block; width: 100%; text-align: left; margin-bottom: 6px; }
.icon-btn {
  border: 0; background: transparent; width: 30px; height: 30px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px; color: inherit;
}
.icon-btn:hover { background: rgba(9, 30, 66, .1); }
input[type=text], input[type=password], input[type=date], textarea, select {
  width: 100%; border: 2px solid var(--border); border-radius: 4px; padding: 7px 9px; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, #0079bf, #5067c5); }
.login-box { background: #fff; border-radius: 12px; padding: 32px; width: 100%; max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.login-box h1 { margin: 0 0 6px; font-size: 22px; }
.login-box p { color: var(--muted); margin: 0 0 20px; }
.login-box input { margin-bottom: 12px; }
.login-box .btn { width: 100%; padding: 10px; }
.error { color: var(--danger); min-height: 20px; margin-top: 8px; font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: rgba(0, 0, 0, .25); color: #fff;
}
.home .topbar { background: #026aa7; }
.topbar .brand { font-weight: 700; font-size: 17px; text-decoration: none; margin-right: 8px; }
.topbar .spacer { flex: 1; }
.topbar .icon-btn:hover, .topbar .btn.ghost:hover { background: rgba(255,255,255,.2); }
.topbar .btn.ghost { color: #fff; }
.topbar input.search {
  width: 220px; background: rgba(255,255,255,.2); border: 0; color: #fff; padding: 7px 10px;
}
.topbar input.search::placeholder { color: rgba(255,255,255,.8); }
.topbar input.search:focus { background: #fff; color: var(--text); }

/* ---------- home ---------- */
.home-main { max-width: 1100px; margin: 0 auto; padding: 28px 20px; }
.home-main h2 { font-size: 16px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 32px; }
.board-tile {
  position: relative; height: 100px; border-radius: var(--radius); padding: 10px 12px; color: #fff;
  font-weight: 700; font-size: 16px; text-decoration: none; display: flex; flex-direction: column;
  justify-content: space-between; overflow: hidden; word-break: break-word;
}
.board-tile::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,0); transition: background .15s; }
.board-tile:hover::after { background: rgba(0,0,0,.15); }
.board-tile .meta { font-weight: 400; font-size: 12px; opacity: .9; }
.board-tile .star { position: absolute; right: 8px; bottom: 6px; z-index: 1; border: 0; background: none;
  color: #fff; font-size: 16px; opacity: 0; }
.board-tile:hover .star, .board-tile .star.on { opacity: 1; }
.board-tile .star.on { color: #f2d600; }
.new-board { background: rgba(9,30,66,.06); color: var(--muted); align-items: center; justify-content: center;
  font-weight: 500; font-size: 14px; border: 0; }
.new-board:hover { background: rgba(9,30,66,.12); }
.new-board-form { background: #fff; border-radius: var(--radius); padding: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.new-board-form input { margin-bottom: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.swatch { width: 28px; height: 24px; border-radius: 4px; border: 0; padding: 0; }
.swatch.sel { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- board ---------- */
.board-page { height: 100%; display: flex; flex-direction: column; }
.board-header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; color: #fff; background: rgba(0,0,0,.12); }
.board-title {
  font-size: 18px; font-weight: 700; padding: 4px 8px; border-radius: 4px; background: transparent; border: 0;
  color: #fff; max-width: 60vw; min-width: 40px;
}
.board-title:hover { background: rgba(255,255,255,.2); }
input.board-title-input { font-size: 18px; font-weight: 700; width: auto; padding: 2px 8px; }
.board-header .spacer { flex: 1; }
.board-header .btn.ghost { color: #fff; }
.board-header .btn.ghost:hover, .board-header .icon-btn:hover { background: rgba(255,255,255,.2); }
.board-canvas { flex: 1; overflow-x: auto; overflow-y: hidden; padding: 12px; }
.lists { display: flex; align-items: flex-start; gap: 10px; height: 100%; }
.list {
  flex: 0 0 272px; width: 272px; max-height: 100%; display: flex; flex-direction: column;
  background: var(--list-bg); border-radius: 12px;
}
.list-header { display: flex; align-items: center; padding: 8px 6px 4px 10px; gap: 4px; cursor: grab; }
.list-title { flex: 1; font-weight: 600; padding: 4px 6px; border-radius: 4px; word-break: break-word; cursor: pointer; }
.list-header input { font-weight: 600; padding: 3px 6px; }
.list-count { color: var(--muted); font-size: 12px; }
.cards { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px; min-height: 8px; }
.card {
  position: relative; background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px 10px; margin-bottom: 8px; cursor: pointer; word-break: break-word;
}
.card:hover { box-shadow: 0 0 0 2px var(--accent); }
.card.done .card-title { color: var(--muted); text-decoration: line-through; }
.card-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.card-label { height: 8px; min-width: 40px; border-radius: 4px; font-size: 0; }
.card-label.named { height: auto; font-size: 11px; font-weight: 600; color: #fff; padding: 1px 8px; text-shadow: 0 0 2px rgba(0,0,0,.35); }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 1px 4px; border-radius: 3px; }
.badge.due-soon { background: #f5cd47; color: #172b4d; }
.badge.overdue { background: #eb5a46; color: #fff; }
.badge.complete { background: #61bd4f; color: #fff; }
.add-card-btn { margin: 2px 8px 8px; text-align: left; color: var(--muted); }
.composer { padding: 0 8px 8px; }
.composer textarea { min-height: 54px; margin-bottom: 6px; box-shadow: var(--shadow); border: 0; }
.composer .row { display: flex; gap: 6px; align-items: center; }
.add-list { flex: 0 0 272px; background: rgba(255,255,255,.24); color: #fff; border-radius: 12px; }
.add-list > .btn { width: 100%; text-align: left; color: #fff; background: transparent; padding: 10px 12px; }
.add-list > .btn:hover { background: rgba(255,255,255,.15); }
.add-list form { background: var(--list-bg); padding: 8px; border-radius: 12px; }
.add-list form input { margin-bottom: 6px; }
.ghost { opacity: .4; }
.sortable-drag { transform: rotate(3deg); }
.hidden { display: none !important; }

/* ---------- popover menu ---------- */
.popover {
  position: fixed; z-index: 50; background: #fff; border-radius: 8px; width: 280px; padding: 12px;
  box-shadow: 0 8px 24px rgba(9,30,66,.25); color: var(--text);
}
.popover h4 { margin: 0 0 10px; text-align: center; color: var(--muted); font-size: 14px; font-weight: 600; }
.popover .item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 8px; border-radius: 4px; }
.popover .item:hover { background: rgba(9,30,66,.08); }
.popover .item.danger { color: var(--danger); }
.popover hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: flex; justify-content: center;
  align-items: flex-start; overflow-y: auto; padding: 48px 16px;
}
.modal { background: var(--bg); border-radius: 12px; width: 100%; max-width: 760px; padding: 20px 24px 24px; position: relative; }
.modal .close { position: absolute; right: 10px; top: 10px; }
.modal-title { font-size: 20px; font-weight: 600; width: calc(100% - 40px); border: 2px solid transparent;
  background: transparent; padding: 4px 6px; margin-left: -8px; resize: none; overflow: hidden; min-height: 0; }
.modal-title:focus { background: #fff; border-color: var(--accent); }
.modal-sub { color: var(--muted); margin: 2px 0 18px; }
.modal-body { display: grid; grid-template-columns: 1fr 180px; gap: 20px; }
.modal-section { margin-bottom: 22px; }
.modal-section h3 { font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.modal-section h3 .grow { flex: 1; }
.field-row { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 18px; }
.field-row .field h5 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.label-chip { display: inline-flex; align-items: center; min-width: 40px; height: 32px; padding: 0 12px;
  border-radius: 4px; color: #fff; font-weight: 600; margin: 0 4px 4px 0; border: 0; vertical-align: top; text-shadow: 0 0 2px rgba(0,0,0,.35); }
.label-chip.off { opacity: .35; }
.label-chip.add { background: rgba(9,30,66,.08); color: var(--text); text-shadow: none; }
.due-wrap { display: flex; align-items: center; gap: 6px; }
.due-wrap input[type=date] { width: auto; }
.desc-view { background: rgba(9,30,66,.05); border-radius: 4px; padding: 10px 12px; min-height: 56px; white-space: pre-wrap; cursor: pointer; }
.desc-view.empty { color: var(--muted); }
.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.progress .bar { flex: 1; height: 8px; background: rgba(9,30,66,.1); border-radius: 4px; overflow: hidden; }
.progress .fill { height: 100%; background: var(--accent); transition: width .2s; }
.progress .fill.full { background: #61bd4f; }
.check-item { display: flex; align-items: flex-start; gap: 8px; padding: 4px 4px; border-radius: 4px; }
.check-item:hover { background: rgba(9,30,66,.05); }
.check-item input[type=checkbox] { width: 16px; height: 16px; margin-top: 3px; flex: 0 0 auto; }
.check-item .txt { flex: 1; padding: 2px 0; cursor: text; word-break: break-word; }
.check-item.done .txt { text-decoration: line-through; color: var(--muted); }
.check-item .icon-btn { width: 24px; height: 24px; font-size: 13px; opacity: 0; }
.check-item:hover .icon-btn { opacity: 1; }
.check-add { margin-top: 6px; }
.sidebar h5 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.sidebar .group { margin-bottom: 16px; }
.archived-row { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; box-shadow: var(--shadow); }
.archived-row .t { flex: 1; word-break: break-word; }
.archived-row small { color: var(--muted); display: block; }
.label-edit-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.label-edit-row .swatch-pick { width: 34px; height: 32px; border-radius: 4px; border: 0; flex: 0 0 auto; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px); background: #172b4d;
  color: #fff; padding: 10px 16px; border-radius: 6px; transition: transform .2s; z-index: 100; pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 700px) {
  .modal-body { grid-template-columns: 1fr; }
  .modal { padding: 16px; }
  .modal-backdrop { padding: 12px 8px; }
  .topbar input.search { width: 130px; }
  .list, .add-list { flex-basis: 85vw; width: 85vw; }
}
.btn { white-space: nowrap; }
.board-title { text-align: left; }
@media (max-width: 700px) { .board-title { font-size: 16px; } }
