/* Plasthic CRM — palette overrides for Bootstrap 5.3 + utilities. */

:root {
  /* Plasthic palette */
  --plasthic-red:      #E12D0E;
  --plasthic-red-soft: #ff2d00;
  --plasthic-red-deep: #c42609;
  --plasthic-black:    #171717;
  --plasthic-text:     #3f3f3f;
  --plasthic-muted:    #666666;
  --plasthic-border:   #dddddd;
  --plasthic-bg-light: #f8fcfb;
  --plasthic-bg-canvas: #f5f5f5;

  /* Bootstrap 5.3 token overrides */
  --bs-primary:        var(--plasthic-red);
  --bs-primary-rgb:    225, 45, 14;
  --bs-link-color:     var(--plasthic-red);
  --bs-link-hover-color: var(--plasthic-red-deep);
  --bs-link-color-rgb: 225, 45, 14;
  --bs-body-color:     var(--plasthic-text);
  --bs-body-bg:        var(--plasthic-bg-canvas);
  --bs-border-color:   var(--plasthic-border);
  --bs-border-radius:  0.625rem;
  --bs-border-radius-sm: 0.5rem;
  --bs-border-radius-lg: 0.875rem;
  --bs-heading-color:  var(--plasthic-black);
  --bs-emphasis-color: var(--plasthic-black);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.95rem;
  min-height: 100vh;
}

a {
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--plasthic-red);
  --bs-btn-border-color: var(--plasthic-red);
  --bs-btn-hover-bg: var(--plasthic-red-deep);
  --bs-btn-hover-border-color: var(--plasthic-red-deep);
  --bs-btn-active-bg: var(--plasthic-red-deep);
  --bs-btn-active-border-color: var(--plasthic-red-deep);
  --bs-btn-disabled-bg: var(--plasthic-red);
  --bs-btn-disabled-border-color: var(--plasthic-red);
}

.btn-outline-primary {
  --bs-btn-color: var(--plasthic-red);
  --bs-btn-border-color: var(--plasthic-red);
  --bs-btn-hover-bg: var(--plasthic-red);
  --bs-btn-hover-border-color: var(--plasthic-red);
  --bs-btn-active-bg: var(--plasthic-red-deep);
  --bs-btn-active-border-color: var(--plasthic-red-deep);
}

.btn-dark {
  --bs-btn-bg: var(--plasthic-black);
  --bs-btn-border-color: var(--plasthic-black);
  --bs-btn-hover-bg: #000;
  --bs-btn-hover-border-color: #000;
}

/* ── Navbar ─────────────────────────────────────────────────────────────── */
.navbar.navbar-plasthic {
  background-color: var(--plasthic-black);
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
}

.navbar.navbar-plasthic .navbar-brand,
.navbar.navbar-plasthic .nav-link {
  color: rgba(255, 255, 255, 0.92);
}

.navbar.navbar-plasthic .navbar-brand {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.navbar.navbar-plasthic .nav-link.active,
.navbar.navbar-plasthic .nav-link:hover {
  color: var(--plasthic-red);
}

/* ── Cards / blocks ─────────────────────────────────────────────────────── */
.card {
  border-radius: var(--bs-border-radius-lg);
  box-shadow: 0 1px 2px rgba(23, 23, 23, 0.04);
  background: #fff;
}

.card-header {
  font-weight: 600;
  color: var(--plasthic-black);
  background: #fff;
  border-bottom: 1px solid var(--plasthic-border);
}

/* ── Score badges ───────────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.score-badge.cold { background: #fde3df; color: var(--plasthic-red-deep); }
.score-badge.warm { background: #fff3cd; color: #92682a; }
.score-badge.hot  { background: #d8f3dc; color: #1b6b3b; }

/* ── Stage chips ────────────────────────────────────────────────────────── */
.stage-chip {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: rgba(23, 23, 23, 0.06);
  color: var(--plasthic-black);
}

/* ── Auth pages ─────────────────────────────────────────────────────────── */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--plasthic-bg-light) 0%, var(--plasthic-bg-canvas) 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  background: #fff;
  border-radius: var(--bs-border-radius-lg);
  box-shadow: 0 12px 32px rgba(23, 23, 23, 0.08);
}

.auth-card h1 {
  font-size: 1.7rem;
  margin-bottom: 0.25rem;
  color: var(--plasthic-black);
  font-weight: 600;
}

