:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1c2129;
  --text-2: #4e5663;
  --muted: #7c8592;
  --accent: #3b6fd8;
  --accent-soft: #e8effc;
  --accent-text: #2a59bd;
  --danger: #c93c3c;
  --danger-soft: #fbeaea;
  --good: #24834f;
  --good-soft: #e5f4ec;
  --warn: #a86a00;
  --warn-soft: #fbf1dc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --bar: #3b6fd8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #22272e;
    --border: #2c323b;
    --border-strong: #3a414c;
    --text: #e8ebef;
    --text-2: #b4bcc7;
    --muted: #8a93a0;
    --accent: #5b8cf0;
    --accent-soft: #1f2c47;
    --accent-text: #8fb0f7;
    --danger: #ec6b6b;
    --danger-soft: #3a1f22;
    --good: #4cc083;
    --good-soft: #17301f;
    --warn: #e0a640;
    --warn-soft: #362a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    --bar: #6b98f2;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 6px 16px; }
.ws-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px 4px; }
.ws-select { margin: 0 0 14px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
#nav a:hover { background: var(--surface-2); text-decoration: none; }
#nav a.active { background: var(--accent-soft); color: var(--accent-text); }
#nav .ico { width: 18px; text-align: center; opacity: .85; }
.badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; line-height: 18px; }
.badge.neutral { background: var(--muted); }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px 6px 0; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.menu-btn { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 640px; }
#global-search { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
#global-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.search-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 70vh; overflow: auto; z-index: 30; padding: 6px; }
.search-results h4 { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; padding: 8px 10px 4px; }
.search-results a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.search-results .sub { color: var(--muted); font-size: 12px; margin-left: 6px; }
.new-wrap { position: relative; margin-left: auto; }
.menu { position: absolute; right: 0; top: 40px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 30; min-width: 160px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.view { flex: 1; overflow: auto; padding: 24px; }

/* Buttons & inputs */
a.btn { color: var(--text); text-decoration: none; }
a.btn.primary { color: #fff; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 6px; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=password], input[type=url], select, textarea {
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; background: var(--surface); width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Page header */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Cards & stats */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card h2 { margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--text-2); font-size: 12px; font-weight: 550; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.alert .value { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > * { min-width: 0; }

/* Stage bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 120px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 4px; position: relative; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }
.empty-big { text-align: center; padding: 50px 20px; color: var(--text-2); }
.empty-big h2 { margin-bottom: 6px; }

/* Tables */
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); position: sticky; top: 0; cursor: pointer; user-select: none; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.name-cell { font-weight: 600; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; flex: none; }
.avatar.lg { width: 48px; height: 48px; font-size: 17px; }
.cell-flex { display: flex; align-items: center; gap: 10px; }

/* Chips */
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin: 1px 3px 1px 0; white-space: nowrap; }
.ws-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.status { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.status.good { background: var(--good-soft); color: var(--good); }
.status.bad { background: var(--danger-soft); color: var(--danger); }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status.info { background: var(--accent-soft); color: var(--accent-text); }
.status.plain { background: var(--surface-2); color: var(--text-2); }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.today { color: var(--warn); font-weight: 600; }
.prio-high { color: var(--danger); font-weight: 700; }

/* Kanban */
.kanban { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; min-height: 60vh; }
.column { flex: 1 0 175px; max-width: 320px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.column-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.column-head .title { display: flex; justify-content: space-between; font-weight: 650; }
.column-head .meta { color: var(--muted); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.column-head.won .title { color: var(--good); }
.column-head.lost .title { color: var(--muted); }
.column-body { padding: 8px; overflow-y: auto; flex: 1; min-height: 60px; display: flex; flex-direction: column; gap: 8px; }
.column-body.drop { background: var(--accent-soft); border-radius: 0 0 var(--radius) var(--radius); }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; cursor: grab; box-shadow: var(--shadow); }
.kcard:hover { border-color: var(--border-strong); }
.kcard.dragging { opacity: .45; }
.kcard .t { font-weight: 600; margin-bottom: 3px; }
.kcard .s { color: var(--muted); font-size: 12px; }
.kcard .row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; }
.kcard .val { font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text); }
.progress { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--good); }
.add-card { border: 1px dashed var(--border-strong); background: none; border-radius: 8px; padding: 7px; color: var(--muted); cursor: pointer; }
.add-card:hover { color: var(--text); background: var(--surface); }

