:root {
  --bg: #0d0e10;
  --panel: #15171a;
  --panel-2: #1b1d21;
  --hover: #1e2125;
  --border: #23262b;
  --border-2: #2e3238;
  --text: #e6e6e6;
  --muted: #8a8f98;
  --faint: #5c616a;
  --accent: #7c6cff;
  --accent-2: #9488ff;
  --danger: #eb5757;
  --warn: #f2994a;
  --radius: 6px;
  --sidebar: 232px;
  --panel-w: min(760px, 58vw);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { line-height: 1.45; -webkit-font-smoothing: antialiased; overflow: hidden; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
kbd {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 5px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--border-2); color: var(--muted);
}
.muted { color: var(--muted); }
.hint { font-size: 12px; }
.spacer { flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
svg { flex: none; display: block; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--border-2); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: #3a3e45; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: #ff8a8a; }
.btn.danger:hover { border-color: var(--danger); }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius);
  background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.sm { width: 22px; height: 22px; font-size: 14px; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--muted); cursor: pointer; text-align: left; font-size: 12px; }
.link-btn:hover { color: var(--text); text-decoration: none; }
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: var(--radius); overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 0 12px; height: 28px; color: var(--muted); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border-2); }
.seg button.on { background: var(--panel-2); color: var(--text); }

/* layout */
#app { display: flex; height: 100vh; height: 100dvh; }
#sidebar {
  width: var(--sidebar); flex: none; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 10px 8px; overflow-y: auto;
}
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#scrim { display: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 4px 8px 12px; font-size: 14px; }
.logo-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent) url("/favicon.svg") center/cover; display: inline-block; }
.nav-item {
  display: flex; align-items: center; gap: 8px; padding: 0 8px; height: 30px; border-radius: var(--radius);
  color: var(--text); text-decoration: none !important;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: #23252b; }
.nav-item.dim { opacity: .55; }
.nav-ico { width: 16px; display: grid; place-items: center; color: var(--muted); }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.nav-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.key-badge {
  font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--border-2); padding: 3px 4px; border-radius: 4px; min-width: 34px; text-align: center; flex: none;
}
.key-badge.lg { font-size: 12px; padding: 4px 7px; color: var(--text); }
.nav-foot { margin-top: auto; padding: 12px 8px 4px; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); }

