/* DentMate — общие компоненты. Подключать после tokens.css.
   Правила: одна основная кнопка на экран; Brass (--value) только для денег; цвет статуса всегда со словом. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 16px/1.55 var(--font-body);
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-tint); }
.tnum, .money, .kpi-value { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 0.875em; letter-spacing: -0.01em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Типографика */
.display { font: 400 56px/1.1 var(--font-display); letter-spacing: -0.02em; margin: 0; }
.h1 { font: 400 40px/1.2 var(--font-display); letter-spacing: -0.015em; margin: 0; }
.h2 { font: 500 30px/1.2 var(--font-display); letter-spacing: -0.01em; margin: 0; }
.h3 { font: 600 22px/1.35 var(--font-body); letter-spacing: -0.01em; margin: 0; }
.h4 { font: 600 16px/1.4 var(--font-body); margin: 0; }
.body-lg { font-size: 18px; line-height: 1.55; }
.small { font-size: 14px; line-height: 1.5; }
.caption { font: 500 12px/1.35 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.value { color: var(--value); }
@media (max-width: 767px) {
  .display { font-size: 36px; } .h1 { font-size: 30px; } .h2 { font-size: 24px; } .h3 { font-size: 20px; }
}

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent;
  font: 600 15px/1 var(--font-body); white-space: nowrap; cursor: pointer;
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease), transform var(--d-instant) var(--ease), color var(--d-fast) var(--ease);
  touch-action: manipulation; text-decoration: none !important; color: var(--text);
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { border-color: var(--border-control); }
.btn-secondary:hover { background: var(--bg-subtle); }
.btn-ghost { color: var(--text-subtle); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text); }
.btn-tint { background: var(--accent-tint); color: var(--accent); }
.btn-tint:hover { background: var(--accent-tint-2); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-sm svg { width: 16px; height: 16px; }
.btn-lg { height: 52px; padding: 0 24px; font-size: 16px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* Поля */
.field { display: grid; gap: 6px; }
.label { font: 500 14px/1.3 var(--font-body); color: var(--text); }
.hint { font-size: 13px; color: var(--text-muted); }
.input, .select, .textarea {
  height: 44px; width: 100%; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border-control); background: var(--surface); color: var(--text);
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: .8; }
.field-error .input { border-color: var(--danger); }
.error-text { font-size: 13px; color: var(--danger); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); }
.search .input { padding-left: 38px; }
.kbd { font: 500 12px/1 var(--font-mono); padding: 3px 6px; border-radius: 6px; border: 1px solid var(--border); color: var(--text-muted); background: var(--surface); }

/* Переключатель (iOS-style) */
.switch { position: relative; width: 44px; height: 26px; flex: none; display: inline-block; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--disabled); transition: background var(--d-base) var(--ease); }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform var(--d-base) var(--ease-spring); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Сегменты (segmented control) */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--bg-subtle); border: 1px solid var(--border); }
.segmented button { height: 32px; padding: 0 12px; border: 0; background: transparent; border-radius: 8px; font: 500 14px/1 var(--font-body); color: var(--text-subtle); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease); }
.segmented button[aria-pressed="true"], .segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--e1), var(--ring-card); }
.segmented .count { font-size: 12px; color: var(--text-muted); }

/* Карточки */
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--e1), var(--ring-card); padding: var(--s5); }
.card-flat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); }
.card-tint { background: var(--accent-tint-2); border-radius: var(--r-lg); padding: var(--s5); }
.card-value { background: var(--value-tint); border-radius: var(--r-lg); padding: var(--s5); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: var(--s4); }
.card-title { font: 600 16px/1.35 var(--font-body); margin: 0; }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--s4) 0; }

/* KPI */
.kpi { display: grid; gap: 6px; }
.kpi-value { font: 500 44px/1.1 var(--font-body); letter-spacing: -0.025em; }
.kpi-value.md { font-size: 32px; }
.kpi-value.sm { font-size: 24px; letter-spacing: -0.015em; }
.kpi-delta { font-size: 14px; color: var(--text-muted); line-height: 1.45; }
.kpi-delta.up { color: var(--success); }
.kpi-delta svg { width: 14px; height: 14px; display: inline-block; vertical-align: -2px; margin-right: 4px; }
@media (max-width: 767px) { .kpi-value { font-size: 32px; } }

