:root {
  --bg: #f4f6f5; --surface: #ffffff; --surface-2: #eef2f1; --line: #dde4e2; --text: #17211f; --muted: #5c6b68;
  --brand: #0f766e; --brand-2: #115e59; --brand-soft: #d9f0ec; --on-brand: #ffffff;
  --late: #c2261d; --late-soft: #fde7e5; --wait: #a15c00; --wait-soft: #fdf0d9; --done: #1f7a35; --done-soft: #e1f3e5;
  --prog: #1d5fb8; --prog-soft: #e3edfb; --urgent: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 2px 8px rgba(16, 24, 22, .05);
  --radius: 14px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514; --surface: #172020; --surface-2: #1e2a29; --line: #2a3836; --text: #e6eeec; --muted: #9aaba7;
    --brand: #2bb3a5; --brand-2: #5fcdc0; --brand-soft: #173a37; --on-brand: #04201d;
    --late: #ff7b72; --late-soft: #3b1816; --wait: #f0b45a; --wait-soft: #3a2a10; --done: #6fd08a; --done-soft: #15301d;
    --prog: #7fb0f5; --prog-soft: #172a45; --urgent: #ff8a80; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1514; --surface: #172020; --surface-2: #1e2a29; --line: #2a3836; --text: #e6eeec; --muted: #9aaba7;
  --brand: #2bb3a5; --brand-2: #5fcdc0; --brand-soft: #173a37; --on-brand: #04201d;
  --late: #ff7b72; --late-soft: #3b1816; --wait: #f0b45a; --wait-soft: #3a2a10; --done: #6fd08a; --done-soft: #15301d;
  --prog: #7fb0f5; --prog-soft: #172a45; --urgent: #ff8a80; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.45rem; margin: 0; } h2 { font-size: 1.1rem; margin: 0; } h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .78rem; }
.row { display: flex; align-items: center; gap: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; } .hide { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 6px; padding: 8px 16px; }
.logo { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); margin-right: 10px; min-width: 0; }
.logo-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 800; flex: none; }
.nav { display: flex; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 999px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--brand-soft); color: var(--brand-2); font-weight: 650; }
.icon { width: 18px; height: 18px; flex: none; }
.iconbtn { position: relative; border: 0; background: transparent; border-radius: 999px; padding: 8px; cursor: pointer; display: grid; place-items: center; }
.iconbtn:hover { background: var(--surface-2); }
.badge-dot { position: absolute; top: 2px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--late); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.bottomnav { display: none; }