/* Tasks */
.task-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
.task-group h3.red { color: var(--danger); }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.task:first-of-type { border-top: 0; }
.task .check { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); background: none; cursor: pointer; flex: none; margin-top: 1px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: transparent; }
.task .check:hover { border-color: var(--good); color: var(--good); }
.task.done .check { background: var(--good); border-color: var(--good); color: #fff; }
.task.done .ttl { text-decoration: line-through; color: var(--muted); }
.task .grow { flex: 1; min-width: 0; cursor: pointer; }
.task .links { font-size: 12px; color: var(--muted); margin-top: 2px; }
.quick-add { display: flex; gap: 8px; margin-bottom: 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* Drawer */
.drawer { position: fixed; inset: 0; background: rgba(10, 14, 20, .28); z-index: 40; display: flex; justify-content: flex-end; }
.drawer-panel { width: min(720px, 100%); height: 100%; background: var(--bg); box-shadow: var(--shadow-lg); overflow-y: auto; animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.d-head { background: var(--surface); border-bottom: 1px solid var(--border); padding: 18px 22px; position: sticky; top: 0; z-index: 2; }
.d-head .top { display: flex; gap: 14px; align-items: center; }
.d-head .top .grow { flex: 1; min-width: 0; }
.d-head h1 { font-size: 20px; }
.d-head .actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.d-body { padding: 18px 22px 40px; display: flex; flex-direction: column; gap: 14px; }
.fields { display: grid; grid-template-columns: 130px 1fr; gap: 7px 14px; font-size: 13px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; word-break: break-word; white-space: pre-wrap; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

/* Timeline */
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer .types { display: flex; gap: 4px; }
.composer .types button { border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 3px 11px; cursor: pointer; font-size: 12px; }
.composer .types button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.composer textarea { min-height: 64px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: 0; }
.timeline .tico { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; flex: none; font-size: 14px; }
.timeline .tbody { flex: 1; min-width: 0; }
.timeline .tsub { font-weight: 600; }
.timeline .tmeta { font-size: 12px; color: var(--muted); }
.timeline .ttext { white-space: pre-wrap; margin-top: 4px; color: var(--text-2); max-height: 160px; overflow: hidden; position: relative; }
.timeline .ttext.expanded { max-height: none; }
.timeline .more { font-size: 12px; cursor: pointer; color: var(--accent-text); border: 0; background: none; padding: 0; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 20, .38); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal-card { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(620px, 100%); }
.modal-card.wide { width: min(860px, 100%); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.modal-foot .left { margin-right: auto; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form .help { font-weight: 400; color: var(--muted); }
.err { color: var(--danger); font-size: 13px; }
.kv-row { display: flex; gap: 6px; margin-bottom: 6px; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 380px; animation: pop .15s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Settings */
.settings-grid { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.setting-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.setting-row:first-of-type { border-top: 0; }
.setting-row .grow { flex: 1; min-width: 0; }
.stage-row { display: grid; grid-template-columns: 22px 1fr 90px 100px 32px; gap: 8px; align-items: center; margin-bottom: 6px; }
.drag-handle { cursor: grab; color: var(--muted); text-align: center; user-select: none; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow: auto; border: 1px solid var(--border); }
.color-input { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 45; height: 100%; transform: translateX(-100%); transition: transform .15s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-block; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .form { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 100px 1fr; }
  .bar-row { grid-template-columns: 90px 1fr 90px; }
}
.form label input, .form label select, .form label textarea { font-size: 14px; font-weight: 400; color: var(--text); }

/* Team version */
.me-line { display: flex; gap: 10px; align-items: center; color: var(--text-2); }
.me-name { font-weight: 600; color: var(--text); font-size: 13px; }
.check-inline { display: inline-flex; gap: 5px; align-items: center; margin: 4px 14px 0 0; font-weight: 500; color: var(--text-2); font-size: 13px; }
.ws-checks { display: flex; flex-wrap: wrap; }
.team-row { align-items: flex-start; }
.team-row select, .team-row .btn { margin-top: 2px; }
.auth-page { display: flex; align-items: flex-start; justify-content: center; min-height: 100vh; padding: 10vh 16px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px; }
.auth-card .brand { padding: 0 0 18px; }
.auth-card h1 { margin-bottom: 10px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin: 16px 0; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.auth-form label input { font-size: 15px; font-weight: 400; color: var(--text); padding: 9px 11px; }
.auth-form .btn { justify-content: center; padding: 10px; }
.auth-form .row { display: flex; gap: 10px; }
.auth-form .row .btn { flex: 1; }
.auth-card .err, p.err { color: var(--danger); margin: 0; font-size: 13px; }
.auth-card ul { padding-left: 20px; color: var(--text-2); }
