/* Smart Concierge CRM Styles (CONTRACT §42-43, W2) */
:root {
  --paper: #F7F5EF;
  --surface: #FFFFFF;
  --sunk: #F0EDE4;
  --line: #E1DDD2;
  --line-strong: #CBC6B8;
  --ink: #1C211E;
  --muted: #596259;
  --pine: #1F4037;
  --pine-hover: #16302A;
  --pine-soft: #E5ECE7;
  --sub-bg: #D9EAD3;
  --sub-ink: #21492A;
  --sub-dot: #3F8A4E;
  --tbl-bg: #EDE9DE;
  --tbl-ink: #46453B;
  --rust: #973A1B;
  --mark: #F4E7B8;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-title: Georgia, "Times New Roman", serif;
  --nav-h: 64px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--font-ui);
  overflow-wrap: break-word;
}

h1, h2, h3, p, ul, ol, dl, dd, figure {
  margin: 0;
  padding: 0;
}

ul, ol {
  list-style: none;
}

a {
  color: inherit;
}

button, input, select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
}

h1:focus {
  outline: none;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: 8px;
  top: -64px;
  background: var(--pine);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  z-index: 30;
}

.skip:focus {
  top: 8px;
}

h1 {
  font: 600 28px/1.2 var(--font-title);
  letter-spacing: 0;
}

h2 {
  font: 600 22px/1.25 var(--font-title);
}

h3 {
  font: 600 16px/1.4 var(--font-ui);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 14px;
  line-height: 1.6;
}

.nowrap {
  white-space: nowrap;
}

/* Utilities for spacing without inline styles */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* Topbar and layout */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 0;
}

.brand {
  font: 600 18px/1.3 var(--font-title);
  color: var(--pine);
}

main {
  padding: 16px 16px calc(var(--nav-h) + 40px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.inner {
  width: 100%;
}

.sidebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.sidebar .brand,
.sidebar .side-note {
  display: none;
}

.nav {
  display: flex;
}

.nav li {
  flex: 1;
}

.nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.3;
  color: var(--muted);
}

.nav a[aria-current=page] {
  color: var(--pine);
  font-weight: 600;
}

.nav svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav .count {
  position: absolute;
  top: 6px;
  left: calc(50% + 8px);
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--rust);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}

/* Badges / Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  min-height: 24px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  white-space: nowrap;
}

.pill::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
}

.pill-sub {
  background: var(--sub-bg);
  color: var(--sub-ink);
}

.pill-sub::before {
  background: var(--sub-dot);
  border-radius: 50%;
}

.pill-table {
  background: var(--tbl-bg);
  color: var(--tbl-ink);
}

.pill-table::before {
  border: 1.5px solid var(--tbl-ink);
  border-radius: 1px;
}

.pill-tg {
  background: transparent;
  color: var(--tbl-ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.pill-tg::before {
  border: 1.5px solid var(--tbl-ink);
  border-radius: 50%;
}

.pill-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex: none;
}

.pill-dot-sub {
  background: var(--sub-dot);
  border-radius: 50%;
}

.pill-dot-table {
  border: 1.5px solid var(--tbl-ink);
  border-radius: 1px;
}

.pill-dot-tg {
  border: 1.5px solid var(--tbl-ink);
  border-radius: 50%;
}

/* Buttons and interactive elements */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--pine);
  background: transparent;
  color: var(--pine);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--pine-soft);
}

.btn-primary {
  background: var(--pine);
  color: #fff;
}

.btn-primary:hover {
  background: var(--pine-hover);
}

.btn[disabled] {
  border-color: var(--line-strong);
  background: var(--sunk);
  color: var(--muted);
  cursor: not-allowed;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0 4px;
  min-height: 44px;
  color: var(--pine);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: 14px;
}

/* Home Overview */
.page-date {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 4px;
}

.home {
  display: grid;
  gap: 40px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.h1-count {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 18px;
  color: var(--muted);
  margin-left: 8px;
  white-space: nowrap;
}

.rows > li {
  border-top: 1px solid var(--line);
}

.rows > li:last-child {
  border-bottom: 1px solid var(--line);
}

.row-link {
  position: relative;
}

.stretch {
  text-decoration: none;
  font-weight: 600;
}

.stretch::after {
  content: "";
  position: absolute;
  inset: 0;
}

.stretch:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.row-link:hover {
  background: rgba(31, 64, 55, .03);
}

.wait-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 16px 0;
  align-items: center;
}

