@font-face {
  font-family: "Circe";
  src: url("/fonts/Circe-Regular.otf") format("opentype");
  font-weight: 400;
}
@font-face {
  font-family: "Circe";
  src: url("/fonts/Circe-Bold.otf") format("opentype");
  font-weight: 700;
}
@font-face {
  font-family: "RoadRadio";
  src: url("/fonts/RoadRadio.otf") format("opentype");
  font-weight: 900;
}

:root {
  --sea: #3d8c99;
  --sea-dark: #366572;
  --dark: #12373d;
  --text: #1a2e33;
  --grey-light: #dce0e5;
  --grey: #ced2d8;
  --grey-dark: #c2c6cc;
  --white: #ffffff;
  --danger: #b03a3a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Circe", sans-serif;
  color: var(--text);
  background: var(--grey-light);
}

h1, h2, h3 { font-family: "RoadRadio", "Circe", sans-serif; font-weight: 900; margin: 0 0 12px; }

a { color: var(--sea-dark); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--dark);
  color: var(--white);
  padding: 10px 20px;
}
.topbar .logo { height: 32px; }
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar button { background: var(--sea); color: white; border: none; border-radius: var(--radius); padding: 6px 14px; cursor: pointer; font-family: inherit; }
.topbar button:hover { background: var(--sea-dark); }

.container { padding: 20px; max-width: 1400px; margin: 0 auto; }
@media (max-width: 600px) { .container { padding: 12px; } }

