/* ==========================================================================
   OSAGO Workspace — Design System
   Единые токены и компоненты. Подключается ПОСЛЕ Bootstrap 5.
   ========================================================================== */

:root {
  /* Поверхности и текст */
  --c-bg: #f1f5f9;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-border: #e2e8f0;
  --c-text: #0f172a;
  --c-text-2: #475569;
  --c-muted: #94a3b8;

  /* Семантика действий */
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-success: #16a34a;
  --c-warning: #d97706;
  --c-danger: #dc2626;
  --c-info: #0891b2;

  /* Финансовые потоки — НЕ смешивать визуально */
  --c-cash: #15803d;         /* наличные, принятые сотрудником */
  --c-cash-soft: #ecfdf3;
  --c-noncash: #1d4ed8;      /* СБП / безнал на р/с */
  --c-noncash-soft: #eff4ff;
  --c-client-card: #64748b;  /* карта клиента — не наши деньги */
  --c-client-card-soft: #f1f5f9;
  --c-reward: #7c3aed;       /* вознаграждение сотрудника */
  --c-reward-soft: #f5f3ff;
  --c-owner-card: #b45309;   /* списание с нашей карты (расход владельца) */

  /* Sidebar */
  --c-sidebar: #0f172a;
  --c-sidebar-2: #1e293b;
  --c-sidebar-text: #94a3b8;
  --c-sidebar-active-bg: rgba(37, 99, 235, 0.16);
  --c-sidebar-active-text: #ffffff;

  /* Геометрия */
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --sidebar-width: 248px;
  --topbar-height: 60px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Layout: sidebar + topbar + content
   ========================================================================== */
.app-layout { display: flex; min-height: 100vh; }

.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--c-sidebar);
  color: var(--c-sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1030;
}

.app-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-height);
  padding: 0 20px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}
.app-brand .brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--c-primary);
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}

.app-nav { flex: 1; overflow-y: auto; padding: 12px 12px 24px; }
.app-nav-section { margin-bottom: 18px; }
.app-nav-title {
  padding: 0 12px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.7);
}
.app-nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--c-sidebar-text);
  text-decoration: none;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background .12s, color .12s;
}
.app-nav-link i { font-size: 16px; width: 18px; text-align: center; flex: 0 0 auto; }
.app-nav-link:hover { background: var(--c-sidebar-2); color: #fff; }
.app-nav-link.active { background: var(--c-sidebar-active-bg); color: var(--c-sidebar-active-text); }
.app-nav-link .nav-badge {
  margin-left: auto;
  background: var(--c-danger);
  color: #fff; font-size: 11px; font-weight: 600;
  border-radius: 999px; padding: 1px 7px;
}

.app-sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px 16px;
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  position: sticky; top: 0; z-index: 1020;
  height: var(--topbar-height);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
}
.app-hamburger { font-size: 20px; color: var(--c-text-2); padding: 6px 8px; }
.app-topbar-title { font-weight: 600; font-size: 15px; color: var(--c-text); }
.app-topbar-spacer { flex: 1; }
.app-topbar-user { display: flex; align-items: center; gap: 10px; }
.app-topbar-user .user-name { font-weight: 500; color: var(--c-text); }

.app-content { padding: 24px; flex: 1; }

/* Offcanvas (mobile nav) */
.app-offcanvas {
  background: var(--c-sidebar);
  color: var(--c-sidebar-text);
  width: var(--sidebar-width) !important;
}

/* Auth (login) layout */
.auth-body { background: var(--c-bg); }
.auth-content {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; }

/* ==========================================================================
   Page header
   ========================================================================== */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header-title { display: flex; align-items: center; gap: 12px; }
.page-header-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--c-primary); font-size: 19px;
  flex: 0 0 auto;
}
.page-title { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.2; }
.page-subtitle { margin: 2px 0 0; color: var(--c-muted); font-size: 13px; }
.page-header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--c-surface);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--c-border);
  padding: 14px 18px;
  font-weight: 600;
  color: var(--c-text);
}
.card-body { padding: 18px; }

/* ==========================================================================
   Stat cards
   ========================================================================== */
.stat-grid { display: grid; gap: 14px; }
.stat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--c-muted);
}
.stat-label { font-size: 12.5px; font-weight: 500; color: var(--c-text-2); }
.stat-value { font-size: 22px; font-weight: 700; color: var(--c-text); line-height: 1.1; }
.stat-card .stat-icon {
  position: absolute; right: 14px; top: 14px;
  font-size: 18px; color: var(--c-muted); opacity: .5;
}