.wait-who {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.wait-who .stretch {
  font-size: 17px;
}

.wait-what {
  grid-column: 1 / -1;
}

.wait-time {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.wait-time small {
  display: inline;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  margin-right: 4px;
}

.wait-time.late {
  color: var(--rust);
}

.wait-row .btn {
  position: relative;
  z-index: 1;
}

.silent-row {
  display: grid;
  gap: 4px;
  padding: 12px 0;
  min-height: 44px;
}

.silent-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.silent-days {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.who-list > li {
  border-top: 1px solid var(--line);
}

.who-list > li:last-child {
  border-bottom: 1px solid var(--line);
}

.who-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 0;
  text-decoration: none;
}

.who-list a:hover {
  background: rgba(31, 64, 55, .03);
}

.who-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.who-num {
  font: 600 28px/1 var(--font-title);
  font-variant-numeric: tabular-nums;
}

.who-note {
  margin-top: 12px;
}

.empty {
  padding: 32px 16px;
  background: var(--sunk);
  border-radius: 8px;
  text-align: center;
}

.empty h2, .empty h3 {
  font: 600 18px/1.4 var(--font-ui);
  margin-bottom: 4px;
}

.empty .btn {
  margin-top: 16px;
}

/* Clients Directory */
.page-head {
  margin-bottom: 24px;
}

.field label, .label {
  display: block;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 500;
  margin-bottom: 4px;
}

.input, .select {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.select {
  min-height: 44px;
  appearance: auto;
}

.input::placeholder {
  color: #6B736B;
}

.search-col {
  margin-bottom: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 6px;
  margin: 8px 0 16px;
}

.chip {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
}

.chip:hover {
  background: var(--sunk);
}

.chip.active,
.chip[aria-pressed=true] {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff;
  font-weight: 500;
}

.chip-n {
  opacity: .75;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.result-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 4px;
}

.c-row {
  padding: 12px 0;
  display: grid;
  gap: 4px;
}

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

.c-top .stretch {
  font-size: 17px;
}

.noname {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 4px;
}

.table-wrap {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-align: left;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line-strong);
  vertical-align: middle;
}

td {
  padding: 12px 12px 12px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr {
  position: relative;
}

tbody tr:hover {
  background: rgba(31, 64, 55, .03);
}

.td-date {
  line-height: 24px;
}

th.num, td.num {
  text-align: right;
  padding-right: 0;
  font-variant-numeric: tabular-nums;
}

.th-btn {
  background: none;
  border: 0;
  padding: 0;
  min-height: 44px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.th-btn span {
  color: var(--muted);
  margin-left: 4px;
}

.col-client { width: 27%; }
.col-group { width: 20%; }
.col-tags { width: 25%; }
.col-date { width: 18%; }
.col-msgs { width: 10%; }

/* Client Card */
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  text-decoration: none;
  color: var(--pine);
  margin-bottom: 4px;
}

.back:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.card-head {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
}

.card-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.card-head h1 {
  overflow-wrap: anywhere;
}

.waiting-note {
  color: var(--rust);
  font-weight: 600;
}

.waiting-note.calm {
  color: var(--ink);
}

.card-head .btn {
  width: 100%;
}

.tg-note {
  font-size: 14px;
  color: var(--muted);
}

.card {
  display: grid;
  gap: 32px;
  grid-template-columns: minmax(0, 1fr);
}

.ai {
  background: var(--sunk);
  border-radius: 8px;
  padding: 16px;
}

.ai-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 4px;
}

.block h2 {
  margin-bottom: 12px;
}

.side {
  display: grid;
  gap: 32px;
  align-content: start;
  min-width: 0;
}

.dl {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
}

.dl dt, .dl dd {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.dl dt {
  font-size: 14px;
  color: var(--muted);
  line-height: 24px;
  padding-right: 12px;
}

.dl .wide {
  grid-column: 1 / -1;
}

.dl dt.wide {
  padding-bottom: 0;
}

.dl dd.wide {
  border-top: 0;
  padding-top: 0;
}

.none {
  color: var(--muted);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--tbl-bg);
  font-size: 14px;
  line-height: 20px;
}

.fact-list li {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.req-item {
  padding: 12px 0;
  display: grid;
  gap: 4px;
}

.req-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.req-meta b {
  font-weight: 500;
  color: var(--ink);
}

.late-text {
  color: var(--rust);
  font-weight: 500;
}

.empty-line {
  padding: 16px;
  background: var(--sunk);
  border-radius: 8px;
  color: var(--muted);
}

/* Feed / Messages */
.feed-search {
  margin-bottom: 16px;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feed-date {
  align-self: center;
  font-size: 14px;
  color: var(--muted);
  padding: 8px 0 4px;
}

.msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
}

.msg-in {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
}

.msg-out {
  align-self: flex-end;
  background: var(--pine-soft);
  border: 1px solid transparent;
}

.msg-from {
  font-size: 14px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.voice {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}

.feed-load-more {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.feed-note {
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

/* Requests */
.req-page {
  display: grid;
  gap: 40px;
}

.req-page .req-item {
  padding: 16px 0;
}

.req-name {
  font-weight: 600;
}

.req-client {
  font-weight: 400;
}

.req-client a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--pine);
  text-underline-offset: 3px;
}

/* Desktop styles */
@media (min-width: 600px) {
  .card-head .btn {
    width: auto;
    justify-self: start;
  }
}

@media (min-width: 1000px) {
  h1 {
    font-size: 34px;
  }

  .topbar {
    display: none;
  }

  .sidebar {
    top: 0;
    right: auto;
    bottom: 0;
    width: 232px;
    border-top: 0;
    border-right: 1px solid var(--line);
    background: var(--paper);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
  }

  .sidebar .brand {
    display: block;
    padding: 0 12px 24px;
  }

  .sidebar .side-note {
    display: block;
    margin-top: auto;
    padding: 0 12px;
    font-size: 14px;
    color: var(--muted);
  }

  .nav {
    flex-direction: column;
    gap: 4px;
  }

  .nav li {
    flex: none;
  }

  .nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 16px;
  }

  .nav a:hover {
    background: var(--sunk);
  }

  .nav a[aria-current=page] {
    background: var(--pine-soft);
  }

  .nav .count {
    position: static;
    margin-left: auto;
  }

  main {
    margin: 0 0 0 232px;
    max-width: none;
    padding: 32px 40px 64px;
  }

  .inner {
    max-width: 1000px;
  }

  .home {
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-areas: "wait who" "silent who";
    grid-template-rows: auto 1fr;
    gap: 40px 48px;
  }

  .home-wait {
    grid-area: wait;
  }

  .home-who {
    grid-area: who;
    padding-top: 48px;
  }

  .home-silent {
    grid-area: silent;
  }

  .wait-row {
    grid-template-columns: 96px minmax(0, 1fr) auto;
    gap: 4px 16px;
    align-items: start;
  }

  .wait-time {
    grid-row: 1 / span 2;
    grid-column: 1;
  }

  .wait-time small {
    display: block;
    margin: 0;
  }

  .wait-who {
    grid-column: 2;
  }

  .wait-what {
    grid-column: 2;
  }

  .wait-row .btn {
    grid-row: 1 / span 2;
    grid-column: 3;
  }

  .silent-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 4px 16px;
  }

  .silent-days {
    grid-column: 2;
    grid-row: 1;
    white-space: nowrap;
  }

  .silent-last {
    grid-column: 1;
  }

  .client-list {
    display: none;
  }

  .table-wrap {
    display: block;
  }

  .tools {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 200px 200px;
    gap: 16px;
    align-items: start;
  }

  .controls {
    display: contents;
  }

  .search-col {
    margin-bottom: 0;
  }

  .chips {
    margin: 0 0 16px;
  }

  .card {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-areas: "ai side" "req side" "feed side";
    grid-template-rows: auto auto 1fr;
    gap: 32px 48px;
  }

  .c-ai { grid-area: ai; }
  .side { grid-area: side; }
  .c-req { grid-area: req; }
  .c-feed { grid-area: feed; }

  .req-page .req-item {
    grid-template-columns: minmax(0, 1fr) 160px 270px;
    gap: 16px;
    align-items: start;
  }

  .req-page .req-meta {
    display: contents;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Страницы списка */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Экран входа */
.login-wrapper { min-height: 80vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px 24px; display: grid; gap: 20px; }
.login-header h1 { font: 500 26px/1.25 var(--font-title); margin-bottom: 8px; }
.login-desc { color: var(--muted); }
.login-btn { display: flex; justify-content: center; width: 100%; min-height: 48px; }
.login-status { color: var(--muted); font-size: 14px; }
.login-retry { display: grid; gap: 12px; margin-top: 12px; }
.login-retry[hidden] { display: none; }
.login-expired-note { color: var(--rust); font-size: 14px; }
.login-retry-btn { display: flex; justify-content: center; min-height: 44px; }
.logout-form { margin-top: 16px; }

.pill { white-space: nowrap; }

/* Лента: своя прокрутка, даты, краткая выжимка в списке */
#feed-container { max-height: 70vh; overflow-y: auto; }
.feed-date { text-align: center; color: var(--muted); font-size: 13px; margin: 12px 0 4px; }
.c-summary { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Выход: на телефоне вверху, на компьютере в боковой панели */
.topbar-logout { margin: 0; }
.topbar-logout .link-btn { min-height: 44px; }
.sidebar .logout-form { display: none; }
@media (min-width: 1000px) {
  .sidebar .logout-form { display: block; }
  .topbar-logout { display: none; }
}

.login-help { display: grid; gap: 6px; }
.login-command { display: block; padding: 8px 10px; background: var(--sunk); border-radius: 8px; font-size: 13px; word-break: break-all; user-select: all; }