.auth-card .lede {
  color: var(--plasthic-muted);
  margin-bottom: 1.5rem;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table {
  --bs-table-hover-bg: rgba(225, 45, 14, 0.04);
  background: #fff;
}

.table th {
  font-weight: 600;
  color: var(--plasthic-black);
  border-bottom: 2px solid var(--plasthic-border);
}

.table tbody tr {
  cursor: pointer;
}

/* ── Misc ───────────────────────────────────────────────────────────────── */
.text-plasthic-muted {
  color: var(--plasthic-muted);
}

.divider {
  border-top: 1px solid var(--plasthic-border);
  margin: 1.5rem 0;
}

/* ── Sidebar navigation ─────────────────────────────────────────────────── */
:root {
  --crm-sb-w: 240px;
  --crm-sb-w-collapsed: 74px;
}
body.crm-has-sidebar               { --crm-cur-w: var(--crm-sb-w); }
body.crm-has-sidebar.crm-collapsed { --crm-cur-w: var(--crm-sb-w-collapsed); }

.crm-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--crm-cur-w);
  background: var(--plasthic-black);
  color: rgba(255, 255, 255, 0.92);
  display: flex;
  flex-direction: column;
  z-index: 1045;
  transition: width 0.18s ease, transform 0.2s ease;
}
body.crm-has-sidebar > main {
  margin-left: var(--crm-cur-w);
  width: calc(100% - var(--crm-cur-w));   /* не даём контейнеру вылезти за вьюпорт */
  min-width: 0;                            /* таблицы/флекс не распирают ширину */
  overflow-x: hidden;                      /* страховка: широкий контент не скроллит всю страницу */
  transition: margin-left 0.18s ease, width 0.18s ease;
}

