:root {
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #f9faf6;
  --border: #dde2d7;
  --border-strong: #bfc8b7;
  --text: #242821;
  --muted: #6f7669;
  --faint: #a6ad9e;
  --deputy: #f0effa;
  --director: #fff5e5;
  --team: #eaf5ef;
  --deputy-accent: #735bb8;
  --director-accent: #c87f25;
  --team-accent: #39845d;
  --gray: #eceee8;
  --gray-text: #5d665a;
  --violet: #e9e1fb;
  --violet-text: #57419b;
  --red: #ffe4df;
  --red-text: #aa3329;
  --green: #dff2e7;
  --yellow: #fff0bf;
  --shadow: 0 10px 30px rgba(43, 46, 38, .08);
  --row-label-w: 156px;
  --col-w: 244px;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.auth-screen,
.board-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-screen.hidden,
.board-screen.hidden {
  display: none;
}

.auth-card,
.board-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

.board-card {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.board-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.auth-card h1,
.board-card h1 {
  margin: 0;
  font-size: 22px;
}

.auth-card p,
.board-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-card input,
.board-create input {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 11px 12px;
}

.auth-card button,
.board-card button,
.board-create button {
  border: 0;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-weight: 800;
  padding: 11px 12px;
}

.board-card-head button {
  background: var(--surface-soft);
  color: var(--muted);
  border: 1px solid var(--border);
}

.board-list {
  display: grid;
  gap: 8px;
}

.board-list-item {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  background: var(--surface-soft) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}

.board-list-item strong {
  font-size: 15px;
}

.board-list-item span {
  color: var(--muted);
  font-size: 12px;
}

.board-create {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.auth-error {
  min-height: 18px;
  color: var(--red-text);
  font-size: 13px;
}

.app.locked {
  visibility: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.title-block h1 {
  margin: 0 0 6px;
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 0;
}

.title-block p {
  margin: 0;
  max-width: 700px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sync-status {
  min-width: 132px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  padding: 9px 12px;
  font-size: 13px;
  text-align: center;
}

.sync-status.online {
  color: #276448;
  border-color: #b6ddc8;
  background: #eefaf3;
}

.sync-status.offline {
  color: var(--red-text);
  border-color: #efc1ba;
  background: #fff1ee;
}

.ritual-btn,
.composer button,
.editor-actions button {
  border: 0;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-weight: 700;
  padding: 10px 14px;
}

.ritual-btn.done {
  background: var(--team-accent);
}

.controls,
.composer,
.freezer {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  margin-bottom: 14px;
}

.board-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.board-switcher select {
  min-width: 180px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 9px 10px;
}

.board-switcher button {
  border: 0;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-weight: 800;
  padding: 9px 12px;
}

.board-menu-wrap {
  position: relative;
}

.board-menu-btn {
  width: 38px;
  min-width: 38px;
  padding: 9px 0 !important;
  font-size: 18px;
  line-height: 1;
}

.board-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 8;
  min-width: 190px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 6px;
}

.board-menu.hidden {
  display: none;
}

.board-menu button {
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  text-align: left;
  font-weight: 700;
}

.board-menu button:hover {
  background: var(--surface-soft);
}

.board-menu .danger-menu {
  color: var(--red-text);
}

.legend {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 4px;
  display: inline-block;
}

.c-gray {
  background: var(--gray);
  color: var(--gray-text);
}

.c-violet {
  background: var(--violet);
  color: var(--violet-text);
}

.c-red {
  background: var(--red);
  color: var(--red-text);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.search input,
.composer input,
.composer select,
.editor input,
.editor select,
.editor textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
}

.search input {
  width: min(360px, 42vw);
  padding: 9px 11px;
}

.board-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.board-scroll {
  overflow: auto;
}

.board {
  display: grid;
  grid-template-columns: var(--row-label-w) repeat(var(--board-cols, 4), var(--col-w));
  width: max-content;
  min-width: 100%;
}

.col-header,
.row-label,
.cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.col-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--label-bg, var(--surface)) 48%, var(--surface));
  padding: 14px 34px 12px 14px;
  font-size: 13px;
  font-weight: 800;
}

.editable-label {
  position: relative;
}

.label-main {
  display: block;
}

.label-edit-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, .74);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  opacity: .58;
}

