/* 视觉基线沿用同仓库 keepass/app/static/styles.css 的暗色调色板 */
:root {
  --bg: #0f1217;
  --panel: #161b22;
  --panel-2: #1c2330;
  --line: #262d3a;
  --fg: #d7dee8;
  --muted: #8b98a9;
  --accent: #3b82f6;
  --danger: #ef4444;
  --warn: #d97706;
  --ok: #16a34a;
  --radius: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
button, input, select, textarea {
  font: inherit; color: inherit; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.ghost { background: transparent; }
button.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .45; cursor: not-allowed; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
input, select, textarea { width: 100%; }
.row > input, .row > select { flex: 1; }
textarea { min-height: 60px; resize: vertical; }
.muted { color: var(--muted); font-size: 12px; }
.err { color: var(--danger); font-size: 12px; min-height: 18px; margin: 8px 0 0; }
.spacer { flex: 1; }

header#topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { font-weight: 600; }
.brand em { color: var(--accent); font-style: normal; }
.field-inline { display: flex; align-items: center; gap: 6px; }
.field-inline > span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.field-inline select { width: auto; }

.tabs { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px; }
.tabs button { border: none; background: transparent; padding: 5px 14px; border-radius: 6px;
  color: var(--muted); }
.tabs button.active { background: var(--accent); color: #fff; }

.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
  font-size: 12px; cursor: pointer; user-select: none; }
.toggle input { width: auto; }

.who { display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 600; color: #fff; flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* 提醒铃铛 */
.bell { position: relative; }
.bell .badge-count { position: absolute; top: -6px; right: -6px; background: var(--danger);
  color: #fff; font-size: 10px; border-radius: 99px; min-width: 16px; height: 16px;
  display: grid; place-items: center; padding: 0 4px; }
.bell-panel { position: absolute; right: 0; top: 38px; width: 320px; max-height: 60vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 40; padding: 6px; }
.bell-panel h3 { margin: 6px 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.bell-item { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.bell-item:hover { background: var(--panel-2); }
.bell-item .when { font-size: 11px; margin-left: auto; white-space: nowrap; }
.bell-item .when.overdue { color: var(--danger); }
.bell-item .when.soon { color: var(--warn); }

main { padding: 16px; min-height: calc(100vh - 57px); }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 14px; }
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; }
.filters label { margin: 0; width: auto; }
.board-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.board-pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px;
  padding: 4px 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.board-pill.active { border-color: var(--accent); background: #17325c; }
/* 药丸上的就地管理按钮：平时淡、悬起才亮，避免抢走「切换看板」的视觉主体 */
.board-pill button { border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 0 2px; font-size: 12px; line-height: 1; border-radius: 4px; }
.board-pill button:hover { color: var(--fg); background: rgba(255,255,255,.08); }
.board-pill button.del:hover { color: var(--danger); }
.board-pill button:disabled { opacity: .35; cursor: not-allowed; }
.col-head .col-act { color: var(--muted); cursor: pointer; border: none; background: transparent;
  padding: 0 3px; font-size: 12px; line-height: 1; border-radius: 4px; }
.col-head .col-act:hover { color: var(--fg); background: rgba(255,255,255,.08); }
.col-head .col-act.del:hover { color: var(--danger); }
.col-head .col-act:disabled { opacity: .3; cursor: not-allowed; }

/* 看板 */
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: 290px; flex: none; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); }
.col-head .name { font-weight: 600; }
.col-head .count { color: var(--muted); font-size: 12px; margin-left: auto; }
.col-head .fold { color: var(--muted); cursor: pointer; border: none; background: transparent; padding: 0 4px; }
.col-body { padding: 8px; min-height: 60px; display: flex; flex-direction: column; gap: 8px; }
.col-body.dragover { background: var(--panel-2); outline: 2px dashed var(--accent); outline-offset: -4px; }
.col.collapsed .col-body { display: none; }
.add-col { flex: none; align-self: stretch; border: 1px dashed var(--line); background: transparent;
  color: var(--muted); border-radius: var(--radius); padding: 10px 14px; }
.tcard { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; cursor: grab; }
.tcard:hover { border-color: var(--accent); }
.tcard.done .t { text-decoration: line-through; color: var(--muted); }
.tcard .t { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tcard .t .rt { color: var(--warn); font-size: 12px; }
.tcard .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 10px; padding: 1px 7px; border-radius: 99px; color: #fff; }
.tcard .meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.tcard .due { font-variant-numeric: tabular-nums; }
.tcard .due.overdue { color: var(--danger); }
.tcard .due.soon { color: var(--warn); }
.tcard .sub { color: var(--muted); }
.tcard .avatar { width: 20px; height: 20px; font-size: 10px; margin-left: auto; }
.prio { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: none; }
.prio.high { background: var(--danger); } .prio.med { background: var(--warn); } .prio.low { background: var(--muted); }
.progress { height: 4px; background: var(--line); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* 日历 */
.cal-wrap { max-width: 1000px; }
.cal-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cal-toolbar button { width: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--panel); padding: 6px; text-align: center; color: var(--muted); font-size: 12px; }
.cal-cell { background: var(--bg); min-height: 100px; padding: 6px; cursor: pointer; }
.cal-cell:hover { background: var(--panel); }
.cal-cell.out { color: var(--muted); opacity: .45; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-cell .d { font-size: 12px; margin-bottom: 4px; }
.cal-pill { font-size: 11px; border-radius: 4px; padding: 1px 5px; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.cal-pill .clock { opacity: .85; }
.cal-pill.virtual { opacity: .72; border: 1px dashed rgba(255,255,255,.45); }
/* 已完成的那一次：划掉 + 变暗，与「预览还没物化」的虚线区分开 */
.cal-pill.done { opacity: .5; text-decoration: line-through; }

/* 列表 */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--muted); font-size: 12px; font-weight: 500; }
table.list tr:hover td { background: var(--panel); }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.badge.done { color: var(--ok); border-color: var(--ok); }
.badge.rt { color: var(--warn); border-color: var(--warn); }
.badge.ro { color: var(--danger); border-color: var(--danger); }
.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.pager button { width: auto; }

dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; width: min(600px, 94vw); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 8px; font-size: 18px; padding-right: 30px; }
/* ✕ 钉在滚动区顶部、按钮条钉在底部：长弹层不用拉到最下面也能关掉 */
.dlg-head { position: sticky; top: -20px; z-index: 2; display: flex; justify-content: flex-end;
  height: 0; margin: 0; }
.dlg-x { width: 26px; height: 26px; padding: 0; font-size: 14px; line-height: 1; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.dlg-x:hover { color: var(--fg); background: var(--panel-2); }
dialog menu { position: sticky; bottom: -20px; margin: 18px -20px -20px; padding: 12px 20px 16px;
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
section.block { margin-top: 14px; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
section.block > .block-head { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

/* 标签编辑器 */
.tag-editor { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag-editor .tag { cursor: pointer; }
.tag-editor .tag .x { opacity: .7; margin-left: 4px; }

/* 子任务编辑器 */
.sub-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sub-list li { display: flex; align-items: center; gap: 8px; }
.sub-list li input[type="checkbox"] { width: auto; }
.sub-list li input[type="text"] { flex: 1; }
.sub-list li .rm { color: var(--danger); border: none; background: transparent; }

details.routine summary { cursor: pointer; color: var(--muted); }
.wk { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.wk button { padding: 4px 8px; font-size: 12px; }
.wk button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.preview { margin-top: 10px; padding: 8px 10px; background: var(--panel-2); border-radius: 6px; font-size: 12px; }
.preview b { color: var(--warn); }
menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; align-items: center; }
menu button { width: auto; }

.toast { position: fixed; right: 16px; bottom: 16px; background: var(--panel-2);
  border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; z-index: 60; }
.toast.error { border-color: var(--danger); color: #fecaca; }

/* 任务/卡片状态圆圈：手机版 todo 交互 —— 点一下完成，再点撤销 */
.sbtn { width: 26px; height: 26px; min-width: 26px; padding: 0; border-radius: 50%;
  background: transparent; border: 2px solid var(--muted); display: inline-grid; place-items: center;
  flex: none; color: #fff; font-size: 13px; line-height: 1; }
.sbtn:hover { border-color: var(--accent); }
.sbtn.on { background: var(--ok); border-color: var(--ok); }
.sbtn .ring { display: block; width: 100%; text-align: center; }
td.ck { width: 34px; padding-right: 0; }
.tcard .t .sbtn { width: 20px; height: 20px; min-width: 20px; font-size: 11px; }

/* 列头把手与列菜单 */
.col-head.drag-handle { cursor: grab; }
.col-head.drag-handle:active { cursor: grabbing; }
.col.col-dragover { outline: 2px dashed var(--accent); outline-offset: -2px; }
.col-menu { position: absolute; right: 8px; top: 42px; z-index: 45; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,.5); padding: 4px; }
.col { position: relative; }
.menu-item { display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.menu-item:hover { background: var(--panel-2); }
.menu-item:disabled { opacity: .4; }

/* 任务弹层「更多设置」折叠区 */
details.more { margin-top: 14px; border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 9px 0; user-select: none; }
details.more[open] > summary { border-bottom: 1px dashed var(--line); }
details.more[data-filled] > summary::after { content: " ●"; color: var(--accent); }
details.more > *:last-child { margin-bottom: 12px; }

/* 移动端列表卡片：圆圈在最左，内容占其余 */
.mrow { flex-direction: row; align-items: flex-start; gap: 10px; }
.mrow .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.mrow .sbtn { margin-top: 2px; }

#mgmtTabs { margin: 12px 0; width: fit-content; }
.mgmt-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; margin-bottom: 6px; background: var(--panel-2); flex-wrap: wrap; }
.mgmt-row .nm { font-weight: 600; }
.mgmt-row .cnt { color: var(--muted); font-size: 12px; }
.mgmt-row select { width: auto; padding: 3px 8px; font-size: 12px; }
/* 停用中的账号整行压暗：一眼分得出哪些是还能用的 */
.mgmt-row.off { opacity: .6; }
.mgmt-row.off .nm { text-decoration: line-through; }
.mgmt-add { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.mgmt-add input, .mgmt-add select { width: auto; }

@media (max-width: 900px) {
  header#topbar { gap: 6px; }
  .cols2, .cols3 { grid-template-columns: 1fr; }
}

/* 抽屉与遮罩默认不存在于布局（media 内才亮出固定面板形态） */
#drawer { display: none; }
#drawerMask { display: none; }
#bottomBar { display: none; }
#fabNew { display: none; }

/* ================= 移动端（≤640px）=================
 * 策略：桌面 DOM 原样保留，JS 把控件重排进抽屉/底栏/FAB（同一批节点搬家，事件不丢）；
 * 这里只负责搬家后的容器样式 + 触摸友好尺寸 + 弹层底部抽屉化。 */
.mobile-only { display: none !important; }
@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 15px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: initial !important; }

  /* 顶栏只留：品牌 + 项目 + 铃铛 + 菜单 */
  header#topbar { padding: 8px 10px; gap: 8px; flex-wrap: nowrap;
    padding-top: calc(8px + env(safe-area-inset-top)); }
  header#topbar .spacer { flex: 1; }
  header#topbar .field-inline > span { display: none; }
  header#topbar #newTaskBtn { display: none; }
  header#topbar .who { display: none; }
  header#topbar .toggle { display: none; }
  .brand { font-size: 15px; }
  #projectSel { max-width: 44vw; }

  /* 汉堡按钮 */
  #menuBtn { width: 40px; height: 40px; padding: 0; font-size: 18px; flex: none; }

  /* 抽屉：右侧滑入 */
  #drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 86vw);
    background: var(--panel); border-left: 1px solid var(--line); z-index: 80;
    transform: translateX(102%); transition: transform .22s ease;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); overflow: auto;
    display: flex; flex-direction: column; gap: 14px; }
  #drawer.open { transform: translateX(0); }
  #drawerMask { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 70; }
  #drawer .field-inline, #drawer .who { flex-wrap: wrap; }
  #drawer button { min-height: 42px; }
  #drawer .toggle { font-size: 14px; padding: 10px 0; }

  /* 底部视图切换栏（.tabs 搬家进来） */
  #bottomBar { display: none; }
  body.chrome-ready #bottomBar {
    display: flex; justify-content: space-around; align-items: center; position: fixed;
    left: 0; right: 0; bottom: 0; z-index: 30; background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  #bottomBar .tabs { border: none; background: transparent; padding: 0; width: 100%; }
  #bottomBar .tabs button { flex: 1; min-height: 44px; font-size: 15px; border-radius: 8px; }

  /* FAB 新建按钮 */
  #fabNew { display: none; position: fixed; right: 16px; z-index: 31;
    bottom: calc(76px + env(safe-area-inset-bottom)); width: 52px; height: 52px;
    border-radius: 50%; font-size: 26px; padding: 0; box-shadow: 0 6px 20px rgba(0,0,0,.55);
    background: var(--accent); border-color: var(--accent); color: #fff; }
  body.chrome-ready #fabNew { display: block; }

  main { padding: 10px; min-height: calc(100dvh - 120px); }

  /* 看板：整列吸附横滑 */
  .board { scroll-snap-type: x proximity; }
  .col { width: min(92vw, 320px); scroll-snap-align: start; }
  .col-body { touch-action: pan-y; }

  /* 卡片：触摸拖拽时抬起态 */
  .tcard { padding: 10px 12px; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
  .tcard.dragging { opacity: .35; }
  .drag-ghost { position: fixed; z-index: 100; pointer-events: none; width: 86vw; max-width: 320px;
    box-shadow: 0 14px 40px rgba(0,0,0,.6); transform: rotate(1.5deg) scale(1.02); opacity: .95; }
  .col-body.drag-over { background: #17325c; outline: 2px dashed var(--accent); outline-offset: -4px; }

  /* 弹层：移动端全屏页（小表单也占满，靠底部按钮条钉底保住主操作） */
  dialog { position: fixed; inset: 0; width: 100vw; max-width: 100vw; height: 100dvh;
    max-height: 100dvh; margin: 0; border: none; border-radius: 0; overflow: auto;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }
  dialog h2 { font-size: 17px; }
  dialog menu { position: sticky; bottom: 0; margin: 16px -14px calc(-14px - env(safe-area-inset-bottom));
    padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); }
  dialog menu button { min-height: 44px; flex: none; }
  button.primary, dialog menu button { font-size: 15px; }
  input, select, textarea { min-height: 42px; font-size: 15px; }
  .cols2 select, .cols2 input { min-height: 44px; }

  /* 提醒面板全宽 */
  .bell-panel { position: fixed; left: 8px; right: 8px; top: auto; bottom: calc(68px + env(safe-area-inset-bottom));
    width: auto; max-height: 55dvh; z-index: 85; }
  .bell-item { padding: 12px 10px; min-height: 44px; align-items: center; }

  /* 日历：矮格 + 少药丸 */
  .cal-cell { min-height: 54px; padding: 4px; }
  .cal-pill { max-width: 100%; font-size: 10px; padding: 1px 4px; }
  .cal-dow { font-size: 11px; padding: 4px; }

  /* 列表卡片视图（JS 在移动模式下渲染 .mrow 而非 table）：圆圈在左、内容在右 */
  .mrow { display: flex; flex-direction: row; align-items: flex-start; gap: 10px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
  .mrow .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  .mrow .sbtn { width: 28px; height: 28px; margin-top: 1px; }
  .mrow .top { display: flex; align-items: center; gap: 8px; font-weight: 600; }
  .mrow .top .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mrow .sub { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
  .mrow.done .title { text-decoration: line-through; color: var(--muted); }

  /* 筛选条换行友好 */
  .filters { gap: 6px; }
  .filters select, .filters input { font-size: 13px; min-height: 38px; }
  .toast { left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); }
}

/* 请求进行中：顶部一条进度光带，并禁掉重复点击 */
body.busy::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 90;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: slide 1.1s linear infinite;
}
body.busy .tcard, body.busy .cal-cell { pointer-events: none; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
