* { box-sizing: border-box; }

:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --line: #e3e6ee;
  --text: #1f2430;
  --muted: #8b93a3;
  --accent: #3b6fe0;
  --red: #e5484d;
  --red-bg: #fdebec;
  --yellow: #e0960e;
  --yellow-bg: #fdf3e3;
  --green: #20a363;
  --green-bg: #e7f6ee;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
}

/* ---------- Шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-info {
  color: var(--muted);
  font-size: 13px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { background: #f4f6fb; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { background: var(--red-bg); border-color: #f3c1c3; color: var(--red); }
.btn-danger:hover { background: #fad7d9; }

.btn.status-btn {
  border-radius: 999px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
}
.btn.status-btn.active {
  border-color: var(--accent);
  background: #eaf1ff;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Уведомления ---------- */
.notice {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff7e0;
  border: 1px solid #f0dc9a;
  color: #7a5b00;
}

.notice.error {
  background: var(--red-bg);
  border-color: #f3c1c3;
  color: #a11f24;
}

.hidden { display: none !important; }

/* ---------- Доска ---------- */
.board {
  display: flex;
  gap: 14px;
  padding: 20px;
  overflow-x: auto;
  align-items: flex-start;
  min-height: calc(100vh - 140px);
}

.column {
  flex: 0 0 280px;
  background: rgba(0, 0, 0, .03);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 140px);
}

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

.column-count {
  background: rgba(0,0,0,.07);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  font-weight: 600;
}

.column-cards {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 60px;
}

.column-cards.drag-over {
  background: rgba(59, 111, 224, .08);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  border-radius: 8px;
}

/* ---------- Карточка ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(20, 40, 80, .06);
  transition: box-shadow .12s, transform .12s;
  animation: cardIn .18s ease-out both;
  position: relative;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(20, 40, 80, .16);
  border-color: #c8d6f5;
}

.card:active { transform: scale(.985); }

.card.dragging { transform: none; }

/* подсказка «Карточка открывается по клику» */
.card::after {
  content: "Открыть";
  position: absolute;
  top: 8px;
  right: 58px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: #eaf1ff;
  border: 1px solid #cfdfff;
  border-radius: 999px;
  padding: 1px 9px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity .14s, transform .14s;
  pointer-events: none;
}
.card:hover::after { opacity: 1; transform: none; }

.card.w-red { border-left-color: var(--red); background: linear-gradient(0deg, var(--red-bg), var(--panel) 55%); }
.card.w-yellow { border-left-color: var(--yellow); background: linear-gradient(0deg, var(--yellow-bg), var(--panel) 55%); }
.card.w-green { border-left-color: var(--green); background: linear-gradient(0deg, var(--green-bg), var(--panel) 55%); }

.card.dragging { opacity: .45; }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.order-no {
  font-family: Consolas, monospace;
  font-weight: 700;
  font-size: 12px;
  color: var(--accent-dark, #1a56db);
  white-space: nowrap;
  overflow: visible;
  flex-shrink: 0;
}

.card-orders {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.card-orders .order-no {
  background: #eaf1ff;
  border: 1px solid #cfdfff;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 11px;
  text-decoration: none;
}
.card-orders .order-no:hover {
  background: #dbe8ff;
}

/* ---------- Сворачивание колонок в тонкую плашку ---------- */
.column-head {
  cursor: pointer;
  user-select: none;
}
.col-toggle {
  display: inline-block;
  width: 14px;
  text-align: center;
  color: var(--muted);
  transition: transform .15s;
}
.col-red {
  background: #a11f24;
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  font-weight: 700;
  margin-left: auto;
}
.column.collapsed {
  flex: 0 0 52px;
  width: 52px;
  min-width: 52px;
}
.column.collapsed .column-head {
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  height: 100%;
  box-sizing: border-box;
}
.column.collapsed .col-toggle {
  transform: rotate(-90deg);
}
.column.collapsed .col-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-weight: 700;
  font-size: 13px;
}
.column.collapsed .column-count {
  color: var(--muted);
}
.column.collapsed .col-red {
  margin-left: 0;
}
.column.collapsed .column-cards {
  display: none;
}

.chat-id {
  font-family: Consolas, monospace;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}

.card-msg {
  margin-top: 6px;
  font-size: 13px;
  color: #3a4150;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-comment {
  margin-top: 6px;
  font-size: 12px;
  color: #6b4f1d;
  background: #fff7e0;
  border: 1px solid #f0dfa9;
  border-radius: 6px;
  padding: 4px 7px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-time {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-warn {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
}

.card-warn.w-red { color: var(--red); }
.card-warn.w-yellow { color: var(--yellow); }
.card-warn.w-green { color: var(--green); }

.tiny-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 6px;
}
.tiny-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }

/* ---------- Ссылки на Ozon ---------- */
.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.card-links a {
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
  background: #eaf1ff;
  padding: 3px 9px;
  border-radius: 999px;
}
.card-links a:hover { background: #dbe8ff; }

/* ---------- Полуавтоматическое подтверждение статуса ---------- */
.card-suggest { margin-top: 8px; }
.card-suggest .suggest-btn {
  width: 100%;
  border: 1px solid var(--accent);
  background: #eaf1ff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.card-suggest.s-approve .suggest-btn {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
}
.card-suggest .suggest-btn:hover { filter: brightness(.96); }

.card.w-suggest { border-left-color: var(--accent); }

/* Колонка «Заказ без фото» подсвечивается красным */
.column[data-status="⚠️ Заказ без фото"] { background: rgba(229, 72, 77, .05); }
.column[data-status="⚠️ Заказ без фото"] .column-head { color: #a11f24; }

/* ---------- Панель скрытых ---------- */
.hidden-panel {
  margin: 14px 20px 0;
  padding: 14px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 12px;
}
.hidden-panel h3 { margin: 0 0 10px; font-size: 14px; }
.hidden-cards { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Модальное окно ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 35, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--panel);
  border-radius: 14px;
  width: 640px;
  max-width: 100%;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  position: relative;
  animation: modalIn .16s ease-out;
}

.modal-backdrop {
  animation: fadeIn .15s ease-out;
}

.modal-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, .92);
  border-radius: 14px;
  font-size: 13px;
  color: var(--muted);
  z-index: 5;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-title { font-size: 16px; font-weight: 600; font-family: Consolas, monospace; }
.modal-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.modal-statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #fafbfd;
}

