:root {
  color-scheme: light;
  --bg: #0f172a;
  --panel: #111827;
  --card: #1f2937;
  --border: #374151;
  --text: #f9fafb;
  --muted: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #ef4444;
  --column-width: min(320px, 88vw);
  --lane-width: 140px;
  --col-min: 220px;
  --topbar-pad: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #0b1220 0%, #111827 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
}

.muted {
  color: var(--muted);
}

.error {
  color: #fecaca;
}

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

button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button.secondary {
  background: #374151;
}

button.secondary:hover:not(:disabled) {
  background: #4b5563;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  margin: 12vh auto 0;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.login-card label,
dialog label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #0b1220;
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: var(--topbar-pad) var(--topbar-pad) 12px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: clamp(1.25rem, 4vw, 28px);
  line-height: 1.2;
}

#board-meta {
  font-size: clamp(0.75rem, 2.5vw, 0.875rem);
  line-height: 1.45;
  word-break: break-word;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  justify-content: flex-end;
  flex: 1 1 280px;
  min-width: 0;
}

.board-swim {
  padding: 0 12px max(24px, env(safe-area-inset-bottom));
}

/* --- Desktop swim grid (широкий экран) --- */

.board-layout--desktop {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
  padding-bottom: 4px;
}

.board-layout--mobile {
  display: none;
}

.swim-grid {
  display: grid;
  gap: 10px;
  width: max-content;
  min-width: 100%;
  grid-template-columns:
    minmax(var(--lane-width), 160px)
    repeat(var(--swim-cols, 5), minmax(var(--col-min), var(--column-width)));
}

.swim-corner,
.swim-col-head,
.swim-lane-label {
  position: sticky;
  background: #0f172a;
  z-index: 2;
}

.swim-corner {
  top: 0;
  left: 0;
  z-index: 4;
  padding: 10px 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.swim-col-head {
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  font-weight: 600;
  font-size: clamp(0.8rem, 2vw, 1rem);
  min-width: 0;
  max-width: var(--column-width);
  overflow-wrap: anywhere;
}

.swim-lane-label {
  left: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 120px;
}

.swim-lane-label strong {
  font-size: 15px;
}

.swim-lane-label .muted {
  font-size: 11px;
  line-height: 1.3;
}

.swim-lane-label .count {
  align-self: flex-start;
  margin-top: 4px;
}

.swim-cell {
  min-height: 120px;
  min-width: 0;
  max-width: var(--column-width);
  padding: 8px;
  background: rgba(17, 24, 39, 0.55);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board {
  display: flex;
  gap: 14px;
  padding: 0 20px 24px;
  overflow-x: auto;
  align-items: flex-start;
}

.column {
  flex: 0 0 var(--column-width);
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 420px;
}

.column-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.column-head h2 {
  margin: 0;
  font-size: 16px;
}

.count {
  background: #374151;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  flex-shrink: 0;
}

.column-body {
  padding: 12px;
  display: grid;
  gap: 10px;
  min-height: 360px;
}

.ticket {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  min-width: 0;
}

.ticket.dragging {
  opacity: 0.5;
}

.ticket.priority-high {
  border-color: #f59e0b;
}

.ticket-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  flex-wrap: wrap;
}

.ticket-id {
  color: #93c5fd;
  font-weight: 700;
}

.ticket-priority {
  color: #fbbf24;
  font-size: 11px;
  font-weight: 600;
}

.ticket-sub {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}

.release-filter {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  flex: 1 1 140px;
  min-width: 0;
}

.release-filter select {
  min-width: 0;
  width: 100%;
}

.release-group-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #93c5fd;
  padding: 4px 2px 2px;
}

.ticket-area {
  color: var(--muted);
}

.ticket-title,
.ticket h3 {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.35;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: auto;
}

.ticket-meta {
  margin: 0 0 10px;
  font-size: 12px;
}

.move-select {
  font-size: 12px;
  padding: 6px 8px;
  max-width: 100%;
}

dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  margin: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

#ticket-form,
#release-form {
  padding: 18px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.dialog-head h2 {
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.comments {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.comments ul {
  margin: 0 0 12px;
  padding-left: 18px;
}

.comments li {
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}

/* --- Mobile: колонки списком --- */

.mobile-column {
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  overflow: hidden;
}

.mobile-column-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  color: var(--text);
  border-radius: 0;
  text-align: left;
  font-weight: 600;
  font-size: 15px;
}

.mobile-column-toggle:hover {
  background: #1f2937;
}

.mobile-column-title {
  flex: 1;
  min-width: 0;
}

.mobile-column-body {
  display: none;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
}

.mobile-column.is-open .mobile-column-body {
  display: block;
}

.mobile-lane {
  margin-bottom: 12px;
}

.mobile-lane:last-child {
  margin-bottom: 0;
}

.mobile-lane-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.mobile-lane-head .muted {
  font-size: 11px;
}

.mobile-lane-cards {
  display: grid;
  gap: 8px;
}

.mobile-empty {
  margin: 0;
  padding: 8px 4px;
  font-size: 13px;
}

/* --- Breakpoints --- */

@media (max-width: 1100px) {
  :root {
    --lane-width: 108px;
    --col-min: 200px;
  }
}

@media (max-width: 900px) {
  :root {
    --topbar-pad: 14px;
  }

  .board-layout--desktop {
    display: none;
  }

  .board-layout--mobile {
    display: block;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
  }

  .release-filter {
    flex: 1 1 auto;
  }

  .topbar-actions > button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .board-swim {
    padding-left: 8px;
    padding-right: 8px;
  }

  .login-card {
    margin-top: 8vh;
    padding: 18px;
  }

  #ticket-form,
  #release-form {
    padding: 14px;
  }

  .ticket-title,
  .ticket h3 {
    font-size: 14px;
  }
}
