:root {
  color-scheme: light;
  --ink: #17191f;
  --muted: #737b87;
  --paper: #edf3f4;
  --surface: rgba(255,255,255,.86);
  --white: #fff;
  --line: rgba(23,25,31,.09);
  --teal: #0d8d89;
  --teal-soft: #dff3f0;
  --blue-soft: #e3eefb;
  --peach: #fae8df;
  --yellow: #f7edc8;
  --red: #b94352;
  --shadow: 0 12px 34px rgba(31,46,55,.08);
  font-family: "Avenir Next", Avenir, Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(155,220,218,.28), transparent 28rem),
    radial-gradient(circle at 88% 72%, rgba(250,213,195,.35), transparent 30rem),
    #f3f6f6;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; }
.auth-card {
  width: min(100%, 420px); padding: 38px; border: 1px solid rgba(255,255,255,.85);
  border-radius: 30px; background: rgba(255,255,255,.82); box-shadow: 0 26px 70px rgba(40,60,68,.12);
  backdrop-filter: blur(22px);
}
.brand-mark { width: 50px; height: 50px; display: grid; align-content: center; gap: 6px; padding: 13px; border-radius: 16px; background: var(--ink); }
.brand-mark span { display: block; height: 3px; border-radius: 99px; background: #66d3cc; }
.brand-mark span:nth-child(2) { width: 76%; background: #fff; }
.brand-mark span:nth-child(3) { width: 50%; background: #f5a987; }
.brand-mark.small { width: 38px; height: 38px; padding: 10px; gap: 4px; border-radius: 13px; }
.brand-mark.small span { height: 2px; }
.eyebrow { margin: 23px 0 7px; color: var(--teal); font-size: .7rem; font-weight: 800; letter-spacing: .14em; }
.auth-card h1 { margin: 0; font-size: clamp(2rem, 5vw, 2.55rem); line-height: 1.04; letter-spacing: -.045em; }
.auth-copy { margin: 17px 0 26px; color: var(--muted); line-height: 1.62; }
label { display: grid; gap: 8px; margin: 14px 0; color: #434952; font-size: .84rem; font-weight: 700; }
label span small { color: var(--muted); font-weight: 500; }
input, textarea, select {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 13px;
  outline: none; color: var(--ink); background: rgba(248,250,250,.92);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
input:focus, textarea:focus, select:focus { border-color: rgba(13,141,137,.55); background: #fff; box-shadow: 0 0 0 4px rgba(13,141,137,.09); }
textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.form-error { min-height: 1.25em; margin: 7px 0; color: var(--red); font-size: .82rem; }

.button {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 17px; border: 1px solid transparent; border-radius: 13px; font-weight: 750;
  transition: transform .16s, background .16s, box-shadow .16s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; pointer-events: none; }
.button.primary { color: #fff; background: var(--ink); box-shadow: 0 8px 20px rgba(23,25,31,.16); }
.button.primary:hover { background: #2c3038; }
.button.secondary { color: var(--ink); background: rgba(255,255,255,.86); border-color: var(--line); }
.button.wide { width: 100%; }
.text-button { border: 0; padding: 10px 0; background: transparent; color: var(--teal); font-weight: 750; }
.auth-card > .text-button { width: 100%; margin-top: 7px; }
.text-button.danger { color: var(--red); }

.topbar {
  width: min(1080px, calc(100% - 32px)); height: 64px; position: sticky; top: 12px; z-index: 8;
  display: flex; align-items: center; justify-content: space-between; margin: 12px auto 0; padding: 0 13px 0 11px;
  border: 1px solid rgba(255,255,255,.9); border-radius: 22px; background: rgba(255,255,255,.78);
  box-shadow: 0 10px 30px rgba(36,51,59,.07); backdrop-filter: blur(20px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: -.025em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .avatar-button {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid var(--line);
  border-radius: 14px; color: var(--ink); background: rgba(255,255,255,.9); font-size: 1.2rem;
}
.avatar-button { border: 0; border-radius: 50%; color: #126f6c; background: var(--teal-soft); font-size: .84rem; font-weight: 850; }
.account-wrap { position: relative; }
.account-menu {
  position: absolute; top: calc(100% + 10px); right: 0; width: 240px; padding: 14px;
  border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.96);
  box-shadow: 0 18px 45px rgba(25,35,42,.16); backdrop-filter: blur(18px);
}
.account-label { margin: 0 0 5px; color: var(--muted); font-size: .65rem; font-weight: 850; letter-spacing: .12em; }
.account-email { margin: 0 0 12px; overflow: hidden; color: var(--ink); font-size: .84rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.account-signout { width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; color: var(--ink); background: #f1f4f4; text-align: left; font-weight: 750; }

main { width: min(1020px, calc(100% - 40px)); margin: 0 auto; padding: 58px 0 100px; }
.heading-row { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.heading-row .eyebrow { margin: 0 0 7px; }
.heading-row h2 { max-width: 620px; margin: 0; font-size: clamp(2.15rem, 4.6vw, 3.6rem); line-height: .98; letter-spacing: -.055em; }
.add-button { flex: none; border-radius: 15px; padding-inline: 19px; }
.add-button span { font-size: 1.2rem; font-weight: 400; }

.search-wrap { margin-top: 25px; animation: drop .18s ease; }
.search-wrap input { height: 50px; padding-left: 17px; background: rgba(255,255,255,.76); box-shadow: 0 8px 24px rgba(40,54,62,.05); }
@keyframes drop { from { opacity: 0; transform: translateY(-5px); } }

.status-nav { display: flex; gap: 6px; margin: 32px 0 23px; padding: 5px; width: max-content; border-radius: 16px; background: rgba(255,255,255,.56); }
.status-tab {
  min-height: 40px; display: flex; align-items: center; gap: 7px; padding: 8px 13px;
  border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-weight: 750;
}
.status-tab span { min-width: 21px; padding: 3px 6px; border-radius: 99px; color: var(--muted); background: rgba(23,25,31,.06); font-size: .7rem; }
.status-tab.active { color: #fff; background: var(--ink); box-shadow: 0 7px 16px rgba(23,25,31,.14); }
.status-tab.active span { color: var(--ink); background: #fff; }

.kind-filters {
  display: flex; align-items: center; gap: 6px; margin: -9px 0 21px;
  overflow-x: auto; scrollbar-width: none;
}
.kind-filters::-webkit-scrollbar { display: none; }
.kind-filter {
  flex: none; min-height: 34px; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 999px; color: #68717b; background: rgba(255,255,255,.46);
  font-size: .74rem; font-weight: 750; transition: color .16s, background .16s, border-color .16s;
}
.kind-filter:hover { color: var(--ink); background: rgba(255,255,255,.84); }
.kind-filter.active { color: #087b77; border-color: rgba(13,141,137,.13); background: var(--teal-soft); }

.resurface {
  display: grid; grid-template-columns: 220px 1fr; gap: 20px; margin: 0 0 18px; padding: 22px;
  border: 0; border-radius: 21px; background: linear-gradient(125deg, rgba(223,243,240,.96), rgba(255,255,255,.72));
}
.resurface .eyebrow { margin: 0 0 6px; }
.resurface h3 { margin: 0; font-size: .94rem; }
.resurface-list { display: flex; gap: 9px; overflow-x: auto; }
.resurface-chip { flex: none; max-width: 220px; padding: 10px 12px; border: 0; border-radius: 11px; color: var(--ink); background: rgba(255,255,255,.85); text-align: left; }
.resurface-chip strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resurface-chip small { color: var(--muted); }

.thread-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.thread-card {
  position: relative; min-height: 164px; width: 100%; display: grid; grid-template-columns: 42px minmax(0,1fr) 16px;
  gap: 13px; align-items: start; padding: 19px; border: 1px solid rgba(255,255,255,.72); border-radius: 21px;
  color: var(--ink); background: rgba(255,255,255,.8); box-shadow: 0 10px 28px rgba(43,60,67,.055);
  text-align: left; transition: transform .16s, box-shadow .16s, background .16s;
}
.thread-card:nth-child(4n+1) .kind-icon { background: var(--teal-soft); color: #087b77; }
.thread-card:nth-child(4n+2) .kind-icon { background: var(--peach); color: #ad6044; }
.thread-card:nth-child(4n+3) .kind-icon { background: var(--blue-soft); color: #4777aa; }
.thread-card:nth-child(4n) .kind-icon { background: var(--yellow); color: #8a7425; }
.thread-card:hover { transform: translateY(-2px); background: #fff; box-shadow: 0 17px 35px rgba(43,60,67,.09); }
.kind-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; font-size: .9rem; font-weight: 850; }
.card-body { min-width: 0; }
.card-meta { display: flex; gap: 7px; align-items: center; margin-bottom: 7px; color: #78828d; font-size: .68rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.thread-card h3 { margin: 0 0 11px; font-size: 1.04rem; line-height: 1.27; letter-spacing: -.015em; }
.context-line, .next-line, .notes-preview {
  margin: 5px 0 0; display: -webkit-box; overflow: hidden; color: var(--muted);
  font-size: .84rem; line-height: 1.42; -webkit-box-orient: vertical;
}
.context-line { -webkit-line-clamp: 2; }
.next-line { color: #394048; -webkit-line-clamp: 1; }
.next-line strong { color: var(--teal); }
.notes-preview { padding-top: 6px; border-top: 1px solid var(--line); font-size: .78rem; -webkit-line-clamp: 1; }
.card-arrow { color: #9aa3ab; font-size: 1.1rem; }

.empty-state { padding: 66px 20px; border: 0; border-radius: 24px; background: rgba(255,255,255,.54); text-align: center; }
.empty-glyph { width: 46px; height: 46px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 15px; color: #087b77; background: var(--teal-soft); font-size: 1.25rem; }
.empty-state h3 { margin: 0 0 7px; }
.empty-state p { max-width: 450px; margin: 0 auto 19px; color: var(--muted); line-height: 1.55; }

dialog { width: min(650px, calc(100% - 26px)); max-height: calc(100vh - 26px); padding: 0; border: 0; border-radius: 26px; color: var(--ink); background: #fff; box-shadow: 0 30px 90px rgba(19,26,30,.27); }
dialog::backdrop { background: rgba(22,29,34,.44); backdrop-filter: blur(7px); }
.thread-form { max-height: calc(100vh - 26px); overflow-y: auto; padding: 27px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-header .eyebrow { margin: 2px 0 6px; }
.dialog-header h2 { margin: 0; font-size: 1.45rem; letter-spacing: -.035em; }
.title-field { margin-top: 23px; }
.title-field input { padding: 15px; font-size: 1.04rem; font-weight: 700; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.dialog-actions { display: flex; align-items: center; gap: 9px; padding-top: 10px; }
.action-spacer { flex: 1; }
.mobile-close { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 20; transform: translate(-50%,20px);
  display: flex; align-items: center; min-width: max-content;
  padding: 11px 12px 11px 16px; border-radius: 12px; color: #fff; background: var(--ink);
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%,0); }
.toast-action {
  margin-left: 12px; padding: 5px 9px; border: 0; border-radius: 8px;
  color: var(--ink); background: #fff; font-weight: 800;
}
.thread-card.is-completed { background: rgba(244,246,246,.72); box-shadow: none; }
.thread-card.is-completed h3 { color: #626a72; }
.thread-card.is-completed .kind-icon { color: #747d84; background: #e6e9e9; }

@media (max-width: 760px) {
  body { background: linear-gradient(180deg, #f1f7f7 0%, #f6f2f0 100%); }
  .auth-card { padding: 29px 23px; }
  .topbar { width: calc(100% - 24px); height: 58px; top: 10px; margin-top: 10px; padding: 0 9px; border-radius: 19px; }
  .brand { gap: 9px; font-size: .95rem; }
  .brand-mark.small { width: 36px; height: 36px; }
  .icon-button, .avatar-button { width: 38px; height: 38px; border-radius: 13px; }
  .avatar-button { border-radius: 50%; }
  main { width: calc(100% - 28px); padding: 43px 0 156px; }
  .heading-row { display: block; }
  .heading-row h2 { max-width: 300px; font-size: 2rem; line-height: 1.02; }
  .heading-row .eyebrow { margin-bottom: 6px; }
  .add-button {
    position: fixed; right: 17px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 7;
    width: 56px; height: 56px; min-height: 56px; padding: 0; border-radius: 18px; font-size: 0;
    box-shadow: 0 13px 28px rgba(23,25,31,.25);
  }
  .add-button span { font-size: 1.6rem; }
  .search-wrap { margin-top: 21px; }
  .status-nav {
    position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 6; transform: translateX(-50%);
    width: calc(100% - 28px); display: grid; grid-template-columns: repeat(4,1fr); gap: 3px;
    margin: 0; padding: 5px; border: 1px solid rgba(255,255,255,.82); border-radius: 20px;
    background: rgba(25,28,33,.94); box-shadow: 0 15px 38px rgba(17,22,26,.25); backdrop-filter: blur(18px);
  }
  .status-tab { min-width: 0; min-height: 48px; flex-direction: column; justify-content: center; gap: 2px; padding: 5px 2px; border-radius: 15px; color: rgba(255,255,255,.58); font-size: .67rem; line-height: 1; }
  .status-tab span { min-width: 17px; padding: 2px 4px; color: rgba(255,255,255,.7); background: rgba(255,255,255,.1); font-size: .6rem; }
  .status-tab.active { color: var(--ink); background: #fff; box-shadow: none; }
  .status-tab.active span { color: #fff; background: var(--teal); }
  .kind-filters {
    width: calc(100vw - 28px); margin: 22px 0 0; padding: 1px 0 3px;
    scroll-padding-inline: 2px;
  }
  .kind-filter { min-height: 36px; padding: 8px 13px; background: rgba(255,255,255,.62); }
  .kind-filter.active { background: var(--teal-soft); }
  .thread-list { grid-template-columns: 1fr; gap: 10px; margin-top: 25px; }
  .thread-card { grid-template-columns: 40px minmax(0,1fr) 14px; gap: 11px; min-height: 0; padding: 16px; border-radius: 19px; }
  .kind-icon { width: 40px; height: 40px; border-radius: 13px; }
  .thread-card h3 { margin-bottom: 9px; font-size: 1rem; }
  .card-meta { gap: 5px; font-size: .64rem; }
  .context-line, .next-line { font-size: .82rem; }
  .notes-preview { font-size: .76rem; }
  .resurface { grid-template-columns: 1fr; padding: 18px; }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
  dialog {
    width: calc(100% - 24px);
    height: calc(100dvh - 24px);
    max-height: none;
    margin: 12px auto;
    overflow: hidden;
    border-radius: 24px;
  }
  .thread-form {
    height: 100%;
    max-height: none;
    padding: 20px;
    overscroll-behavior: contain;
  }
  .dialog-header > #close-dialog { display: none; }
  .thread-form label { gap: 7px; margin: 12px 0; }
  .title-field { margin-top: 18px !important; }
  .dialog-actions {
    position: sticky;
    bottom: -20px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "delete empty archive"
      "close save save";
    gap: 9px;
    margin: 16px -20px -20px;
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.97);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }
  .dialog-actions .action-spacer { display: none; }
  #delete-thread { grid-area: delete; justify-self: start; }
  #archive-thread { grid-area: archive; }
  #save-thread { grid-area: save; width: 100%; }
  .dialog-actions .mobile-close { grid-area: close; display: inline-flex; width: 100%; }
  .dialog-actions .button { padding-inline: 14px; white-space: nowrap; }
  .toast { bottom: 96px; }
}
@media (max-width: 370px) {
  .status-tab { font-size: .62rem; }
  .top-actions { gap: 5px; }
}
@media (prefers-reduced-motion: reduce) { *,*::before,*::after { scroll-behavior: auto !important; transition: none !important; } }