:root {
  --bg: #f2f2f7;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --hairline: rgba(60, 60, 67, 0.18);
  --tile: #ffffff;
  --hover: rgba(0, 0, 0, 0.035);
  --needs: #ff9500;
  --fyi: #007aff;
  --archived: #8e8e93;
  --completed: #636366;
  --accent: var(--needs);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --panel: #000000;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --hairline: rgba(84, 84, 88, 0.6);
    --tile: #2c2c2e;
    --hover: rgba(255, 255, 255, 0.05);
    --needs: #ff9f0a;
    --fyi: #0a84ff;
    --archived: #98989d;
    --completed: #aeaeb2;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--panel);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

/* ---------------------------------------------------------------- layout */
.app { display: flex; min-height: 100vh; background: var(--bg); }
.sidebar {
  width: 300px; flex: none;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; overflow-y: auto;
  background: var(--bg);
  padding: 22px 14px;
}
.main {
  flex: 1; min-width: 0; min-height: 100vh; padding: 28px 36px 80px;
  background: var(--panel);
  border-top-left-radius: 12px;
}
.main > * { max-width: 788px; }

/* ---------------------------------------------------------------- smart-list tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--tile);
  border-radius: 11px;
  padding: 9px 11px 8px;
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  row-gap: 6px;
  box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.06);
  transition: transform .08s ease;
}
.tile:active { transform: scale(0.98); }
.tile .dot {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 14px; font-weight: 600;
}
.tile .num { justify-self: end; font-size: 26px; font-weight: 700; line-height: 28px; }
.tile .name { grid-column: 1 / -1; font-size: 14px; font-weight: 600; color: var(--muted); }
.tile.selected { background: var(--c); }
.tile.selected .name, .tile.selected .num { color: #fff; }
.tile.selected .dot { background: #fff !important; color: var(--c); }
.tile[data-list="needs"] { --c: var(--needs); }
.tile[data-list="fyi"] { --c: var(--fyi); }
.tile[data-list="archived"] { --c: var(--archived); }
.tile[data-list="completed"] { --c: var(--completed); }
.tile .dot { background: var(--c); }

/* ---------------------------------------------------------------- notifications toggle */
.notify { margin-top: 18px; padding: 0 2px; }
.notify-button {
  width: 100%; text-align: left;
  background: var(--tile); border-radius: 11px; padding: 10px 12px;
  font-size: 14px; font-weight: 500; color: var(--fyi);
  box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.06);
}
.notify-button[data-state="on"] { color: var(--muted); }
.notify-button:disabled { color: var(--muted); cursor: default; }
.notify-hint { color: var(--muted); font-size: 12px; margin: 8px 2px 0; line-height: 1.4; }

/* ---------------------------------------------------------------- list header */
.list-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.list-header h1 { margin: 0; font-size: 32px; font-weight: 700; color: var(--accent); letter-spacing: 0.2px; }
.list-count { font-size: 32px; font-weight: 600; color: var(--accent); }
.completed-bar {
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 13px;
  padding: 6px 0 8px; border-bottom: 1px solid var(--hairline);
}
.link-button { color: var(--accent); font-size: 13px; }