/* Чипы статуса — всегда со словом */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font: 500 12.5px/1 var(--font-body); white-space: nowrap; background: var(--bg-subtle); color: var(--text-subtle); }
.chip svg { width: 13px; height: 13px; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-success { background: var(--success-tint); color: var(--success); }
.chip-warning { background: var(--warning-tint); color: var(--warning); }
.chip-info { background: var(--info-tint); color: var(--info); }
.chip-danger { background: var(--danger-tint); color: var(--danger); }
.chip-accent { background: var(--accent-tint); color: var(--accent); }
.chip-value { background: var(--value-tint); color: var(--value); }
.chip-outline { background: transparent; border: 1px solid var(--border); }
.lang { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 20px; padding: 0 5px; border-radius: 6px; font: 600 11px/1 var(--font-mono); letter-spacing: 0.02em; background: var(--bg-subtle); color: var(--text-subtle); border: 1px solid var(--border); }

/* Аватары */
.avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; font: 600 13px/1 var(--font-body); background: var(--bg-subtle); color: var(--text-subtle); flex: none; position: relative; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.avatar.agent { background: var(--accent-tint); color: var(--accent); }
.avatar .ch { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface); }
.avatar .ch svg { width: 12px; height: 12px; }

/* Списки и таблицы */
.list { display: grid; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font: 500 12px/1.35 var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--d-fast) var(--ease); }
.table tbody tr:hover { background: var(--bg-subtle); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Прогресс */
.progress { height: 6px; border-radius: 999px; background: var(--bg-subtle); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

/* Уведомление-баннер */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md); background: var(--info-tint); color: var(--text); font-size: 14px; }
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--info); }
.banner.warning { background: var(--warning-tint); } .banner.warning svg { color: var(--warning); }
.banner.success { background: var(--success-tint); } .banner.success svg { color: var(--success); }
.banner.danger { background: var(--danger-tint); } .banner.danger svg { color: var(--danger); }

/* Тост */
.toast-wrap { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 14px; background: #16181A; color: #ECEAE5; box-shadow: var(--e3); font-size: 14px; animation: toast-in var(--d-base) var(--ease-enter); }
.toast svg { width: 18px; height: 18px; color: var(--toast-accent, #8CCBBB); }
.toast button { background: none; border: 0; color: var(--toast-accent, #8CCBBB); font-weight: 600; cursor: pointer; padding: 4px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Модальное окно и шит */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 900; display: grid; place-items: center; padding: 24px; animation: fade var(--d-base) var(--ease); backdrop-filter: blur(2px); }
.modal { width: min(560px, 100%); max-height: calc(100dvh - 48px); overflow: auto; background: var(--surface); border-radius: 24px; box-shadow: var(--e3); padding: 28px; animation: rise var(--d-base) var(--ease-enter); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--surface); box-shadow: var(--e3); z-index: 950; overflow: auto; animation: slide-in var(--d-slow) var(--ease-enter); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes appear { from { opacity: 0; transform: translateY(8px); } }
.appear { animation: appear var(--d-base) var(--ease-enter) both; }

/* Живой индикатор */
.live { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }
.live::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--success); opacity: 0; animation: pulse 1.8s var(--ease) infinite; }
@keyframes pulse { 0% { opacity: .6; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.6); } }
.wave { display: inline-flex; align-items: center; gap: 2px; height: 16px; }
.wave i { width: 2px; border-radius: 2px; background: currentColor; animation: wave 1s var(--ease) infinite; height: 40%; }
.wave i:nth-child(2) { animation-delay: .15s; } .wave i:nth-child(3) { animation-delay: .3s; } .wave i:nth-child(4) { animation-delay: .45s; } .wave i:nth-child(5) { animation-delay: .6s; }
@keyframes wave { 0%, 100% { height: 30%; } 50% { height: 100%; } }

/* Пустое состояние */
.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--border-control); }

/* Скелетон */
.skeleton { background: linear-gradient(90deg, var(--bg-subtle), var(--border), var(--bg-subtle)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Знак */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--accent); text-decoration: none !important; }
.brand svg { width: 28px; height: 28px; flex: none; }
.brand b { font: 600 19px/1 var(--font-body); letter-spacing: -0.024em; color: var(--accent); }
.brand b span { color: inherit; }

/* Подпись демо */
.demo-note { font-size: 12px; color: var(--text-muted); }

/* Утилиты */
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ico { width: 20px; height: 20px; flex: none; }
.ico-sm { width: 16px; height: 16px; flex: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 160ms !important; animation-iteration-count: 1 !important; transition-duration: 160ms !important; }
  .appear, .modal, .drawer, .toast { animation-name: fade !important; }
  .live::after, .wave i { animation: none !important; }
}
