:root {
  --brand: #1F4E79;
  --brand-light: #EAF1F8;
  --accent: #FFF2CC;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #6b7a89;
  --danger: #c0392b;
  --ok: #2e7d32;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 42, 67, .12);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Arial, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

/* ---------- login ---------- */
.login {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--brand) 0%, #142f4e 100%);
}
.login form {
  background: var(--card); padding: 32px; border-radius: var(--radius);
  width: min(320px, 90vw); display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.login h1 { margin: 0 0 8px; color: var(--brand); font-size: 22px; text-align: center; }
.login input {
  padding: 12px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 16px;
}
.login button {
  padding: 12px; border: 0; border-radius: 8px; background: var(--brand);
  color: #fff; font-size: 16px; cursor: pointer;
}
.err { color: var(--danger); font-size: 13px; min-height: 16px; margin: 0; text-align: center; }

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
header h1 { font-size: 17px; margin: 0; white-space: nowrap; }
header input[type="search"] {
  flex: 1; min-width: 60px; padding: 8px 12px; border: 0; border-radius: 8px; font-size: 15px;
}
header button {
  border: 0; border-radius: 8px; padding: 8px 14px; font-size: 15px;
  background: rgba(255,255,255,.15); color: #fff; cursor: pointer;
}
header button.primary { background: #e8833a; font-weight: bold; }

/* ---------- board ---------- */
main {
  display: flex; gap: 12px; padding: 12px;
  overflow-x: auto; height: calc(100vh - 58px);
  align-items: flex-start;
  scroll-snap-type: x proximity;
}
.col {
  background: #e7ebf0; border-radius: var(--radius);
  min-width: 280px; width: 280px; flex-shrink: 0;
  max-height: 100%; display: flex; flex-direction: column;
  scroll-snap-align: start;
}
.col-head {
  padding: 10px 14px; font-weight: bold; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center;
  border-top: 4px solid var(--stage-color, var(--brand));
  border-radius: var(--radius) var(--radius) 0 0;
}
.col-head .count { color: var(--muted); font-weight: normal; }
.col-head .sum { font-size: 12px; color: var(--muted); }
.col-body { padding: 8px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.col.drag-over { outline: 2px dashed var(--brand); outline-offset: -4px; }

.card {
  background: var(--card); border-radius: 8px; box-shadow: var(--shadow);
  padding: 10px 12px; cursor: grab; user-select: none;
  border-left: 4px solid transparent;
}
.card.stalled { border-left-color: #e8a33a; background: #fffdf4; }
.card.dragging { opacity: .5; }
.card .when { font-size: 11px; color: var(--muted); }
.card .name { font-weight: bold; font-size: 14px; margin: 2px 0; }
.card .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .contacts { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.card .contact { font-size: 12px; color: var(--brand); text-decoration: none; white-space: nowrap; }
.card .contact:hover { text-decoration: underline; }
.card span.contact { color: var(--muted); }
.card .tag {
  display: inline-block; font-size: 11px; background: var(--brand-light);
  color: var(--brand); border-radius: 4px; padding: 1px 6px; margin-top: 4px;
}
.card .amount { float: right; font-size: 12px; font-weight: bold; color: var(--ok); }
.card .move-btn {
  float: right; border: 0; background: none; font-size: 16px; color: var(--muted);
  cursor: pointer; padding: 0 2px; display: none;
}

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(12, 30, 50, .55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: min(560px, 100vw);
  max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px 18px calc(24px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 4px 0 10px; font-size: 18px; color: var(--brand); }
.close { border: 0; background: none; font-size: 28px; color: var(--muted); cursor: pointer; }
.sheet form { display: flex; flex-direction: column; gap: 10px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.sheet input, .sheet select, .sheet textarea {
  padding: 10px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 15px;
  font-family: inherit; width: 100%;
}
.sheet .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet .check { flex-direction: row; align-items: center; font-size: 14px; color: var(--text); }
.sheet .check input { width: auto; }
.sheet button.primary {
  padding: 12px; border: 0; border-radius: 8px; background: var(--brand);
  color: #fff; font-size: 16px; cursor: pointer;
}
.sheet button.danger {
  padding: 10px; border: 1px solid var(--danger); border-radius: 8px;
  background: none; color: var(--danger); font-size: 14px; cursor: pointer;
}
#historyBlock h3, #filesBlock h3 { font-size: 14px; color: var(--brand); margin: 18px 0 8px; }

/* ---------- файли угоди ---------- */
#fileList { list-style: none; margin: 0 0 10px; padding: 0; }
#fileList li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid #eef2f6; font-size: 14px;
}
#fileList a {
  color: var(--brand); text-decoration: none; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
}
#fileList a:hover { text-decoration: underline; }
#fileList .fmeta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.file-del { border: 0; background: none; font-size: 15px; cursor: pointer; padding: 0 2px; }
.file-add {
  display: block; text-align: center; padding: 10px;
  border: 1px dashed var(--brand); border-radius: 8px;
  color: var(--brand); font-size: 14px; cursor: pointer;
  background: var(--brand-light);
}
.tag.files-tag { background: var(--accent); color: #7a6210; margin-left: 4px; }
.note-add { display: flex; gap: 8px; margin-bottom: 10px; }
.note-add input { flex: 1; padding: 10px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 15px; }
.note-add button {
  border: 0; border-radius: 8px; background: var(--brand); color: #fff;
  width: 42px; font-size: 18px; cursor: pointer;
}
#historyList, #taskList { list-style: none; margin: 0; padding: 0; }
#historyList li { padding: 8px 0; border-bottom: 1px solid #eef2f6; font-size: 13px; }
#historyList li .ts { color: var(--muted); font-size: 11px; display: block; }
#taskList li {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid #eef2f6; font-size: 14px;
}
#taskList li.done { text-decoration: line-through; color: var(--muted); }
#taskList .due { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
#taskList .due.overdue { color: var(--danger); font-weight: bold; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  header h1 { display: none; }
  main { scroll-snap-type: x mandatory; }
  .col { min-width: 86vw; width: 86vw; }
  .card { cursor: default; }
  .card .move-btn { display: inline-block; }
  .overlay { align-items: flex-end; }
}
@media (min-width: 641px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; }
}
