:root {
  --bg: #f5f6fa; --panel: #ffffff; --panel2: #f0f2f7; --border: #e2e5ee; --text: #1c2033; --muted: #6b7189;
  --accent: #6366f1; --accent-weak: #eef0ff; --danger: #e5484d; --ok: #12a36a; --warn: #d98a00;
  --shadow: 0 1px 2px rgba(20,24,40,.06), 0 4px 16px rgba(20,24,40,.06); --radius: 10px;
  --c-vacation: #22c55e; --c-sick: #ef4444; --c-dayoff: #f59e0b; --c-trip: #3b82f6; --c-remote: #a855f7;
  --p-low: #94a3b8; --p-normal: #3b82f6; --p-high: #f59e0b; --p-critical: #ef4444;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c; --panel: #1a1d28; --panel2: #222634; --border: #2d3244; --text: #e6e8f0; --muted: #9298ad;
    --accent: #818cf8; --accent-weak: #262a48; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; } .right { margin-left: auto; }
.hidden { display: none !important; }

/* Buttons & inputs */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); } button.danger:hover { border-color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; } button.ghost:hover { background: var(--panel2); }
button.sm { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 34px; width: 50px; }
textarea { resize: vertical; min-height: 80px; }
label.f { display: block; margin-bottom: 12px; } label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar-in { display: flex; align-items: center; gap: 12px; padding: 8px 16px; max-width: 1600px; margin: 0 auto; }
.logo { font-weight: 700; display: flex; align-items: center; gap: 8px; font-size: 15px; }
.logo i { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block; }
.team-switch { width: auto; max-width: 220px; font-weight: 600; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 0 16px; max-width: 1600px; margin: 0 auto; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); border-bottom-color: var(--team, var(--accent)); }
.nav .badge { margin-left: 4px; }
.main { padding: 20px 16px 60px; max-width: 1600px; margin: 0 auto; }
.usermenu { position: relative; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 200px; padding: 6px; z-index: 30; }
.dropdown button { width: 100%; justify-content: flex-start; border: 0; background: none; }
.dropdown button:hover { background: var(--panel2); }
@media (max-width: 700px) { .logo span { display: none; } .topbar-in { gap: 8px; } .uname { display: none; } }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 26px; line-height: 1.1; } .kpi span { color: var(--muted); font-size: 12px; }
.kpi.bad b { color: var(--danger); }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; margin-right: auto; }

.avatar { width: 26px; height: 26px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex: none; }
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--panel2); color: var(--muted); }
.badge.accent { background: var(--accent); color: #fff; }
.tag { display: inline-block; padding: 0 6px; border-radius: 5px; font-size: 11px; background: var(--accent-weak); color: var(--accent); }
.prio { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prio.low { background: var(--p-low); } .prio.normal { background: var(--p-normal); } .prio.high { background: var(--p-high); } .prio.critical { background: var(--p-critical); }
.st { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.st-backlog { background: #94a3b822; color: #64748b; } .st-todo { background: #3b82f622; color: #3b82f6; }
.st-in_progress { background: #f59e0b22; color: #d97706; } .st-review { background: #a855f722; color: #a855f7; } .st-done { background: #22c55e22; color: #16a34a; }
.overdue { color: var(--danger); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.list li:last-child { border-bottom: 0; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.progress { height: 8px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

/* Board */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters select, .filters input { width: auto; min-width: 140px; }
.filters input[type=search] { min-width: 200px; }
.board { display: grid; grid-template-columns: repeat(5, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: var(--panel2); border-radius: var(--radius); padding: 8px; min-height: 200px; }
.col.drop { outline: 2px dashed var(--accent); }
.col-h { display: flex; align-items: center; gap: 6px; padding: 4px 6px 10px; font-weight: 600; }
.tcard { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.tcard:hover { border-color: var(--accent); }
.tcard.mine { border-left: 3px solid var(--accent); }
.tcard[draggable=true] { cursor: grab; }
.tcard.dragging { opacity: .4; }
.tcard .t-title { font-weight: 500; margin: 4px 0 8px; word-break: break-word; }
.tcard .meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.ref { color: var(--muted); font-size: 12px; font-weight: 500; }

table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel2); position: sticky; top: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--panel2); }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,12,20,.5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 980px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-h h2 { margin: 0; flex: 1; font-size: 16px; }
.modal-b { padding: 18px; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@media (max-width: 600px) { .modal-bg { padding: 0; } .modal { border-radius: 0; min-height: 100%; } }
.task-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; }
@media (max-width: 800px) { .task-layout { grid-template-columns: 1fr; } }
.side label.f { margin-bottom: 10px; }
.side .val { padding: 4px 0; }
.comment { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment .body { flex: 1; min-width: 0; }
.check { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.check.done span { text-decoration: line-through; color: var(--muted); }

/* Markdown */
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 16px 0 8px; } .md p { margin: 0 0 10px; }
.md pre { background: var(--panel2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md hr { border: 0; border-top: 1px solid var(--border); }
.md li.cb { list-style: none; margin-left: -20px; }

/* Notes */
.notes { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 800px) { .notes { grid-template-columns: 1fr; } }
.note-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.note-item:hover { background: var(--panel2); }
.note-item.active { background: var(--accent-weak); border-color: var(--accent); }
.note-item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-split textarea { min-height: 420px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.editor-split .md { border: 1px solid var(--border); border-radius: 8px; padding: 10px; min-height: 420px; max-height: 70vh; overflow: auto; }
@media (max-width: 900px) { .editor-split { grid-template-columns: 1fr; } }

/* Calendar */
.cal-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table.cal { border-collapse: collapse; min-width: 100%; }
.cal th, .cal td { border: 1px solid var(--border); padding: 0; text-align: center; font-size: 11px; }
.cal th { padding: 4px 0; min-width: 30px; font-weight: 600; color: var(--muted); }
.cal th.name, .cal td.name { text-align: left; padding: 6px 10px; min-width: 170px; position: sticky; left: 0; background: var(--panel); z-index: 1; font-size: 13px; color: var(--text); white-space: nowrap; }
.cal td { height: 34px; cursor: pointer; }
.cal .we { background: var(--panel2); }
.cal .hol { background: repeating-linear-gradient(45deg, var(--panel2), var(--panel2) 4px, transparent 4px, transparent 8px); }
.cal th.today { background: var(--accent); color: #fff; }
.cal td.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal td.ab { color: #fff; font-weight: 700; }
.cal td.ab.pending { opacity: .55; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.35), rgba(255,255,255,.35) 3px, transparent 3px, transparent 7px); }
.ab-vacation { background-color: var(--c-vacation); } .ab-sick { background-color: var(--c-sick); } .ab-dayoff { background-color: var(--c-dayoff); }
.ab-trip { background-color: var(--c-trip); } .ab-remote { background-color: var(--c-remote); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

/* Team */
.members { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.member { display: flex; gap: 12px; align-items: center; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .logo { justify-content: center; font-size: 20px; margin-bottom: 20px; }
.err { color: var(--danger); margin-bottom: 10px; min-height: 1em; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.err { background: var(--danger); color: #fff; }
.feed { max-height: 520px; overflow-y: auto; }
.feed li { align-items: flex-start; }
.feed .when { white-space: nowrap; }
