/* KRAFTEK CRM — цветовете са от kraftekdesign.com */
:root {
  --bg: #f3efe8;
  --card: #ffffff;
  --ink: #1c1a17;
  --muted: #8a8378;
  --line: #e8e2d8;
  --dark: #14110c;
  --accent: #c4a06a;
  --accent-ink: #8f7347;
  --ok: #3d7a4f;
  --ok-bg: #e9f3ec;
  --warn-bg: #fbf1dc;
  --bad: #a8402f;
  --meeting: #2456c9;
  --meeting-bg: #e4ecfd;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 20px; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }

.brand { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; white-space: nowrap; }
.brand span { color: var(--accent); }

.btn {
  padding: 7px 15px;
  border: 1px solid transparent;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
}
.btn--primary { background: var(--accent); color: var(--dark); font-weight: 600; }
.btn--primary:hover { background: #d1ae7a; }
.btn--ghost { background: transparent; border-color: currentColor; opacity: 0.75; }
.btn--ghost:hover { opacity: 1; }
.btn--small { padding: 4px 11px; background: var(--card); border-color: var(--line); }
.btn--small:hover { border-color: var(--accent); }

/* ---------- Вход ---------- */
.login {
  max-width: 340px;
  margin: 18vh auto 0;
  padding: 32px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 10px;
}
.login .brand { margin-bottom: 12px; }
.login label { font-size: 13px; color: var(--muted); }
.login__error { margin: 0; min-height: 20px; color: var(--bad); font-size: 13px; }

/* ---------- Един екран: лента + календар + канбан ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 16px;
  background: var(--dark);
  color: #f2ede4;
}
.modules { display: flex; gap: 6px; flex: 1; margin-left: 10px; }
.modules a {
  padding: 5px 13px;
  border-radius: 99px;
  color: #a89f92;
  text-decoration: none;
}
.modules a.is-active { background: rgba(196, 160, 106, 0.18); color: var(--accent); }
.search { width: 260px; padding: 6px 12px; background: #221d16; border-color: #3a3328; border-radius: 99px; color: #f2ede4; }
.search::placeholder { color: #8a8378; }

.board {
  display: grid;
  grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  padding: 10px 16px 12px;
}

/* ---------- Календар ---------- */
.cal { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; min-height: 0; }
.cal__bar { display: flex; align-items: center; gap: 14px; min-width: 0; }
.cal__nav { display: flex; gap: 4px; }
.cal__bar h1 { min-width: 190px; white-space: nowrap; }

.chips { display: flex; gap: 4px; }
.chips button {
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
}
.chips button.is-active { background: var(--dark); border-color: var(--dark); color: #f2ede4; }

.status { flex: 1; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.status.is-error { color: var(--bad); }

.legend { display: flex; gap: 14px; margin: 0; padding: 0; list-style: none; font-size: 12px; color: var(--muted); white-space: nowrap; }
.legend li { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 3px; }
.dot--lead { background: var(--accent); }
.dot--done { background: #cfc8bb; }
.dot--meeting { background: var(--meeting); }

.cal__grid { display: grid; gap: 6px; min-height: 0; }
.cal__grid.is-week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal__grid.is-month { grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto; grid-auto-rows: minmax(0, 1fr); gap: 4px; }

.day, .cell {
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.day { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.day.is-today, .cell.is-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.day__head span, .kcol__head span {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.day__body { display: grid; gap: 4px; align-content: start; padding: 6px; overflow-y: auto; }

.weekday { padding: 0 6px; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.cell { display: grid; gap: 3px; align-content: start; padding: 4px 5px; overflow-y: auto; }
.cell.is-other { background: transparent; }
.cell.is-other .cell__num { color: #c2bbae; }
.cell__num { justify-self: start; padding: 0 4px; background: none; border: 0; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; }
.cell__num:hover { background: var(--bg); }
.cell .chip { padding: 1px 6px; font-size: 12px; }

/* събитие в календара */
.chip {
  display: flex;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 3px 8px;
  background: var(--warn-bg);
  border: 0;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.chip:hover { filter: brightness(0.96); }
.chip__time { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip.is-contacted { background: #f1eee8; border-left-color: #cfc8bb; color: var(--muted); }
.chip.is-contacted .chip__name { font-weight: 400; }
.chip--meeting { background: var(--meeting); border-left-color: #12327f; color: #fff; }
.chip--meeting .chip__time { color: #cfdcfb; }
.chip.is-lost, .kcard.is-lost { opacity: 0.5; }

/* чака среща → пулсира */
.is-pulsing { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(36, 86, 201, 0.6); }
  50% { box-shadow: 0 0 0 5px rgba(36, 86, 201, 0); filter: brightness(1.18); }
}

/* ---------- Канбан ---------- */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; min-height: 0; }
.kcol {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  background: #ebe6dc;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 10px;
}
.kcol--contacted { border-top-color: #cfc8bb; }
.kcol--meeting { border-top-color: var(--meeting); }
.kcol--reoffer { border-top-color: #b06a2c; }
.kcol--contract_wait { border-top-color: #7a5aa8; }
.kcol--signed { border-top-color: var(--ok); }
.kcol.is-over { background: #e0d8c8; outline: 2px dashed var(--accent); outline-offset: -4px; }
.kcol__head { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px 3px; font-size: 13px; }
.kcol__head span { background: var(--card); }
.kcol__body { display: grid; gap: 5px; align-content: start; padding: 5px 6px 6px; overflow-y: auto; }

.kcard {
  display: grid;
  gap: 1px;
  width: 100%;
  min-width: 0;
  padding: 6px 9px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  cursor: grab;
}
.kcard:hover { border-color: var(--accent); }
.kcard b, .kcard span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard span { font-size: 12px; color: var(--muted); }
.kcard .kcard__meeting { color: var(--meeting); font-weight: 600; }
.kcard.is-pulsing { background: var(--meeting-bg); border-color: var(--meeting); }

/* ---------- Диалози ---------- */
.dialog { width: min(460px, calc(100vw - 32px)); padding: 26px; border: 0; border-radius: 14px; }
.dialog::backdrop { background: rgba(20, 17, 12, 0.55); }
.dialog form { display: grid; gap: 10px; }
.dialog form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 10px; }

.dialog--lead[open] {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 26px;
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
}
.dialog__close {
  position: absolute;
  top: 8px;
  right: 12px;
  padding: 0 6px;
  background: none;
  border: 0;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.lead__info { min-width: 0; }
.lead__name { margin: 0 0 4px; overflow-wrap: anywhere; }
.lead__contacts { margin: 0 0 10px; padding: 0; list-style: none; font-size: 15px; overflow-wrap: anywhere; }
.lead__contacts a { color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.lead__contacts a:hover { text-decoration: underline; }
.lead__contacts span { color: var(--muted); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge {
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--bg);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.badge--cat { background: var(--dark); color: var(--accent); }
.lead__price { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.lead__request { margin: 0; font-size: 13px; color: #5f594f; white-space: pre-line; overflow-wrap: anywhere; }

.lead__result { display: grid; gap: 6px; align-content: start; min-width: 0; padding-top: 14px; }
.lead__result > label { margin-top: 4px; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.lead__check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  background: var(--warn-bg);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.lead__check input { width: 18px; height: 18px; flex: none; accent-color: var(--ok); }
.lead__check.is-on { background: var(--ok-bg); color: var(--ok); }
.lead__when { margin: 4px 0 0; min-height: 17px; font-size: 12px; color: var(--muted); }
.lead__hint { margin: 0; font-size: 12px; color: var(--meeting); }
.lead__hint:empty { display: none; }
.lead__foot { display: flex; justify-content: space-between; align-items: center; min-height: 18px; }
.lead__saved { font-size: 12px; color: var(--ok); }
.lead__saved.is-error { color: var(--bad); }
.link { padding: 0; background: none; border: 0; color: var(--accent-ink); font-size: 12px; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link--danger { color: var(--bad); }

.tabs { display: none; }

/* телефон: календар и канбан са отделни раздели, всеки на цял екран */
@media (max-width: 900px) {
  .app { grid-template-rows: auto minmax(0, 1fr) auto; }
  input, select, textarea { font-size: 16px; } /* iOS не приближава при фокус */

  .top { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .top .brand { flex: 1; font-size: 14px; letter-spacing: 1px; }
  .top .btn { padding: 7px 12px; }
  .modules { display: none; }
  .search { order: 5; flex: 1 1 100%; width: auto; padding: 8px 14px; }

  .board { grid-template-rows: minmax(0, 1fr); padding: 8px 12px; }
  .board[data-tab="cal"] .kanban, .board[data-tab="kanban"] .cal { display: none; }

  .cal__bar { flex-wrap: wrap; gap: 8px; }
  .cal__bar h1 { flex: 1 1 60%; min-width: 0; font-size: 16px; }
  #cat-chips { flex: 1; min-width: 0; overflow-x: auto; }
  .cal__nav .btn, .chips button { padding: 7px 13px; }
  .legend, .status:empty { display: none; }
  .status { flex: 1 1 100%; white-space: normal; }

  /* седмицата е списък по дни */
  .cal__grid.is-week { display: block; overflow-y: auto; }
  .day { display: block; margin-bottom: 6px; }
  .day__body { overflow: visible; }
  .day__body:empty { display: none; }
  .day:has(.day__body:empty) .day__head { border-bottom: 0; color: var(--muted); }
  .day .chip { padding: 10px 11px; font-size: 15px; }

  /* месецът показва само точки; докосване на ден отваря седмицата му */
  .cell { padding: 3px; overflow: hidden; cursor: pointer; }
  .cell .chip { height: 5px; padding: 0; border: 0; background: var(--accent); pointer-events: none; }
  .cell .chip span { display: none; }
  .cell .chip.is-contacted { background: #cfc8bb; }
  .cell .chip--meeting { background: var(--meeting); }

  /* канбанът се плъзга настрани колона по колона */
  .kanban { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-left: 0; }
  .kcol { flex: 0 0 84%; scroll-snap-align: start; }
  .kcard { padding: 10px 12px; font-size: 15px; }
  .kcard span { font-size: 13px; }

  .tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--dark); padding-bottom: env(safe-area-inset-bottom); }
  .tabs button { padding: 13px 0; background: none; border: 0; border-top: 2px solid transparent; color: #a89f92; font-weight: 600; cursor: pointer; }
  .tabs button.is-active { border-top-color: var(--accent); color: var(--accent); }

  /* попъпите излизат отдолу на цялата ширина */
  .dialog, .dialog--lead[open] {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0;
    padding: 22px 16px calc(18px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
  }
  .dialog--lead[open] { grid-template-columns: 1fr; gap: 6px; }
  .dialog__close { top: 6px; right: 8px; padding: 6px 12px; }
  .lead__contacts { font-size: 17px; line-height: 1.9; }
  .lead__check { padding: 13px; }
  .link { padding: 8px 0; font-size: 14px; }
}