main { max-width: 1180px; margin: 0 auto; padding: 22px 16px 90px; }
.pagehead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card-h { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; }
.stat b { display: block; font-size: 1.9rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat.late { background: var(--late-soft); border-color: transparent; } .stat.late b { color: var(--late); }
.stat.wait { background: var(--wait-soft); border-color: transparent; } .stat.wait b { color: var(--wait); }
.stat.done { background: var(--done-soft); border-color: transparent; } .stat.done b { color: var(--done); }
.stat.prog { background: var(--prog-soft); border-color: transparent; } .stat.prog b { color: var(--prog); }
.banner { border-radius: 12px; padding: 10px 14px; background: var(--wait-soft); color: var(--text); margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.banner.info { background: var(--brand-soft); } .banner.bad { background: var(--late-soft); }

/* buttons & forms */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--late); } .btn.good { background: var(--done); border-color: var(--done); color: #fff; }
.btn.small { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
label.f { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 11px; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { resize: vertical; min-height: 84px; }
.field { margin-bottom: 12px; }
.fieldrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: .88rem; display: inline-flex; gap: 6px; align-items: center; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.error { color: var(--late); font-size: .9rem; margin-top: 6px; min-height: 1.2em; }
.mic { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center; flex: none; }
.mic.on { background: var(--late); color: #fff; border-color: var(--late); }

/* tasks */
.tasklist { display: flex; flex-direction: column; gap: 8px; }
.task { display: flex; gap: 12px; align-items: center; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; border-left: 4px solid var(--line); }
.task:hover { border-color: var(--brand); }
.task.is-late { border-left-color: var(--late); background: linear-gradient(90deg, var(--late-soft), var(--surface) 55%); }
.task.is-wait { border-left-color: var(--wait); } .task.is-done { border-left-color: var(--done); opacity: .85; }
.task.is-prog { border-left-color: var(--prog); }
.task .t-title { font-weight: 600; }
.task .t-meta { font-size: .84rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.tag { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.tag.late { background: var(--late); color: #fff; } .tag.todo { background: var(--surface-2); color: var(--muted); }
.tag.in_progress { background: var(--prog-soft); color: var(--prog); } .tag.waiting { background: var(--wait-soft); color: var(--wait); }
.tag.done { background: var(--done-soft); color: var(--done); } .tag.urgent { background: var(--late-soft); color: var(--urgent); }
.tag.high { background: var(--wait-soft); color: var(--wait); } .tag.low { background: var(--surface-2); color: var(--muted); }
.tag.ext { background: var(--prog-soft); color: var(--prog); }
.due-late { color: var(--late); font-weight: 700; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; font-weight: 700; font-size: .82rem; flex: none; }
.avatar.sm { width: 26px; height: 26px; font-size: .7rem; }
.group-h { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; }
.group-h .count { color: var(--muted); font-size: .86rem; }
.dept-h { font-size: .78rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 2px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* board */
.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.col-h { display: flex; justify-content: space-between; font-weight: 700; margin: 2px 4px 10px; }
.col .task { flex-direction: column; align-items: stretch; gap: 4px; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-h { font-size: .78rem; font-weight: 700; color: var(--muted); text-align: center; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-height: 96px; padding: 6px; overflow: hidden; }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.day.other { opacity: .5; }
.day .dnum { font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.calitem { font-size: .76rem; padding: 3px 6px; border-radius: 6px; background: var(--surface-2); margin-bottom: 3px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calitem.late { background: var(--late-soft); color: var(--late); font-weight: 600; }
.calitem.done { background: var(--done-soft); color: var(--done); text-decoration: line-through; }
.weekcols { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.weekcols .day { min-height: 140px; }

/* task detail */
.detail { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.desc { white-space: pre-wrap; word-break: break-word; }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.check.done span { text-decoration: line-through; color: var(--muted); }
.progress { height: 7px; background: var(--surface-2); border-radius: 9px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.msg { padding: 9px 12px; border-radius: 12px; background: var(--surface-2); max-width: 92%; }
.msg.mine { align-self: flex-end; background: var(--brand-soft); }
.msg.boss:not(.mine) { border-left: 3px solid var(--brand); }
.msg .who { font-size: .78rem; font-weight: 700; color: var(--muted); display: flex; gap: 8px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.event { font-size: .8rem; color: var(--muted); text-align: center; }
.file { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.file:last-child { border-bottom: 0; }
.fileicon { width: 36px; height: 36px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; font-size: .7rem; font-weight: 800; color: var(--muted); flex: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stars button { border: 0; background: none; font-size: 1.5rem; cursor: pointer; color: var(--line); padding: 0 2px; }
.stars button.on { color: #e5a100; }

/* people & progress */
.person { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.bar { display: flex; height: 8px; border-radius: 9px; overflow: hidden; background: var(--surface-2); margin-top: 5px; }
.bar i { display: block; height: 100%; }
.bar .b-done { background: var(--done); } .bar .b-open { background: var(--prog); opacity: .55; } .bar .b-late { background: var(--late); }
.legend { display: flex; gap: 12px; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.feed-item { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; cursor: pointer; }
.feed-item:last-child { border-bottom: 0; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.tbl th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tbl tr.off td { opacity: .55; }
.tablewrap { overflow-x: auto; }

/* popover / dialog / toast */
.pop { position: absolute; right: 0; top: 44px; width: min(380px, calc(100vw - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.18); z-index: 40; max-height: 70vh; overflow-y: auto; }
.pop-item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .9rem; }
.pop-item.unread { background: var(--brand-soft); }
.pop-item:hover { background: var(--surface-2); }
dialog.dlg { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.dlg::backdrop { background: rgba(10, 20, 18, .45); }
.dlg-h { padding: 16px 18px 6px; display: flex; align-items: center; } .dlg-b { padding: 8px 18px; max-height: 70vh; overflow-y: auto; }
.dlg-f { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }

/* sign in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; background: radial-gradient(1200px 500px at 20% -10%, var(--brand-soft), transparent), var(--bg); }
.auth .card { width: min(420px, 100%); padding: 26px; }
.auth .logo { margin-bottom: 18px; font-size: 1.15rem; }

@media (max-width: 900px) {
  .grid-main, .detail, .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .weekcols { grid-template-columns: 1fr; }
  .weekcols .day { min-height: 0; }
}
@media (max-width: 720px) {
  .nav { display: none; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; padding: 6px 0; color: var(--muted); border-radius: 10px; }
  .bottomnav a.on { color: var(--brand-2); background: var(--brand-soft); font-weight: 700; }
  .fieldrow { grid-template-columns: 1fr; }
  .cal .day { min-height: 64px; padding: 3px; } .calitem { font-size: .66rem; padding: 2px 3px; }
  .kv { grid-template-columns: 90px 1fr; }
  main { padding-top: 16px; }
  .logo span.name { max-width: 46vw; }
}
@media print {
  .topbar, .bottomnav, .noprint { display: none !important; }
  body { background: #fff; } .card { box-shadow: none; }
}
