:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e7e9ee;
  --muted: #8b90a0;
  --border: #2a2f3a;
  --accent: #6b7cff;
  --accent-ink: #fff;
  --danger: #ef4444;
  --good: #22c55e;
  --warn: #f59e0b;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --radius: 14px;
}
html[data-theme="light"] {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f0f2f8;
  --text: #1b2030;
  --muted: #6b7180;
  --border: #e3e7ef;
  --shadow: 0 6px 24px rgba(30,40,80,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.topbar .spacer { flex: 1; }
.topbar .iconbtn { position: relative; }
.badge-dot {
  position: absolute; top: -3px; right: -3px; min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; line-height: 16px; text-align: center;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 18px 16px 60px; }
.page-title { font-size: 22px; font-weight: 700; margin: 6px 0 16px; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-weight: 600; font-size: 14px;
  transition: filter .15s, background .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Inputs */
.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 44px; }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pill { display:inline-flex; align-items:center; gap:5px; padding: 2px 10px; border-radius: 20px; font-size: 12px; border: 1px solid var(--border); }
.tag { color: #fff; padding: 2px 9px; border-radius: 6px; font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap-flex { display: flex; flex-wrap: wrap; gap: 8px; }

/* Projects grid */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.proj-card { padding: 16px; cursor: pointer; position: relative; overflow: hidden; }
.proj-card:hover { border-color: var(--accent); }
.proj-card .picon { font-size: 26px; }
.proj-card h3 { margin: 8px 0 4px; font-size: 17px; }
.progress { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin: 10px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--good); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* Kanban board */
.board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 10px; }
.column { flex: 0 0 300px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.column > h4 { margin: 4px 6px 10px; font-size: 14px; display: flex; justify-content: space-between; }
.column.drop-hover { outline: 2px dashed var(--accent); }
.branch-card {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 9px; cursor: pointer;
}
.branch-card:hover { border-color: var(--accent); }
.branch-card .bt { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.branch-card .bmeta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); align-items: center; }
.branch-card.dragging { opacity: .4; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 1px 8px; font-size: 12px; }
.chip.overdue { color: var(--danger); border-color: var(--danger); }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 16px; }
.tab { padding: 7px 14px; border-radius: 20px; cursor: pointer; border: 1px solid var(--border); background: var(--panel); font-size: 14px; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* Branch panel (slide-over) */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; display: none; }
.overlay.open { display: block; }
.panel-host { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 50; }
.panel-slide {
  position: absolute; top: 0; right: 0; height: 100%; width: min(680px, 100%);
  background: var(--bg); border-left: 1px solid var(--border); pointer-events: auto;
  transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column;
}
.panel-slide.open { transform: translateX(0); }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.panel-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.panel-foot { border-top: 1px solid var(--border); padding: 10px 12px; background: var(--panel); }

/* Messages */
.msg { padding: 10px 0; border-top: 1px solid var(--border); }
.msg:first-child { border-top: none; }
.msg .mhead { display: flex; align-items: baseline; gap: 8px; }
.msg .mhead b { font-size: 14px; }
.msg .mtext { margin: 4px 0; white-space: pre-wrap; word-break: break-word; }
.msg.pinned { background: rgba(245,158,11,.08); border-radius: 8px; padding: 8px 10px; }
.media { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.media img { width: 130px; height: 130px; object-fit: cover; border-radius: 8px; cursor: pointer; background: var(--panel-2); }
.file-chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.reactions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.reaction { border: 1px solid var(--border); border-radius: 20px; padding: 1px 9px; font-size: 13px; cursor: pointer; background: var(--panel); }
.reaction.mine { border-color: var(--accent); background: rgba(107,124,255,.15); }
.msg-actions { display: flex; gap: 10px; margin-top: 4px; }
.msg-actions button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0; }
.msg-actions button:hover { color: var(--text); }

/* Composer */
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; }
.attach-preview { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.attach-preview .p { position: relative; }
.attach-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; }
.attach-preview .x { position: absolute; top: -6px; right: -6px; background: var(--danger); color:#fff; border-radius: 50%; width: 18px; height: 18px; line-height: 18px; text-align: center; cursor: pointer; font-size: 12px; }

/* Checklist */
.chk-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.chk-item.done span { text-decoration: line-through; color: var(--muted); }
.chk-item input[type=checkbox] { width: 17px; height: 17px; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }
.cal .day { min-height: 78px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 5px; font-size: 12px; }
.cal .day.other { opacity: .4; }
.cal .day .dnum { color: var(--muted); }
.cal .day.today { border-color: var(--accent); }
.cal .ev { background: var(--panel-2); border-left: 3px solid var(--accent); border-radius: 5px; padding: 2px 5px; margin-top: 3px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal .ev.overdue { border-left-color: var(--danger); }

/* Gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); width: min(520px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal .mh { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; display:flex; justify-content:space-between; align-items:center; }
.modal .mb { padding: 16px 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 80; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

/* Toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast-item { background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s; }
.toast-item.err { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(400px, 100%); padding: 28px; text-align: center; }
.token-input { text-align: center; letter-spacing: 3px; font-size: 20px; font-weight: 700; }

/* Table */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.token-badge { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--panel-2); padding: 3px 8px; border-radius: 6px; letter-spacing: 1px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* Context menu (right-click / long-press) */
.pm-context { position: fixed; z-index: 90; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 194px; }
.ctx-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 10px 2px; }
.ctx-item { padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; user-select: none; }
.ctx-item:hover { background: var(--panel-2); }
.ctx-item.on { color: var(--accent); font-weight: 600; }
.ctx-item.danger { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* Urgent branch */
.branch-card.urgent { border-color: var(--danger); background: linear-gradient(0deg, rgba(239,68,68,.07), rgba(239,68,68,.07)), var(--panel-2); }

/* History feed */
.history { display: flex; flex-direction: column; }
.hist-item { padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.hist-item:hover { background: var(--panel); }

.brand .pm-logo svg { display: block; }

/* Аватарки */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; font-weight: 700; line-height: 1; flex: 0 0 auto; letter-spacing: -.02em; }

/* Мини-таблица в ветке */
.pm-table-wrap { overflow-x: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: 10px; }
table.pm-table { border-collapse: collapse; width: 100%; font-size: 14px; }
table.pm-table th, table.pm-table td { border: 1px solid var(--border); padding: 0; vertical-align: top; }
table.pm-table th { background: var(--panel-2); }
table.pm-table th:first-child, table.pm-table td:first-child { }
table.pm-table .cell { padding: 6px 9px; min-width: 96px; min-height: 20px; outline: none; }
table.pm-table th .cell { font-weight: 600; }
table.pm-table .cell:focus { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 3px; }
table.pm-table .ctl { width: 26px; min-width: 26px; text-align: center; color: var(--muted); cursor: pointer; background: var(--panel); user-select: none; }
table.pm-table .ctl:hover { color: var(--danger); }
.pm-table-tools { display: flex; gap: 6px; margin-top: 8px; }

/* Страница не должна давать горизонтальную прокрутку (clip не ломает sticky-шапку) */
body { overflow-x: clip; }

@media (max-width: 640px) {
  .wrap { padding: 14px 12px 60px; }
  .column { flex-basis: 84vw; }
  .proj-grid { grid-template-columns: 1fr; }
  .media img { width: 46%; height: auto; aspect-ratio: 1; }
}