.modal-links {
  padding: 10px 20px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.modal-links a {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.modal-links a:hover { text-decoration: underline; }

.modal-comment {
  padding: 10px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.modal-comment label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.modal-comment textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
}
.modal-comment .btn { align-self: flex-start; font-size: 12px; }

.messages {
  list-style: none;
  margin: 0;
  padding: 14px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.from-customer { align-self: flex-start; background: #eef1f7; border-bottom-left-radius: 4px; }
.msg.from-seller { align-self: flex-end; background: #e3edff; border-bottom-right-radius: 4px; }
.msg.from-system { align-self: center; background: #f6f1e2; font-size: 12px; }

.msg-head {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.msg-img img {
  max-width: 220px;
  border-radius: 8px;
  display: block;
}

.msg-file-link a {
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
}

.modal-actions {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.modal-candidates {
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  max-height: 240px;
  overflow-y: auto;
}

.modal-cand-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.cand-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.cand-item.empty { color: var(--muted); border-style: dashed; justify-content: center; }

.modal-cand-paste {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
#modal-link-chat-id { flex: 1; }

.cand-meta { white-space: nowrap; font-size: 11px; color: var(--muted); }
.cand-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand-text a { font-size: 11px; }

.small-btn { padding: 4px 10px; font-size: 12px; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #20242e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 99;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: toastIn .2s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Общие лёгкие анимации ---------- */
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes fadeIn { from { opacity: 0; } }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- Угол: время последнего обновления доски ---------- */
.board-updated {
  position: fixed;
  right: 12px;
  bottom: 12px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  z-index: 90;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.empty-col {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 18px 8px;
}

/* ---------- Авторизация ---------- */
.topbar-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
}

.current-user {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  background: #eaf1ff;
  border: 1px solid #cddefa;
  border-radius: 999px;
  padding: 4px 12px;
}

.login-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 40, 60, .55);
  backdrop-filter: blur(3px);
  animation: fadeIn .15s ease-out;
}

.login-box {
  width: 320px;
  background: var(--panel);
  border-radius: 12px;
  padding: 24px 26px;
  box-shadow: 0 16px 40px rgba(15, 25, 45, .25);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: modalIn .18s ease-out;
}

.login-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.login-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
}

.login-label input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

.login-label input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
}

.login-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 14px;
  padding: 9px 14px;
}

.login-btn:hover { background: #3162c9; }

.main-blur { transition: filter .2s; }

/* ---------- Панель «Учётные записи» ---------- */
.users-modal-backdrop { z-index: 55; }

.users-panel { max-width: 560px; }

.users-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 10px;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.users-table th, .users-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}

.users-table th {
  color: var(--muted);
  font-weight: 600;
}

.users-table .tiny-btn, .users-table .set-pass-btn {
  margin-right: 6px;
}

.users-add {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.users-add-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.users-add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.users-add-row input[type="text"], .users-add-row input[type="password"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  width: 150px;
}

.chk {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.users-table input[type="text"], .users-table input[type="password"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
  width: 110px;
}