/* ---------------------------------------------------------------- items */
.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 12px; padding: 9px 0 0; position: relative; }
.item:hover .delete { opacity: 1; }
.check {
  flex: none; width: 21px; height: 21px; margin-top: 1px;
  border-radius: 50%; border: 1.5px solid #c7c7cc;
  display: grid; place-items: center;
  transition: border-color .15s ease;
}
@media (prefers-color-scheme: dark) { .check { border-color: #545458; } }
.check::after {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  background: var(--item-c, var(--accent)); transform: scale(0); transition: transform .15s ease;
}
.item.done .check { border-color: var(--item-c, var(--accent)); }
.item.done .check::after { transform: scale(1); }
.body {
  flex: 1; min-width: 0;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--hairline);
}
.title { outline: none; word-wrap: break-word; }
.title:focus { cursor: text; }
.item.done .title { color: var(--muted); }
.note { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: pre-wrap; outline: none; }
.note:empty { display: none; }
.note.editing:empty { display: block; min-height: 1.3em; }
.meta { color: var(--muted); font-size: 12px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.meta a { color: var(--item-c, var(--accent)); text-decoration: none; }
.meta a:hover { text-decoration: underline; }
.tag { color: var(--item-c, var(--accent)); }
.meta .src { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.meta a.src:hover { color: var(--text); text-decoration: none; }
.src-icon { width: 14px; height: 14px; border-radius: 3.5px; flex: none; }
.resolved::before { content: "\2713  "; }
.delete {
  position: absolute; right: 0; top: 8px;
  opacity: 0; color: var(--muted); font-size: 17px; line-height: 1; padding: 2px 4px;
  transition: opacity .12s;
}
.delete:hover { color: #ff3b30; }
.item.leaving { animation: leave .35s ease forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(8px); } }

.new-item { color: var(--accent); margin-top: 12px; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.new-item .plus { width: 21px; text-align: center; font-size: 22px; line-height: 18px; font-weight: 300; }
.empty { color: var(--muted); text-align: center; margin-top: 64px; font-size: 15px; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.login-card { text-align: center; padding: 32px; }
.login-card h1 { margin: 14px 0 4px; font-size: 24px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.login-icon {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 15px;
  background: url(/static/icon.svg) center / cover;
}
.login-button {
  display: inline-block; background: var(--fyi); color: #fff; text-decoration: none;
  padding: 9px 22px; border-radius: 9px; font-weight: 600;
}
.login-error { color: #ff3b30; margin-top: 16px !important; font-size: 13px; }


/* ---------------------------------------------------------------- chat with Francis */
.item { cursor: default; }
.item .body { cursor: pointer; }
.item.selected .body { border-bottom-color: transparent; }
.item.selected { background: var(--hover); border-radius: 10px; margin: 0 -10px; padding-left: 10px; padding-right: 10px; }
.talk {
  position: absolute; right: 26px; top: 8px; width: 20px; height: 20px;
  opacity: 0; transition: opacity .12s;
  background: center / 16px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a8 8 0 0 1-11.6 7.1L4 20.5l1.4-4.9A8 8 0 1 1 21 12z'/%3E%3C/svg%3E");
}
.item:hover .talk, .talk.has-chat, .item.selected .talk { opacity: 1; }
.talk.has-chat {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23007aff' stroke='%23007aff' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M21 12a8 8 0 0 1-11.6 7.1L4 20.5l1.4-4.9A8 8 0 1 1 21 12z'/%3E%3C/svg%3E");
}

.detail {
  width: 420px; flex: none;
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--hairline);
  background: var(--panel);
}
.detail-head { padding: 22px 22px 14px; border-bottom: 1px solid var(--hairline); position: relative; }
.detail-close {
  position: absolute; top: 16px; right: 14px; width: 26px; height: 26px; border-radius: 50%;
  color: var(--muted); font-size: 13px;
}
.detail-close:hover { background: var(--hover); color: var(--text); }
.detail-title { font-weight: 600; font-size: 16px; padding-right: 30px; }
.detail-meta { margin-top: 6px; font-size: 12px; color: var(--muted); }
.detail-meta .src { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; }
.detail-meta .src:hover { color: var(--text); }
.detail-note { margin-top: 6px; font-size: 13px; line-height: 1.4; white-space: pre-wrap; }

.thread { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.thread-empty { color: var(--muted); font-size: 13px; line-height: 1.45; text-align: center; margin: auto 18px; }
.msg { max-width: 85%; font-size: 14px; line-height: 1.4; word-wrap: break-word; }
.msg.user {
  align-self: flex-end; background: var(--fyi); color: #fff;
  padding: 7px 12px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap;
}
.msg.agent {
  align-self: flex-start; background: var(--bg);
  padding: 7px 12px; border-radius: 18px 18px 18px 4px;
}
@media (prefers-color-scheme: dark) { .msg.agent { background: var(--tile); } }
.msg.agent p { margin: 0 0 6px; } .msg.agent p:last-child { margin: 0; }
.msg.agent ul { margin: 2px 0 6px; padding-left: 18px; }
.msg.agent a { color: var(--fyi); }
.msg.agent code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--hover); padding: 0 3px; border-radius: 4px; }
.msg.tool { align-self: flex-start; color: var(--muted); font-size: 12px; padding: 0 4px; }
.msg.tool::before { content: "\21BB  "; }
.msg.error { align-self: center; color: #ff3b30; font-size: 12px; text-align: center; }
.msg.typing { align-self: flex-start; background: var(--bg); border-radius: 18px; padding: 10px 14px; display: flex; gap: 4px; }
@media (prefers-color-scheme: dark) { .msg.typing { background: var(--tile); } }
.msg.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.msg.typing span:nth-child(2) { animation-delay: .2s; } .msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.msg.ask {
  align-self: stretch; max-width: none; border: 1px solid var(--hairline); border-radius: 12px; padding: 10px 12px;
}
.msg.ask.answered { opacity: .6; }
.ask-text { white-space: pre-wrap; }
.ask-hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.ask-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ask-option, .ask-skip { border-radius: 14px; padding: 4px 12px; font-size: 13px; }
.ask-option { background: var(--fyi); color: #fff; }
.ask-skip { color: var(--muted); }
.ask-option:disabled, .ask-skip:disabled { opacity: .5; cursor: default; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  margin: 0 14px 14px; padding: 6px 6px 6px 14px;
  border: 1px solid var(--hairline); border-radius: 20px; background: var(--panel);
}
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.4; padding: 5px 0; max-height: 160px;
}
.composer button {
  width: 28px; height: 28px; border-radius: 50%; background: var(--fyi); color: #fff;
  font-size: 16px; font-weight: 600; flex: none;
}
.composer button:disabled { opacity: .35; cursor: default; }
.composer-off { color: var(--muted); font-size: 13px; text-align: center; margin: 0 0 18px; }

@media (max-width: 1180px) { .detail { width: 360px; } }
@media (max-width: 720px) {
  .detail { position: fixed; inset: 0; width: auto; height: auto; z-index: 10; border-left: 0; }
  .detail-head { padding-top: calc(18px + env(safe-area-inset-top)); }
  .composer { margin-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .talk { opacity: 1; }
  body.has-detail { overflow: hidden; }
}

/* ---------------------------------------------------------------- small screens */
@media (max-width: 720px) {
  .app { display: block; }
  .sidebar { width: auto; height: auto; border-right: 0; padding: 16px 16px 6px; position: sticky; top: 0; z-index: 2; }
  .tiles { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .tile { padding: 7px 8px; }
  .tile .dot { width: 22px; height: 22px; font-size: 12px; }
  .tile .num { font-size: 20px; line-height: 22px; }
  .notify { margin-top: 10px; }
  .notify-button { padding: 8px 10px; font-size: 13px; }
  .tile .name { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .main { padding: 14px 16px 60px; border-radius: 0; box-shadow: none; }
  .list-header h1, .list-count { font-size: 28px; }
  .delete { opacity: 1; }
}
