:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --text: #1c2330;
  --muted: #6b7380;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --grid: rgba(0, 0, 0, .07);
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --panel-2: #252a33;
    --text: #e6e9ee;
    --muted: #949cab;
    --border: #2f3541;
    --accent: #4f8cff;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
    --grid: rgba(255, 255, 255, .06);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
}
textarea { resize: vertical; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.icon-btn {
  border: none; background: none; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px; font-size: 16px;
}
.icon-btn:hover { background: var(--panel-2); }
.link { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0; text-decoration: underline; }

/* Вход */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login-box {
  background: var(--panel); padding: 28px; border-radius: 12px; box-shadow: var(--shadow);
  width: min(360px, 100%); display: grid; gap: 14px;
}
.login-box h1 { margin: 0; }
.login-box p { margin: 0; }

/* Каркас */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100%; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.brand { font-weight: 700; font-size: 17px; padding: 16px; }
.nav-item, .project-list a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px; color: inherit; text-decoration: none;
}
.nav-item:hover, .project-list a:hover { background: var(--panel-2); }
.nav-item.active, .project-list a.active { background: var(--panel-2); font-weight: 600; }
.sidebar-title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 10px 4px 16px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
.project-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 12px 16px; display: grid; gap: 8px; }
.me-row { display: flex; gap: 10px; align-items: center; font-size: 13px; }
.me-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online { display: flex; gap: 4px; flex-wrap: wrap; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; color: #fff;
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 600; flex: none;
}
.avatar.small { width: 20px; height: 20px; font-size: 9px; }
.avatar.offline { opacity: .35; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.topbar h2 { margin: 0; font-size: 17px; cursor: pointer; }
.tabs { display: flex; gap: 2px; background: var(--panel-2); border-radius: 8px; padding: 2px; }
.tabs a { padding: 4px 12px; border-radius: 6px; color: inherit; text-decoration: none; }
.tabs a.active { background: var(--panel); box-shadow: var(--shadow); }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: #16a34a; }
.conn.off { background: var(--danger); }
.view { flex: 1; min-height: 0; overflow: auto; position: relative; }
.mobile-only { display: none; }

/* Канбан */
.board { display: flex; gap: 12px; padding: 16px; align-items: flex-start; min-height: 100%; }
.column {
  background: var(--panel-2); border-radius: var(--radius); width: 280px; flex: none;
  display: flex; flex-direction: column; max-height: calc(100vh - 110px);
}
.column-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 6px 12px; font-weight: 600; }
.column-head .name { flex: 1; cursor: text; }
.column-head .count { color: var(--muted); font-weight: 400; font-size: 12px; }
.column-head .count.over { color: var(--danger); font-weight: 600; }
.cards { padding: 4px 8px; display: grid; gap: 8px; overflow-y: auto; min-height: 30px; align-content: start; }
.cards.drop { outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 6px; }
.card {
  background: var(--panel); border-radius: 6px; padding: 8px 10px; box-shadow: var(--shadow);
  cursor: pointer; display: grid; gap: 6px; border-left: 3px solid transparent;
}
.card.dragging { opacity: .4; }
.card.prio-high { border-left-color: #dc2626; }
.card.prio-medium { border-left-color: #f59e0b; }
.card.prio-low { border-left-color: #10b981; }
.card .title { word-break: break-word; }
.card.done .title { text-decoration: line-through; color: var(--muted); }
.card-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.card-meta .due.overdue { color: var(--danger); font-weight: 600; }
.label { background: var(--panel-2); border-radius: 4px; padding: 0 6px; font-size: 11px; }
.add-card { margin: 6px 8px 10px; text-align: left; border: none; background: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px; }
.add-card:hover { background: var(--panel); color: var(--text); }
.add-column { width: 280px; flex: none; }

/* Календарь */
.calendar { padding: 16px; display: grid; gap: 8px; }
.cal-head { display: flex; gap: 8px; align-items: center; }
.cal-head h3 { margin: 0 8px; min-width: 160px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--panel-2); padding: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.cal-day { background: var(--panel); min-height: 110px; padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.cal-day.other { background: var(--bg); }
.cal-day.today .num { background: var(--accent); color: var(--accent-text); border-radius: 50%; }
.cal-day.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.cal-day .num { width: 22px; height: 22px; display: grid; place-items: center; font-size: 12px; align-self: flex-end; cursor: pointer; }
.cal-item {
  font-size: 12px; padding: 1px 6px; border-radius: 4px; color: #fff; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-item.done { opacity: .5; text-decoration: line-through; }

/* Холст */
.canvas {
  position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1.2px, transparent 1.2px);
}
.canvas.panning { cursor: grabbing; }
.canvas-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.note {
  position: absolute; border-radius: 4px; box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; color: #1c2330;
}
.note-bar { height: 22px; cursor: move; display: flex; justify-content: flex-end; align-items: center; gap: 2px; padding: 0 4px; opacity: .55; }
.note:hover .note-bar { opacity: 1; }
.note-bar button { border: none; background: none; cursor: pointer; font-size: 12px; padding: 0 3px; color: #1c2330; }
.note textarea {
  flex: 1; border: none; background: transparent; resize: none; padding: 2px 10px 10px;
  font-size: 15px; line-height: 1.35; color: #1c2330; outline: none;
}
.note-resize { position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.note .author { position: absolute; left: 8px; bottom: 4px; font-size: 10px; opacity: .55; pointer-events: none; }
.zoom-label { min-width: 46px; text-align: center; color: var(--muted); }
.swatches { display: flex; gap: 4px; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .15); cursor: pointer; }
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { position: absolute; left: 16px; bottom: 12px; color: var(--muted); font-size: 12px; pointer-events: none; }

/* Модальное окно */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box {
  background: var(--panel); border-radius: 12px; padding: 20px; width: min(560px, 100%);
  max-height: 90vh; overflow: auto; display: grid; gap: 12px; box-shadow: var(--shadow);
}
.modal-box h3 { margin: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .left { margin-right: auto; }
.check { display: flex; flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.check input { width: auto; }
.meta-line { font-size: 12px; color: var(--muted); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 5; box-shadow: var(--shadow); }
  .sidebar.closed { display: none; }
  .mobile-only { display: inline-block; }
  .toolbar .muted, .hint { display: none; }
  .column, .add-column { width: 82vw; }
  .cal-day { min-height: 70px; }
  .cal-item { font-size: 10px; padding: 0 3px; }
}