#topbar { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 48px; border-bottom: 1px solid var(--border); flex: none; }
#title { font-size: 14px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#filterbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); flex: none; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.fbtn {
  height: 26px; padding: 0 9px; border-radius: 13px; border: 1px dashed var(--border-2); background: transparent;
  color: var(--muted); cursor: pointer; font-size: 12px; white-space: nowrap;
}
.fbtn:hover { color: var(--text); border-color: #3a3e45; }
.fbtn.on { border-style: solid; color: var(--text); background: #1f1d33; border-color: #3d3670; }
.fbtn.clear { border: 0; }
.search { margin-left: auto; }
.search input {
  height: 28px; width: 220px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel);
  padding: 0 10px; outline: none;
}
.search input:focus, .input:focus, .form input:focus, .form select:focus, .form textarea:focus, textarea:focus { border-color: var(--accent); outline: none; }
#content { flex: 1; overflow: auto; outline: none; }
#footer { display: flex; gap: 14px; padding: 6px 16px; border-top: 1px solid var(--border); color: var(--faint); font-size: 11px; flex: none; }
#footer kbd { font-size: 10px; padding: 1px 4px; }

/* project header */
.project-head { padding: 14px 16px 6px; border-bottom: 1px solid var(--border); }
.ph-row { display: flex; align-items: center; gap: 10px; }
.ph-counts { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.count-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 12px; color: var(--muted); font-size: 12px; }
.count-pill b { color: var(--text); font-weight: 600; }
.ph-desc { max-width: 820px; color: #c9ccd1; margin-top: 6px; }
.pstatus { font-size: 11px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border-2); color: var(--muted); }
.pstatus-active { color: #4cb782; border-color: #2b4d3b; }
.pstatus-paused { color: var(--warn); border-color: #4d3a26; }
.pstatus-done { color: var(--accent-2); border-color: #3d3670; }

/* list */
.group-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); cursor: pointer; user-select: none;
}
.group-head:hover { background: #181a1e; }
.chev { width: 10px; color: var(--muted); font-size: 10px; transition: transform .12s; }
.chev.open { transform: rotate(90deg); }
.g-name { font-weight: 500; }
.g-count { color: var(--muted); font-size: 12px; }
.row {
  display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 16px; border-bottom: 1px solid #191b1f;
  cursor: pointer; outline: none;
}
.row:hover { background: #16181b; }
.row.sel { background: #1a1b24; box-shadow: inset 2px 0 0 var(--accent); }
.row.open { background: #1d1c2b; }
.r-pri { width: 16px; display: grid; place-items: center; }
.r-ident { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 62px; white-space: nowrap; }
.r-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-labels { display: flex; gap: 4px; flex: none; max-width: 40%; overflow: hidden; }
.r-proj { color: var(--faint); font-size: 11px; font-family: ui-monospace, Menlo, monospace; }
.r-cc { color: var(--faint); font-size: 11px; }
.r-upd { color: var(--faint); font-size: 12px; width: 62px; text-align: right; white-space: nowrap; flex: none; }
.due { font-size: 12px; color: var(--muted); white-space: nowrap; padding: 1px 6px; border: 1px solid var(--border-2); border-radius: 4px; }
.due.overdue, input.overdue { color: #ff7b7b; border-color: #5a2a2a; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 11px;
  border: 1px solid var(--border-2); color: #c9ccd1; white-space: nowrap; flex: none;
}
.chip i, .chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }
.chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 13px; line-height: 1; }
.chip-x:hover { color: var(--text); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* board */
.board { display: flex; gap: 10px; padding: 12px 16px; height: 100%; min-height: 300px; overflow-x: auto; align-items: flex-start; }
.project-head + .board { height: auto; }
.col { width: 280px; flex: none; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; max-height: 100%; }
.col.drop { border-color: var(--accent); background: #17162a; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-weight: 500; }
.col-body { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 40px; }
.card { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.card:hover { border-color: #3a3e45; }
.card.sel { border-color: var(--accent); }
.card.dragging { opacity: .4; }
.card-top { display: flex; align-items: center; gap: 6px; }
.card-title { margin: 4px 0 6px; overflow-wrap: anywhere; }
.card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.card-status { margin-left: auto; height: 24px; background: var(--panel); border: 1px solid var(--border-2); border-radius: 4px; font-size: 11px; color: var(--muted); max-width: 104px; }

/* panel */
#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-w); background: var(--bg); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 20; box-shadow: -12px 0 32px rgba(0,0,0,.45);
}
#panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 12px; border-bottom: 1px solid var(--border); flex: none; }
.crumb { color: var(--muted); }
.crumb-ident { font-variant-numeric: tabular-nums; }
.panel-body { flex: 1; overflow: auto; display: flex; }
.panel-main { flex: 1; min-width: 0; padding: 18px 22px 30px; }
.panel-props { width: 230px; flex: none; border-left: 1px solid var(--border); padding: 14px 14px; background: var(--panel); display: flex; flex-direction: column; gap: 4px; }
.title-input {
  width: 100%; resize: none; border: 1px solid transparent; background: transparent; font-size: 19px; font-weight: 600;
  padding: 4px 6px; margin: 0 -6px 8px; border-radius: var(--radius); overflow: hidden; line-height: 1.3;
}
.title-input:hover { border-color: var(--border); }
.desc-view { position: relative; margin-bottom: 18px; }
.desc-view .md { min-height: 20px; }
.desc-empty { padding: 8px 0; cursor: text; }
.edit-desc { margin-top: 4px; }
.desc-edit { margin-bottom: 18px; border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--panel); }
.tabs { display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; color: var(--muted); padding: 4px 10px; border-radius: 4px; cursor: pointer; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.desc-input { width: 100%; min-height: 180px; border: 0 !important; background: transparent; padding: 10px 12px; resize: vertical; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.desc-preview { padding: 10px 12px; min-height: 180px; }
.desc-edit .row-actions { padding: 6px 8px; border-top: 1px solid var(--border); }
.row-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.timeline-head { font-weight: 600; margin: 8px 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.act { display: flex; align-items: baseline; gap: 8px; color: var(--muted); font-size: 12px; padding: 0 2px; }
.act b { color: #c9ccd1; font-weight: 500; }
.act-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border-2); flex: none; transform: translateY(-1px); }
.act-time { margin-left: auto; color: var(--faint); font-size: 11px; white-space: nowrap; }
.comment { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 12px; }
.c-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.avatar { width: 20px; height: 20px; border-radius: 50%; background: #2a2650; color: #c8c2ff; display: grid; place-items: center; font-size: 11px; font-weight: 600; }
.comment-box { margin-top: 14px; }
.comment-input { width: 100%; background: var(--panel); border: 1px solid var(--border-2); border-radius: 8px; padding: 10px 12px; resize: vertical; min-height: 70px; }
.prop { display: flex; flex-direction: column; gap: 3px; padding: 6px 0; }
.prop > span:first-child { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.prop-ctl { display: flex; align-items: center; gap: 6px; }
.prop select, .prop input[type="date"], .label-input {
  flex: 1; min-width: 0; height: 30px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 0 6px;
}
.prop-labels { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.label-input { flex: 1 1 100%; margin-top: 2px; }
.prop-stamps { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.prop-stamp { display: flex; flex-direction: column; font-size: 12px; }
.prop-stamp span:first-child { color: var(--muted); font-size: 11px; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; line-height: 1.3; }
.md h1 { font-size: 18px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14px; } .md h4, .md h5, .md h6 { font-size: 13px; }
.md code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: #1f2126; border: 1px solid var(--border); padding: 1px 4px; border-radius: 4px; }
.md pre { background: #121417; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md li.task { list-style: none; margin-left: -18px; }
.md li.task input { margin: 0 4px 0 0; vertical-align: -2px; accent-color: var(--accent); }
.md blockquote { margin: 0 0 8px; padding: 2px 12px; border-left: 3px solid var(--border-2); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

/* menus, modals, toast */
.menu {
  position: absolute; z-index: 50; min-width: 200px; max-height: 340px; overflow-y: auto; background: var(--panel-2);
  border: 1px solid var(--border-2); border-radius: 8px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.menu-item { display: flex; align-items: center; gap: 8px; padding: 0 8px; height: 32px; border-radius: 5px; cursor: pointer; }
.menu-item:hover { background: var(--hover); }
.menu-item input { accent-color: var(--accent); margin: 0; }
.menu-empty { padding: 8px; color: var(--muted); }
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60; }
.modal {
  position: fixed; z-index: 61; top: 10vh; left: 50%; transform: translateX(-50%); width: min(620px, calc(100vw - 24px));
  max-height: 80vh; overflow: auto; background: var(--panel); border: 1px solid var(--border-2); border-radius: 10px; padding: 16px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal h2 { font-size: 15px; margin: 0; }
.modal-head { display: flex; align-items: center; margin-bottom: 10px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.input, .form input, .form select, .form textarea, .copy-area {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 7px 10px; min-height: 34px;
}
.input.big { font-size: 15px; font-weight: 500; }
.form textarea, .copy-area { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.form-grid label > * { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 13px; }
.form-grid .wide { grid-column: span 2; }
.form[data-form="project"] .form-grid .wide { grid-column: 1 / -1; }
.form[data-form="project"] .form-grid { grid-template-columns: 1fr 1fr; }
.form[data-form="ticket"] .form-grid .wide { grid-column: 1 / -1; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.keys td:first-child { white-space: nowrap; width: 40%; color: var(--muted); }
#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 100;
  background: #26283a; border: 1px solid #3d3670; color: var(--text); padding: 8px 14px; border-radius: 8px; transition: all .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #3a1f22; border-color: #6b2c2c; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; overflow: auto; }
.login-card { width: min(340px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px; padding: 28px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.login-logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; margin-bottom: 6px; }
.login-input { height: 40px; padding: 0 12px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 8px; outline: none; font-size: 14px; }
.login-input:focus { border-color: var(--accent); }
.login-btn { height: 40px; justify-content: center; font-size: 14px; }
.login-error { color: #ff8a8a; font-size: 12px; }

.only-mobile { display: none; }

/* mobile */
@media (max-width: 760px) {
  :root { --panel-w: 100vw; }
  .only-mobile { display: inline-grid; }
  .hide-mobile { display: none !important; }
  #sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: 270px; transform: translateX(-100%); transition: transform .18s;
  }
  body.sidebar-open #sidebar { transform: none; }
  body.sidebar-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 39; }
  .nav-item { height: 40px; }
  #topbar { padding: 0 8px; gap: 6px; }
  #topbar .icon-btn, #topbar .btn, .seg button { height: 36px; min-width: 36px; }
  .btn[data-act="copy-view"], .btn[data-act="copy-ticket"] { font-size: 0; padding: 0 10px; }
  .btn[data-act="copy-view"]::after, .btn[data-act="copy-ticket"]::after { content: "Copy MD"; font-size: 12px; }
  #filterbar { padding: 8px; }
  .fbtn { height: 36px; border-radius: 18px; }
  .search { margin-left: 0; flex: 1 1 100%; }
  .search input { width: 100%; height: 36px; }
  .row { height: auto; min-height: 44px; flex-wrap: wrap; row-gap: 2px; padding: 6px 10px; }
  .r-title { flex: 1 1 60%; white-space: normal; }
  .r-labels { max-width: 100%; }
  .r-status { display: none; }
  .r-upd { width: auto; }
  .group-head { height: 40px; padding: 0 10px; }
  .icon-btn.sm { width: 36px; height: 36px; }
  .board { padding: 10px; scroll-snap-type: x proximity; }
  .col { width: 82vw; scroll-snap-align: start; }
  .card-status { height: 36px; font-size: 13px; max-width: 140px; }
  #panel { border-left: 0; }
  .panel-body { flex-direction: column; }
  .panel-props { width: auto; border-left: 0; border-bottom: 1px solid var(--border); order: -1; display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
  .panel-props .prop-stamps, .panel-props .prop:nth-child(4) { grid-column: 1 / -1; }
  .prop select, .prop input[type="date"], .label-input { height: 38px; }
  .panel-main { padding: 14px; }
  .panel-head .btn { height: 36px; }
  .panel-head .crumb { display: none; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .modal { top: 0; height: 100dvh; max-height: none; width: 100vw; border-radius: 0; }
  #footer { display: none; }
}