.tone-cash::before { background: var(--c-cash); }
.tone-cash .stat-value { color: var(--c-cash); }
.tone-noncash::before { background: var(--c-noncash); }
.tone-noncash .stat-value { color: var(--c-noncash); }
.tone-client-card::before { background: var(--c-client-card); }
.tone-client-card .stat-value { color: var(--c-client-card); }
.tone-reward::before { background: var(--c-reward); }
.tone-reward .stat-value { color: var(--c-reward); }
.tone-owner-card::before { background: var(--c-owner-card); }
.tone-owner-card .stat-value { color: var(--c-owner-card); }
.tone-success::before { background: var(--c-success); }
.tone-success .stat-value { color: var(--c-success); }
.tone-warning::before { background: var(--c-warning); }
.tone-warning .stat-value { color: var(--c-warning); }
.tone-danger::before { background: var(--c-danger); }
.tone-danger .stat-value { color: var(--c-danger); }
.tone-primary::before { background: var(--c-primary); }
.tone-primary .stat-value { color: var(--c-primary); }
.tone-neutral::before { background: var(--c-muted); }

/* Кликабельная стат-карточка (открывает модалку) */
.stat-card-link { display: block; height: 100%; color: inherit; }
.stat-card-link .stat-card {
  height: 100%;
  cursor: pointer;
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.stat-card-link:hover .stat-card {
  border-color: var(--c-primary);
  box-shadow: 0 6px 16px rgba(15, 23, 42, .10);
  transform: translateY(-2px);
}
.stat-card-link:hover { color: inherit; }

/* ==========================================================================
   Money
   ========================================================================== */
.money {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.money-dec { opacity: .55; }
.money-cur { opacity: .7; font-weight: 500; }
.text-end .money, .stat-value .money { }

/* ==========================================================================
   Badges (статусы)
   ========================================================================== */
.badge-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge-status i { font-size: 12px; }
.badge-status-success { background: #e7f6ec; color: #15803d; }
.badge-status-warning { background: #fef3e2; color: #b45309; }
.badge-status-danger  { background: #fdeaea; color: #b91c1c; }
.badge-status-neutral { background: #eef2f6; color: #475569; }
.badge-status-info    { background: #e6f4f7; color: #0e7490; }
.badge-status-primary { background: #e8effd; color: #1d4ed8; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.app-table { margin-bottom: 0; }
.app-table thead th {
  background: var(--c-surface-2);
  color: var(--c-text-2);
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em;
  border-bottom: 1px solid var(--c-border);
  padding: 10px 14px;
  white-space: nowrap;
}
.app-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.app-table tbody tr:last-child td { border-bottom: none; }
.app-table tbody tr:hover td { background: var(--c-surface-2); }
.app-table tfoot td {
  background: var(--c-surface-2);
  border-top: 1px solid var(--c-border);
  font-weight: 600;
  padding: 11px 14px;
}
.num { font-variant-numeric: tabular-nums; }

/* Финансовые ячейки (цветовое кодирование потоков) */
.t-cash { color: var(--c-cash); }
.t-noncash { color: var(--c-noncash); }
.t-client-card { color: var(--c-client-card); }
.t-reward { color: var(--c-reward); }
.t-owner-card { color: var(--c-owner-card); }
.sc-received-cell { background: #f0f6ff; }
.sc-received-head { background: #e7f0ff !important; }

/* Группирующая шапка «НАЛ за смену» — выделение цветом наличных */
.app-table thead th.th-cash-group {
  background: var(--c-cash-soft);
  color: var(--c-cash);
}

/* Группирующая шапка «Оплата за продукт» — синий (безнал) */
.app-table thead th.th-group-product {
  background: var(--c-noncash-soft);
  color: var(--c-noncash);
}

/* Группирующая шапка «Оплата услуги» — зелёный (наш доход/наличные) */
.app-table thead th.th-group-service {
  background: var(--c-cash-soft);
  color: var(--c-cash);
}

/* Вертикальные границы в шапке таблицы */
.app-table-vborders thead th {
  border-left: 1px solid var(--c-border);
  border-right: 1px solid var(--c-border);
}

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--c-muted);
}
.empty-state-icon { font-size: 40px; display: block; margin-bottom: 10px; opacity: .6; }
.empty-state-text { margin: 0 0 14px; color: var(--c-text-2); }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-label { font-weight: 500; color: var(--c-text-2); font-size: 13px; margin-bottom: 5px; }
.form-control, .form-select {
  border-color: var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
.input-group-text { background: var(--c-surface-2); border-color: var(--c-border); color: var(--c-text-2); }
.form-text { color: var(--c-muted); }
.form-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  border-top: 1px solid var(--c-border);
  padding-top: 16px; margin-top: 8px;
}
.form-section-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--c-muted);
  margin: 20px 0 10px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn { border-radius: var(--radius-sm); font-weight: 500; font-size: 14px; }
.btn:focus-visible { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3); }
.btn-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { --bs-btn-bg: var(--c-primary); --bs-btn-border-color: var(--c-primary); --bs-btn-hover-bg: var(--c-primary-hover); --bs-btn-hover-border-color: var(--c-primary-hover); --bs-btn-active-bg: #1e40af; --bs-btn-active-border-color: #1e40af; }
.btn-success { --bs-btn-bg: var(--c-success); --bs-btn-border-color: var(--c-success); --bs-btn-hover-bg: #15803d; --bs-btn-hover-border-color: #15803d; }
.btn-danger  { --bs-btn-bg: var(--c-danger); --bs-btn-border-color: var(--c-danger); --bs-btn-hover-bg: #b91c1c; --bs-btn-hover-border-color: #b91c1c; }
.btn-warning { --bs-btn-bg: var(--c-warning); --bs-btn-border-color: var(--c-warning); --bs-btn-hover-bg: #b45309; --bs-btn-hover-border-color: #b45309; color: #fff; }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--c-border); --bs-btn-color: var(--c-text); --bs-btn-hover-bg: var(--c-surface-2); --bs-btn-hover-border-color: var(--c-border); --bs-btn-hover-color: var(--c-text); }
.btn-outline-secondary { --bs-btn-border-color: var(--c-border); --bs-btn-color: var(--c-text-2); --bs-btn-hover-bg: var(--c-surface-2); --bs-btn-hover-color: var(--c-text); --bs-btn-hover-border-color: var(--c-border); --bs-btn-active-bg: var(--c-surface-2); }
.btn[disabled], .btn.disabled { opacity: .55; }
.btn-loading .bi, .btn-loading i { display: none; }

/* ==========================================================================
   Flash / alerts
   ========================================================================== */
.app-alert {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-info);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 11px 14px;
  margin-bottom: 12px;
}
.app-alert i { font-size: 16px; }
.app-alert-success { border-left-color: var(--c-success); }
.app-alert-success i { color: var(--c-success); }
.app-alert-danger  { border-left-color: var(--c-danger); }
.app-alert-danger i { color: var(--c-danger); }
.app-alert-warning { border-left-color: var(--c-warning); }
.app-alert-warning i { color: var(--c-warning); }
.app-alert-info    { border-left-color: var(--c-info); }
.app-alert-info i { color: var(--c-info); }
.app-alert .btn-close { margin-left: auto; }

/* ==========================================================================
   Avatar / timeline / misc
   ========================================================================== */
.avatar-circle {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--c-primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  flex: 0 0 auto;
}
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--c-border); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before {
  content: ""; position: absolute; left: -24px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-primary); border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--c-border);
}
.timeline-item.event-created::before { background: var(--c-success); }
.timeline-item.event-updated::before { background: var(--c-info); }
.timeline-item.event-cancelled::before { background: var(--c-danger); }
.timeline-item.event-confirmation::before { background: var(--c-warning); }

.divider { border-top: 1px solid var(--c-border); margin: 18px 0; }

.section-title {
  font-size: 13px; font-weight: 600; color: var(--c-text);
  margin: 0 0 12px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 991.98px) {
  .app-main { margin-left: 0; }
  .app-content { padding: 16px; }
  .app-topbar { padding: 0 16px; }
}

@media (max-width: 575.98px) {
  .app-content { padding: 12px; }
  .page-title { font-size: 18px; }
  .stat-value { font-size: 19px; }
  .app-topbar-user .user-name { display: none; }
}

/* Mobile card list (для важных таблиц) */
.mobile-list { display: none; }
@media (max-width: 767.98px) {
  .mobile-list { display: block; }
  .mobile-list + .table-card.d-none-md { display: none !important; }
}

/* ==========================================================================
   Финансовые потоки (тайлы на странице смены)
   ========================================================================== */
.flow-tile {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  height: 100%;
}
.flow-tile-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--c-text-2); margin-bottom: 6px;
}
.flow-tile .d-flex.small { font-size: 12.5px; color: var(--c-text-2); }
.flow-tile-total { font-size: 18px; font-weight: 700; margin-top: 8px; line-height: 1.15; }
.flow-tile-cash { background: var(--c-cash-soft); border-color: rgba(21, 128, 61, 0.25); }
.flow-tile-cash .flow-tile-label { color: var(--c-cash); }
.flow-tile-cash .flow-tile-total { font-size: 22px; }

/* ==========================================================================
   Операция (услуга): форма и карточки — крупный ввод, чёткие границы, компактно
   ========================================================================== */
.op-card .card-header { font-size: 15px; }
.op-subtitle {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--c-text-2);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--c-border);
}
.op-card .form-label { font-size: 14px; font-weight: 600; color: var(--c-text-2); }
.op-card .form-control,
.op-card .form-select {
  font-size: 16px;
  border: 1.5px solid var(--c-border);
  min-height: 44px;
}
.op-card .form-control:focus,
.op-card .form-select:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.op-plaintext {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  min-height: 42px;
}
.op-calc {
  background: #f8fafc;
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

/* Аккордеон: кликабельный заголовок карточки + поворот шеврона */
.collapse-toggle { cursor: pointer; user-select: none; }
.collapse-toggle .collapse-chevron { transition: transform .2s ease; }
.collapse-toggle[aria-expanded="true"] .collapse-chevron { transform: rotate(180deg); }