.crm-sidebar__top {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.85rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 62px;
}
.crm-brand { display: flex; align-items: center; gap: 0.6rem; color: #fff; font-weight: 600; overflow: hidden; flex: 1; }
.crm-brand:hover { text-decoration: none; color: #fff; }
.crm-brand__mark {  /* fallback square used in the mobile bar */
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  background: var(--plasthic-red); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.crm-brand__word { height: 24px; width: auto; display: block; }
.crm-brand__icon { height: 30px; width: 30px; flex: none; display: none; }
.crm-collapse-btn {
  flex: none; background: transparent; border: 0; color: rgba(255, 255, 255, 0.55);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.crm-collapse-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.crm-collapse-btn .bi { transition: transform 0.18s ease; }
body.crm-collapsed .crm-collapse-btn .bi { transform: rotate(180deg); }

.crm-nav { flex: 1; overflow-y: auto; overflow-x: visible; padding: 0.6rem 0.5rem; }
.crm-nav::-webkit-scrollbar { width: 6px; }
.crm-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 3px; }

.crm-nav__group { position: relative; margin-bottom: 0.1rem; }
.crm-nav__label {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.7rem; border-radius: 9px;
  color: rgba(255, 255, 255, 0.8); font-weight: 600; font-size: 0.74rem;
  letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap;
  cursor: pointer; user-select: none;
}
.crm-nav__label:hover { background: rgba(255, 255, 255, 0.05); }
.crm-nav__label .bi { font-size: 1.1rem; flex: none; width: 1.3rem; text-align: center; }
.crm-nav__chev { margin-left: auto; font-size: 0.75rem; opacity: 0.5; transition: transform 0.18s; }
.crm-nav__group.is-open > .crm-nav__label .crm-nav__chev { transform: rotate(90deg); }
.crm-nav__group.is-active > .crm-nav__label { color: #fff; }

.crm-nav__sub { display: flex; flex-direction: column; max-height: 0; overflow: hidden; transition: max-height 0.25s ease; }
.crm-nav__group.is-open > .crm-nav__sub { max-height: 34rem; }
.crm-nav__sub-head { display: none; }
.crm-nav__sub a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.48rem 0.7rem 0.48rem 1.15rem; margin: 0.08rem 0;
  border-radius: 8px; color: rgba(255, 255, 255, 0.76); font-size: 0.9rem; white-space: nowrap;
}
.crm-nav__sub a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.crm-nav__sub a.active { background: var(--plasthic-red); color: #fff; }
.crm-nav__sub a .bi { font-size: 0.95rem; flex: none; width: 1.15rem; text-align: center; }

.crm-sidebar__bottom { border-top: 1px solid rgba(255, 255, 255, 0.08); padding: 0.7rem 0.8rem; }
.crm-user { font-size: 0.8rem; color: rgba(255, 255, 255, 0.7); margin-bottom: 0.55rem; word-break: break-all; }
.crm-signout { width: 100%; }

/* Collapsed mode → icon rail + hover flyout */
body.crm-collapsed .crm-brand__word,
body.crm-collapsed .crm-nav__txt,
body.crm-collapsed .crm-nav__chev,
body.crm-collapsed .crm-user { display: none; }
body.crm-collapsed .crm-brand__icon { display: block; }
body.crm-collapsed .crm-sidebar__top { justify-content: center; }
body.crm-collapsed .crm-nav__label { justify-content: center; padding: 0.6rem; }
body.crm-collapsed .crm-nav__sub {
  position: absolute; left: 100%; top: -0.3rem; margin-left: 8px;
  min-width: 210px; max-height: none; overflow: visible;
  background: #1f1f1f; border-radius: 11px; padding: 0.45rem;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4); opacity: 0; visibility: hidden;
  transform: translateX(-6px); transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
body.crm-collapsed .crm-nav__group.is-open > .crm-nav__sub {
  opacity: 1; visibility: visible; transform: translateX(0);
}
body.crm-collapsed .crm-nav__sub-head {
  display: block; padding: 0.3rem 0.6rem 0.45rem; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: rgba(255, 255, 255, 0.45);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 0.25rem;
}
body.crm-collapsed .crm-nav__group.is-active > .crm-nav__label {
  background: rgba(225, 45, 14, 0.18); color: var(--plasthic-red);
}

/* Mobile: off-canvas */
.crm-mobile-bar { display: none; }
.crm-overlay { display: none; }
@media (max-width: 767.98px) {
  .crm-sidebar { transform: translateX(-100%); width: var(--crm-sb-w); }
  body.crm-mobile-open .crm-sidebar { transform: translateX(0); }
  body.crm-has-sidebar > main { margin-left: 0; width: 100%; padding-top: 4.2rem; }
  .crm-collapse-btn { display: none; }
  .crm-mobile-bar {
    display: flex; align-items: center; gap: 0.6rem;
    position: fixed; top: 0; left: 0; right: 0; height: 54px; z-index: 1030;
    background: var(--plasthic-black); color: #fff; padding: 0 0.9rem;
  }
  .crm-mobile-bar button { background: transparent; border: 0; color: #fff; font-size: 1.4rem; }
  body.crm-mobile-open .crm-overlay {
    display: block; position: fixed; inset: 0; z-index: 1040; background: rgba(0, 0, 0, 0.45);
  }
  body.crm-collapsed .crm-nav__txt { display: inline; }
  body.crm-collapsed .crm-brand__word { display: block; }
  body.crm-collapsed .crm-brand__icon { display: none; } /* on mobile always expanded */
}

/* ── Tables on mobile ────────────────────────────────────────────────────────
   A CRM table has more columns than a phone has width. `.table-stack` drops the
   header row and turns each row into a labelled record.

   Two flavours:
   · default (lists) — label left, value right on one line, so a record stays
     compact instead of running a whole screen.
   · `--sections` (the Procedures card, the invoice builder) — label above and
     the control full width, because those cells hold inputs, not short values. */
@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack tbody tr,
  .table-stack tbody td { display: block; width: 100% !important; }

  /* These tables already sit inside a .card, so rows are separated by a rule
     rather than boxed again — a card inside a card reads as a mistake. */
  .table-stack tbody tr {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--plasthic-border);
    background: transparent !important;
  }
  .table-stack tbody tr:last-child { border-bottom: 0; }

  .table-stack tbody td {
    border: 0 !important;
    background: transparent !important;
    /* Desktop spacing/alignment utilities (ps-4, pe-4, text-end) would leave
       stray indents and right-aligned values once stacked. */
    padding: 0.22rem 0 !important;
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  /* Lists: label and value share a line. */
  .table-stack:not(.table-stack--sections) tbody td[data-label] {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
  }
  .table-stack:not(.table-stack--sections) tbody td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 7.5rem;
    color: var(--plasthic-muted);
    font-size: 0.78rem;
    font-weight: 400;
  }

  /* Form-heavy cells: label above, control full width. */
  .table-stack--sections tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--plasthic-muted);
    font-size: 0.78rem;
    margin-bottom: 0.25rem;
  }
  .table-stack--sections tbody td + td {
    border-top: 1px solid var(--plasthic-border) !important;
    padding-top: 0.6rem !important;
    margin-top: 0.4rem;
  }
  .table-stack--sections tbody td .form-select,
  .table-stack--sections tbody td .form-control,
  .table-stack--sections tbody td .ts-wrapper { max-width: 100% !important; width: 100%; }

  /* An actions cell has no label; give its buttons room and let them wrap. */
  .table-stack tbody td:not([data-label]) {
    display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem;
  }
  /* A button label must never break mid-word ("Ad / d"). */
  .table-stack tbody td .btn { white-space: nowrap; overflow-wrap: normal; }
}

/* A tap on a touch screen leaves the row stuck in :hover until you tap
   elsewhere, so the highlight reads as a selection that isn't there. Hover
   styling is for devices that actually hover. */
@media (hover: none) {
  .table { --bs-table-hover-bg: transparent; }
  .table-hover > tbody > tr:hover > * { background-color: transparent !important; }
}

/* ── Procedures-style tables inside cards ───────────────────────────────────
   Bootstrap paints every th/td with --bs-table-bg (the page body background),
   which repaints the white card grey — and anywhere a rowspan/colspan leaves
   no cell, the card shows through white, producing ragged notches. Cells on a
   card must stay transparent. */
.card .table { --bs-table-bg: transparent; }

/* One subtle rule between procedure rows (the table is otherwise borderless,
   and two stacked selects with no separator read as one blob). */
.table-procedures tbody tr + tr > td {
  border-top: 1px solid var(--plasthic-border) !important;
}
.table-procedures tbody td { padding-top: 0.65rem; padding-bottom: 0.65rem; }

/* Tom Select: keep the text clear of the chevron the wrapper paints on the
   right — long names ("BHT CLINIC Istanbul Tema Hospital") ran underneath it. */
.ts-wrapper.form-select .ts-control,
.ts-wrapper.form-select.form-select-sm .ts-control {
  padding-right: 1.7rem !important;
}