/* Мобильная адаптация топбара (решено 2026-07-25) — раньше на узких экранах строка нав-ссылок
   просто вылезала за экран без переноса/скролла. Сама навигация становится горизонтально
   прокручиваемой лентой, а не переносится по строкам — компактнее и привычнее для пальца. */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .topbar > div:first-child { width: 100%; gap: 12px; }
  .topbar nav { display: flex; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .topbar nav a { margin-right: 14px !important; font-size: 13px; flex: 0 0 auto; }
  .topbar .user { width: 100%; justify-content: space-between; font-size: 12px; }
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.btn {
  display: inline-block;
  background: var(--sea);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.btn:hover { background: var(--sea-dark); }
.btn.secondary { background: var(--grey-dark); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

label { display: block; font-size: 13px; margin: 10px 0 4px; color: var(--dark); }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--grey-dark);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}

.error { color: var(--danger); font-size: 14px; margin-top: 8px; }
.hint { color: #6a7a7f; font-size: 13px; }

.badge {
  display: inline-block;
  background: var(--grey);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.badge.locked { background: #f0dede; color: var(--danger); }

/* Kanban board */
.board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
}
.column {
  flex: 0 0 260px;
  background: rgba(255,255,255,0.5);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 200px;
}
.column h3, .column .column-head { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.column.dragover { outline: 2px dashed var(--sea); }
.column.column-dragover { outline: 2px dashed var(--dark); }
/* На узком экране столбец занимает почти весь экран — свайп между столбцами ощущается
   как переключение "по одному", а не мелкая полоска (решено 2026-07-25). */
@media (max-width: 600px) { .column { flex: 0 0 84vw; } }

/* Заголовок столбца канбана — перетаскиваемый (перестановка этапов местами, только admin,
   решено 2026-07-25, по образцу AmoCRM) + значок переименования. */
.column-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; cursor: grab; }
.column-head:active { cursor: grabbing; }
.column-head .editStageBtn { background: none; border: none; cursor: pointer; font-size: 13px; padding: 0 2px; opacity: 0.6; }
.column-head .editStageBtn:hover { opacity: 1; }
.add-stage-column {
  flex: 0 0 140px; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--grey-dark); border-radius: var(--radius); min-height: 60px;
  color: #6a7a7f; cursor: pointer; background: none; font-family: inherit; font-size: 14px;
}
.add-stage-column:hover { border-color: var(--sea); color: var(--sea-dark); }
.view-toggle { display: inline-flex; gap: 6px; margin-bottom: 12px; }
.view-toggle button.active { background: var(--sea); color: white; }
.deal-card {
  background: var(--white);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  font-size: 13px;
}
.deal-card:active { cursor: grabbing; }
.deal-card .name { font-weight: 700; margin-bottom: 4px; }
.deal-card .price { color: var(--sea-dark); }

.placeholder {
  border: 1px dashed var(--grey-dark);
  border-radius: var(--radius);
  padding: 16px;
  color: #6a7a7f;
  font-size: 13px;
  text-align: center;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grey); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}
.grid-deal { display: grid; grid-template-columns: 1fr 3fr; gap: 16px; align-items: start; }
@media (max-width: 900px) {
  .grid-deal { grid-template-columns: 1fr; }
}

/* Строка реализации: товар — широкий, кол-во/цена/сумма — узкие */
.realize-line { display: flex; gap: 8px; align-items: end; margin-bottom: 8px; }
.realize-line .rlProduct { flex: 3 1 auto; min-width: 0; }
.realize-line .rlQty { flex: 0 0 70px; }
.realize-line .rlPrice { flex: 0 0 90px; }
.realize-line .rlSum { flex: 0 0 100px; }
.realize-line .rlSum .value { font-weight: 700; padding: 8px 0; font-size: 14px; }
.realize-total { text-align: right; font-size: 15px; margin: 8px 0; }
.line-row { display: flex; gap: 8px; align-items: end; margin-bottom: 8px; }
.line-row > div { flex: 1; }
@media (max-width: 600px) {
  .realize-line, .line-row { flex-wrap: wrap; }
  .realize-line .rlProduct { flex: 1 1 100%; }
}

/* Общие карточки-сводки (оплата/долг, статистика) */
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 4px; }
.stat { background: var(--grey-light); border-radius: var(--radius); padding: 8px 10px; min-width: 96px; flex: 1 1 96px; }
.stat .label { font-size: 11px; color: #6a7a7f; }
.stat .value { font-size: 16px; font-weight: 700; font-family: "RoadRadio", "Circe", sans-serif; }
.stat.debt .value { color: var(--danger); }
.stat.ok .value { color: var(--sea-dark); }

/* Напоминания / задачи */
.reminder-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grey); font-size: 14px; }
.reminder-item:last-child { border-bottom: none; }
.reminder-item.overdue { color: var(--danger); font-weight: 700; }
.reminder-item .rem-type { flex: 0 0 auto; background: var(--grey); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.reminder-item.overdue .rem-type { background: #f0dede; }
.reminder-item .rem-note { flex: 1; }
.reminder-item .rem-date { flex: 0 0 auto; color: #6a7a7f; font-size: 13px; }
.reminder-item.overdue .rem-date { color: var(--danger); }

/* Стены/проёмы замера */
#wallsContainer { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
@media (max-width: 700px) { #wallsContainer { grid-template-columns: 1fr; } }
.wall-block { border: 1px solid var(--grey); border-radius: var(--radius); padding: 10px; margin-bottom: 0; font-size: 13px; }
.wall-block label { font-size: 12px; margin: 6px 0 3px; }
.wall-block .wall-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
#measurementSummary { font-size: 12px; line-height: 1.5; }
.opening-row { display: flex; gap: 8px; align-items: end; margin: 6px 0; padding: 8px; background: var(--grey-light); border-radius: 8px; }
.opening-row > div { flex: 1; }

/* Каталог сметы */
.estimate-layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .estimate-layout { grid-template-columns: 1fr; } }
.catalog-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--grey); font-size: 13px; }
.catalog-item:last-child { border-bottom: none; }
.catalog-group-label { font-weight: 700; margin: 10px 0 4px; font-size: 13px; color: var(--dark); }

/* Страница "Задачи" */
tr.overdue-row td { color: var(--danger); font-weight: 700; }

/* Плитки быстрой навигации в карточке сделки (образец AmoCRM, решено 2026-07-25) —
   вместо того, чтобы всё (замер/смета/напоминания/документы/история) было видно одним
   полотном, сверху — ряд ярлыков со счётчиками, клик прокручивает к нужному блоку. */
.deal-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
@media (max-width: 900px) { .deal-tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .deal-tiles { grid-template-columns: repeat(2, 1fr); } }
.deal-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; background: var(--white); border-radius: var(--radius); padding: 12px 6px;
  cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.08); border: none; font-family: inherit;
  text-align: center;
}
.deal-tile:hover { box-shadow: 0 3px 8px rgba(0,0,0,0.15); }
.deal-tile .icon { font-size: 22px; }
.deal-tile .label { font-size: 12px; font-weight: 700; color: var(--dark); }
.deal-tile .count { font-size: 11px; color: #6a7a7f; }
.deal-tile .count.burning { color: var(--danger); font-weight: 700; }

/* Лента "История" с разделителями по датам (образец AmoCRM) */
.history-day { text-align: center; margin: 16px 0 8px; }
.history-day span { display: inline-block; background: var(--grey-light); border-radius: 999px; padding: 2px 12px; font-size: 12px; color: #6a7a7f; }
.history-day:first-child { margin-top: 0; }
.history-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.history-tabs button { background: var(--grey-light); border: none; border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; font-family: inherit; }
.history-tabs button.active { background: var(--sea); color: white; }
.history-event { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--grey); font-size: 14px; }
.history-event:last-child { border-bottom: none; }
.history-event-time { flex: 0 0 46px; color: #6a7a7f; font-size: 12px; padding-top: 2px; }
.history-event-body { flex: 1; min-width: 0; }

/* Карточка сделки: лента прокручивается отдельно, а действия остаются у нижней границы окна —
   паттерн AmoCRM, адаптированный под реальные формы Флагман Строй. */
#historyCard { display: flex; flex-direction: column; position: relative; }
#historyList { min-height: 120px; }
#historyActionDock { margin-top: 12px; border-top: 1px solid var(--grey); padding-top: 10px; background: var(--white); }
.history-action-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.history-action-tab { flex: 0 0 auto; border: none; border-radius: 999px; background: var(--grey-light); color: var(--text); padding: 6px 10px; font-family: inherit; font-size: 12px; cursor: pointer; }
.history-action-tab.active { background: var(--sea); color: white; }
#quickReminderForm { margin-top: 8px; }

/* Рабочая область открывает ту же реальную форму прямо внутри карточки. Карточки не остаются
   вторым полотном под историей — внизу страницы больше нечего догонять скроллом. */
#paymentCard, #documentsCard, #realizationCard, #measurementsCard, #estimatesCard { display: none; }
#dealWorkspaceDrawer {
  position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column;
  padding: 16px; border-radius: var(--radius); background: var(--white);
}
#dealWorkspaceDrawer[hidden] { display: none; }
.deal-workspace-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 12px; border-bottom: 1px solid var(--grey);
}
.deal-workspace-head strong { font-family: "RoadRadio", "Circe", sans-serif; font-size: 18px; }
#dealWorkspaceBody { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 3px 3px 0; }
#dealWorkspaceDrawer #paymentCard,
#dealWorkspaceDrawer #documentsCard,
#dealWorkspaceDrawer #realizationCard,
#dealWorkspaceDrawer #measurementsCard,
#dealWorkspaceDrawer #estimatesCard {
  display: block; margin: 0 !important; padding: 0; box-shadow: none; border-radius: 0;
}
@media (max-width: 900px) {
  #dealWorkspaceDrawer { position: fixed; inset: 8px; z-index: 40; box-shadow: 0 8px 28px rgba(0,0,0,0.2); }
}
@media (min-width: 901px) {
  #historyCard { position: sticky; top: 12px; height: calc(100vh - 104px); }
  #historyList { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 5px; }
  #historyActionDock { flex: 0 0 auto; }
}

/* Финансы: полосовые диаграммы без библиотек (решено 2026-07-25) */
.fin-bar-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.fin-bar-row .fin-label { flex: 0 0 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fin-bar-row .fin-track { flex: 1; background: var(--grey-light); border-radius: 6px; height: 14px; overflow: hidden; }
.fin-bar-row .fin-fill { background: var(--sea); height: 100%; }
.fin-bar-row .fin-fill.expense { background: var(--danger); }
.fin-bar-row .fin-value { flex: 0 0 110px; text-align: right; font-weight: 700; }
@media (max-width: 600px) {
  .fin-bar-row .fin-label { flex-basis: 100px; font-size: 12px; }
  .fin-bar-row .fin-value { flex-basis: 84px; font-size: 12px; }
}

/* Автодополнение контакта (добавление сделки) */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; z-index: 10; left: 0; right: 0; top: 100%;
  background: var(--white); border: 1px solid var(--grey-dark); border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12); max-height: 220px; overflow-y: auto; margin-top: 2px;
}
.autocomplete-item { padding: 8px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--grey); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--grey-light); }
.autocomplete-item .ac-phone { color: #6a7a7f; font-size: 12px; }