.editable-label:hover .label-edit-btn {
  opacity: 1;
}

.corner {
  border-right: 2px solid var(--border-strong);
}

.col-sub {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 500;
}

.row-label {
  border-right: 2px solid var(--border-strong);
  padding: 13px 34px 13px 13px;
}

.row-label {
  background: color-mix(in srgb, var(--label-bg, var(--surface)) 72%, var(--surface));
}

.row-tag {
  display: inline-flex;
  margin-bottom: 8px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.deputy .row-tag {
  color: var(--deputy-accent);
  background: rgba(115, 91, 184, .11);
}

.director .row-tag {
  color: var(--director-accent);
  background: rgba(200, 127, 37, .11);
}

.team .row-tag {
  color: var(--team-accent);
  background: rgba(57, 132, 93, .11);
}

.row-name {
  display: block;
  font-size: 13px;
  font-weight: 800;
}

.row-desc {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.35;
}

.cell {
  position: relative;
  min-height: 140px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cell {
  background:
    linear-gradient(color-mix(in srgb, var(--col-bg, #fff) 18%, transparent), color-mix(in srgb, var(--col-bg, #fff) 18%, transparent)),
    color-mix(in srgb, var(--row-bg, #fff) 32%, #fff);
}

.cell.dragover,
.freezer-body.dragover {
  outline: 2px dashed var(--faint);
  outline-offset: -5px;
}

.cell-empty {
  margin: auto;
  color: var(--faint);
  font-size: 12px;
}

.cell-limit,
.cell-limit-btn {
  position: absolute;
  top: 7px;
  right: 8px;
  z-index: 1;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  color: var(--muted);
  padding: 2px 7px;
  font-size: 10.5px;
  font-weight: 800;
}

.cell-limit-btn {
  min-width: 32px;
  cursor: pointer;
  opacity: .35;
}

.cell:hover .cell-limit-btn,
.cell-limit-btn.has-limit {
  opacity: 1;
}

.cell-limit.over,
.cell-limit-btn.over {
  background: var(--red-text);
  border-color: var(--red-text);
  color: #fff;
}

.sticker {
  position: relative;
  background: var(--sticker-bg, var(--gray));
  color: var(--sticker-text, var(--gray-text));
  border: 1px solid rgba(0, 0, 0, .09);
  border-left-width: 5px;
  border-radius: var(--radius);
  box-shadow: 0 2px 4px rgba(28, 31, 23, .05);
  line-height: 1.35;
  padding: 9px 10px 8px;
  touch-action: pan-y;
  user-select: none;
  transition: transform .12s, box-shadow .12s, opacity .12s;
}

.sticker:hover {
  box-shadow: 0 7px 18px rgba(28, 31, 23, .1);
}

.sticker.dragging {
  opacity: .45;
}

.sticker.swiping {
  box-shadow: 0 8px 22px rgba(28, 31, 23, .13);
}

.sticker.subtask {
  margin-left: 18px;
  border-style: dashed;
}

.sticker.subtask::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 18px;
  width: 12px;
  height: 13px;
  border-left: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  border-radius: 0 0 0 5px;
}

.sticker.size-s {
  padding: 7px 8px;
  font-size: 11.5px;
}

.sticker.size-m {
  font-size: 12.5px;
}

.sticker.size-l {
  padding: 12px;
  font-size: 13.5px;
  font-weight: 700;
}

.sticker[data-priority="low"] {
  border-left-color: #8a9384;
}

.sticker[data-priority="normal"] {
  border-left-color: #3f7fb2;
}

.sticker[data-priority="high"] {
  border-left-color: #d08b2f;
}

.sticker[data-priority="critical"] {
  border-left-color: #c73b35;
}

.sticker-title {
  display: -webkit-box;
  max-height: 4.1em;
  overflow: hidden;
  padding-right: 22px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
}

.sticker-list {
  display: grid;
  gap: 4px;
  list-style: none;
  margin: 8px 0 0;
  max-height: 132px;
  overflow: hidden;
  padding: 0;
}

.sticker-list-empty {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  opacity: .75;
}

.sticker-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 6px;
  align-items: start;
  border-radius: 6px;
  padding: 4px 5px;
  background: rgba(255, 255, 255, .38);
  font-size: 11.5px;
  font-weight: 500;
  touch-action: pan-y;
  transition: transform .12s, background .12s;
}

.item-shift-btn {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 6px;
  background: rgba(255, 255, 255, .5);
  color: inherit;
  line-height: 1;
  padding: 0;
}

.item-shift-btn:hover {
  background: rgba(255, 255, 255, .86);
}

.sticker-item.swiping {
  background: rgba(255, 255, 255, .7);
}

.sticker-item.item-level-1 {
  margin-left: 16px;
  border-left: 2px solid rgba(0, 0, 0, .18);
  background: rgba(255, 255, 255, .56);
}

.sticker-item.item-level-2 {
  margin-left: 32px;
  border-left: 2px solid rgba(0, 0, 0, .28);
  background: rgba(255, 255, 255, .68);
}

.item-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sticker-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge,
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.badge {
  background: rgba(255, 255, 255, .65);
  padding: 2px 7px;
}

.avatar {
  max-width: 100%;
  min-width: 22px;
  color: #fff;
  background: #58738e;
  padding: 2px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-btn,
.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
}

.remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  opacity: .35;
}

.remove-btn:hover {
  background: rgba(0, 0, 0, .06);
  opacity: 1;
}

.freezer {
  margin-top: 14px;
  padding: 13px;
  border-style: dashed;
}

.freezer-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.freezer-head strong {
  color: var(--text);
}

.freezer-body {
  min-height: 66px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-radius: var(--radius);
}

.freezer-body .sticker {
  width: 240px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 170px auto 150px 150px auto;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
}

.composer-title {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.composer input,
.composer select {
  min-width: 0;
  padding: 10px 11px;
}

.color-pick {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.color-dot {
  width: 26px;
  height: 26px;
  border: 2px solid transparent;
  border-radius: 7px;
}

.color-dot.selected {
  border-color: var(--text);
}

.color-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.native-color,
.editor input[type="color"] {
  width: 38px;
  min-width: 38px;
  height: 34px;
  padding: 3px;
  border-radius: 8px;
}

.editor {
  width: min(720px, calc(100% - 24px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow);
}

.small-editor {
  width: min(420px, calc(100% - 24px));
}

.editor::backdrop {
  background: rgba(22, 24, 19, .34);
}

.editor-panel {
  padding: 0;
}

.sticker-editor-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(249, 250, 246, .96)),
    var(--surface);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding: 18px 20px 14px;
  margin-bottom: 0;
}

.editor h2 {
  margin: 0;
  font-size: 18px;
}

.editor-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.editor label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.editor-section {
  display: grid;
  gap: 12px;
  padding: 16px 20px 0;
}

.editor-panel > label {
  padding: 14px 20px 0;
}

.editor textarea,
.editor input,
.editor select {
  width: 100%;
  padding: 10px 11px;
  color: var(--text);
  font-weight: 500;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px 20px 0;
}

.checkbox {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  padding: 12px 20px 0;
}

.checkbox input {
  width: auto;
}

.editor-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
  padding: 14px 20px 18px;
}

.editor-actions.right {
  justify-content: flex-end;
}

.editor-actions .danger {
  background: #fff1ee;
  color: var(--red-text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(120%);
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  transition: transform .18s;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .top,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .sync-status,
  .ritual-btn {
    flex: 1;
  }

  .search {
    align-items: stretch;
    flex-direction: column;
  }

  .board-switcher,
  .board-switcher select {
    width: 100%;
  }

  .board-menu-wrap {
    width: 100%;
  }

  .board-menu-btn {
    width: 100%;
  }

  .board-menu {
    left: 0;
    right: 0;
  }

  .board-create {
    grid-template-columns: 1fr;
  }

  .search input {
    width: 100%;
  }

  .composer {
    grid-template-columns: 1fr 1fr;
  }

  .composer input {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  :root {
    --row-label-w: 120px;
    --col-w: 190px;
  }

  .app {
    padding: 16px 10px 44px;
  }

  .title-block h1 {
    font-size: 22px;
  }

  .composer,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .composer-title {
    grid-column: auto;
  }

  .freezer-body .sticker {
    width: 100%;
  }
}
