:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #efeff4);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --line: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.25));
  --radius: 12px;
  --app-height: var(--tg-viewport-stable-height, 100vh);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

#app {
  height: var(--app-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* у повноекранному режимі Telegram малює свої кнопки поверх — відступаємо від них */
  padding: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px))
    calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px))
    calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px))
    calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px));
}

/* ---------- верхня панель ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 8px;
}
.topbar .title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip {
  flex: 0 0 auto;
  border: 0;
  border-radius: 16px;
  padding: 6px 12px;
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}
.chip.active {
  background: var(--btn);
  color: var(--btn-text);
}
.icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--bg2);
  color: var(--text);
  font-size: 17px;
  line-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- дошка ---------- */
.board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 12px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scroll-padding: 0 12px;
  -webkit-overflow-scrolling: touch;
}
body.is-dragging .board {
  scroll-snap-type: none;
}
.column {
  flex: 0 0 min(84vw, 300px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-radius: 14px;
  scroll-snap-align: start;
}
.col-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 6px 12px;
}
.col-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.count {
  flex: 0 0 auto;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 11px;
  background: var(--bg);
  color: var(--hint);
  font-size: 12px;
  text-align: center;
}
.col-menu {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--hint);
  font-size: 18px;
  padding: 0 6px;
  line-height: 1;
}
.cards {
  flex: 1 1 auto;
  min-height: 56px;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.add-task {
  flex: 0 0 auto;
  margin: 4px 8px 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--link);
  text-align: left;
  font-weight: 500;
}
.add-task:active {
  background: var(--bg);
}
.add-column {
  flex: 0 0 min(60vw, 220px);
  align-self: flex-start;
  padding: 14px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--hint);
  font-weight: 500;
  scroll-snap-align: start;
}

/* ---------- картки ---------- */
.card {
  flex: 0 0 auto;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.card.hidden {
  display: none;
}
.card.done .card-title {
  color: var(--hint);
  text-decoration: line-through;
}
.card-title {
  font-size: 15px;
  word-break: break-word;
}
.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--hint);
}
.card-meta:empty {
  display: none;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg2);
  color: var(--hint);
  white-space: nowrap;
}
.badge.overdue {
  background: rgba(229, 57, 53, 0.14);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}
.badge.soon {
  background: rgba(245, 158, 11, 0.16);
  color: #c27803;
}
.card-desc {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--hint);
  white-space: pre-line;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.assignees {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  max-width: 60%;
  min-width: 0;
}
.assignee-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.avatar-stack {
  display: inline-flex;
  flex: 0 0 auto;
}
.avatar-stack .avatar + .avatar {
  margin-left: -6px;
}
.avatar-stack .avatar {
  box-shadow: 0 0 0 2px var(--bg);
}
.avatar.more {
  width: 20px;
  height: 20px;
  background: var(--bg2);
  color: var(--hint);
  font-size: 9px;
}
.avatar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* стани drag-and-drop (SortableJS) */
.card-ghost {
  opacity: 0.35;
}
.card-chosen {
  box-shadow: 0 0 0 2px var(--btn);
}
.card-drag,
.sortable-fallback {
  opacity: 1 !important;
  transform: rotate(2deg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22) !important;
}

/* ---------- список дошок і службові екрани ---------- */
.page {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 16px 24px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 8px;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--bg2);
  text-align: left;
}
.list-item .name {
  flex: 1 1 auto;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item .sub {
  color: var(--hint);
  font-size: 13px;
}
.muted {
  color: var(--hint);
}
.steps {
  padding-left: 20px;
  line-height: 1.6;
}
.center-msg {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--bg2);
  border-top-color: var(--btn);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- кнопки і форми ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--btn);
  color: var(--btn-text);
  font-weight: 600;
  text-align: center;
}
.btn:disabled {
  opacity: 0.6;
}
.btn.secondary {
  background: var(--bg2);
  color: var(--text);
}
.btn.danger {
  background: transparent;
  color: var(--danger);
}
.btn-row {
  display: flex;
  gap: 8px;
}
.btn-row .btn {
  flex: 1 1 0;
}
.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  margin: 0 0 5px 2px;
  color: var(--hint);
  font-size: 13px;
}
.input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg2);
  color: var(--text);
  font-size: 16px; /* щоб iOS не зумив */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus {
  border-color: var(--btn);
}
textarea.input {
  resize: vertical;
  min-height: 90px;
}
.date-row {
  display: flex;
  gap: 8px;
}
.date-row .input {
  flex: 1 1 auto;
}
.date-row .btn {
  flex: 0 0 auto;
  width: auto;
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 28px;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--line);
  transition: background 0.15s;
  pointer-events: none;
}
.switch span::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch input:checked + span {
  background: var(--btn);
}
.switch input:checked + span::after {
  transform: translateX(18px);
}
.section-title {
  margin: 18px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.people {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.person {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 16px;
  background: var(--bg2);
  font-size: 13px;
}
.meta-line {
  margin: 4px 0 14px;
  font-size: 12px;
  color: var(--hint);
}

.hint {
  margin: 6px 2px 0;
  font-size: 12px;
  color: var(--hint);
}

/* ---------- вибір виконавців ---------- */
.picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.pick.on {
  border-color: var(--btn);
  background: var(--btn);
  color: var(--btn-text);
}
.pick .tick {
  font-weight: 700;
}

/* ---------- файли ---------- */
.files {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  background: var(--bg2);
}
.file-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--bg);
  font-size: 20px;
}
.file-thumb {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  cursor: zoom-in;
}
.file-info {
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
}
.file-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-sub {
  font-size: 12px;
  color: var(--hint);
}
.file-act {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  padding: 0;
}
.file-act:disabled {
  opacity: 0.5;
}
.progress {
  height: 4px;
  margin-top: 6px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.progress-bar {
  width: 0;
  height: 100%;
  background: var(--btn);
  transition: width 0.15s;
}
.viewer {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
}
.viewer img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

/* ---------- нижня шторка ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s;
}
.sheet-backdrop.open {
  opacity: 1;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-height: 90%;
  overflow-y: auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  transform: translateY(100%);
  transition: transform 0.22s ease;
  overscroll-behavior: contain;
}
.sheet.open {
  transform: translateY(0);
}
.sheet-grip {
  width: 36px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 2px;
  background: var(--line);
}
.sheet h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

/* ---------- тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  font-size: 14px;
  text-align: center;
}
.toast.error {
  background: rgba(190, 30, 30, 0.95);
}

@media (min-width: 700px) {
  .column {
    flex-basis: 290px;
  }
}
