:root {
  --app-blue: #1f3b73;
}
body { background: #f3f5f9; font-size: 1.02rem; }
.app-navbar { background: var(--app-blue); }
.login-page { background: linear-gradient(160deg, #e8eefc, #f3f5f9); min-height: 100vh; }

/* Цветные метки этапов */
.status { display: inline-block; padding: .3em .65em; border-radius: 999px; font-size: .85rem; font-weight: 600; line-height: 1.1; white-space: nowrap; color: #fff; }
.status-new { background: #0d6efd; }
.status-clarify { background: #0aa2c0; }
.status-awaiting_payment { background: #ffc107; color: #3d2f00; }
.status-paid { background: #6f42c1; }
.status-in_work { background: #fd7e14; }
.status-ready { background: #198754; }
.status-issued { background: #6c757d; }
.status-postponed { background: #8a94a6; }
.status-canceled { background: #ced4da; color: #495057; text-decoration: line-through; }

.badge-urgent { background: #dc3545; color: #fff; font-weight: 700; padding: .3em .6em; border-radius: .4rem; font-size: .8rem; letter-spacing: .02em; }

/* Карточки заказов */
.order-card { border: 0; border-left: 5px solid transparent; transition: box-shadow .15s; }
.order-card:hover { box-shadow: 0 .25rem .75rem rgba(0,0,0,.08); }
.order-card.is-urgent { border-left-color: #dc3545; }
.order-card.is-overdue .deadline { color: #dc3545; font-weight: 700; }
.order-card a.stretched-link { color: inherit; text-decoration: none; }
.order-number { font-weight: 800; font-size: 1.15rem; }

/* Главное действие */
.btn-main { font-size: 1.15rem; padding: .8rem 1.25rem; font-weight: 600; }
.main-action-bar { margin-top: 1rem; }
.main-action-bar .hint { font-size: .85rem; margin-top: .4rem; }

.filter-pills { overflow-x: auto; white-space: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.filter-pills::-webkit-scrollbar { display: none; }
.filter-pills .btn { border-radius: 999px; }

.empty-state { text-align: center; padding: 3rem 1rem; color: #6c757d; }
.empty-state .big { font-size: 3rem; line-height: 1; }

.thumb { width: 96px; height: 96px; object-fit: cover; border-radius: .5rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 800; }
.stat-card .label { color: #6c757d; font-size: .9rem; }
.money { white-space: nowrap; }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { display: block; }

@media (max-width: 575.98px) {
  main.container-lg { padding-left: 12px; padding-right: 12px; }
}

/* Таблицы на экранах < 768px — карточками */
@media (max-width: 767.98px) {
  .table-mobile-cards thead { display: none; }
  .table-mobile-cards, .table-mobile-cards tbody { display: block; width: 100%; }
  .table-mobile-cards tr { display: block; border: 1px solid #e3e7ee; border-radius: .6rem; padding: .4rem 0; margin-bottom: .6rem; background: #fff; }
  .table-mobile-cards td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 0; padding: .3rem .75rem; text-align: right; }
  .table-mobile-cards td[data-label]::before { content: attr(data-label); color: #6c757d; text-align: left; }
  .table-mobile-cards tfoot { display: block; }
}

/* Документы юрлица — по строке на документ */
.doc-name { width: 5.5rem; flex: none; }
.doc-status { flex: 1; min-width: 0; border-width: 2px; }

/* ---------- Телефон: нижняя панель, крупные элементы, кнопка действия внизу ---------- */
:root { --bottom-nav-h: 64px; --safe-bottom: env(safe-area-inset-bottom, 0px); }
html, body { overflow-x: hidden; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; background: #fff; border-top: 1px solid #dde2ea;
  padding-bottom: var(--safe-bottom); box-shadow: 0 -2px 12px rgba(20, 40, 80, .06);
}
.bottom-nav a, .bottom-nav button {
  flex: 1 1 0; min-width: 0; min-height: var(--bottom-nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #6b7380; text-decoration: none; background: none; border: 0; font-size: .74rem; line-height: 1.1;
}
.bottom-nav i { font-size: 1.45rem; line-height: 1; }
.bottom-nav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.bottom-nav .active { color: var(--app-blue); font-weight: 700; }
.bottom-nav .active i { transform: translateY(-1px); }
.more-menu { height: auto; max-height: 75vh; border-radius: 1rem 1rem 0 0; }
.more-menu .list-group-item { min-height: 52px; display: flex; align-items: center; font-size: 1.05rem; }
.more-menu .offcanvas-body { padding-bottom: calc(1rem + var(--safe-bottom)); }

@media (max-width: 767.98px) {
  /* !important — иначе .py-3 у <main> перебивает отступ и низ страницы уходит под кнопку */
  body.has-bottom-nav main { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 1.5rem) !important; }
  body.has-bottom-nav main:has(.main-action-bar) { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 110px) !important; }
  .app-navbar { padding-top: .35rem; padding-bottom: .35rem; }
  .app-navbar .navbar-brand { font-size: 1.1rem; }

  /* Главное действие экрана — закреплено над нижней панелью */
  .main-action-bar {
    position: fixed; left: 0; right: 0; z-index: 1020; margin: 0;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding: .6rem 12px; background: rgba(243, 245, 249, .96);
    backdrop-filter: blur(6px); border-top: 1px solid #e3e7ee;
  }
  body:not(.has-bottom-nav) .main-action-bar { bottom: var(--safe-bottom); }
  .main-action-bar .btn-main { padding: .7rem 1rem; }
  .main-action-bar .hint { margin-top: .3rem; }

  /* Всё, что нажимают пальцем, — не меньше 44px */
  .btn, .form-control, .form-select, .input-group-text, .nav-link, .list-group-item-action { min-height: 44px; }
  .btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
  .btn-sm, .form-control-sm, .form-select-sm { min-height: 44px; font-size: .95rem; }
  .form-control, .form-select { font-size: 16px; } /* iPhone не увеличивает страницу при вводе */
  .form-check { min-height: 44px; display: flex; align-items: center; gap: .5rem; }
  .form-check-input { width: 1.4em; height: 1.4em; margin-top: 0; flex: none; }
  .form-switch .form-check-input { width: 2.6em; }
  .form-check.form-switch { padding-left: 0; }
  .form-switch .form-check-input { margin-left: 0; }
  .btn-close { min-width: 44px; min-height: 44px; }
  .filter-pills .btn { min-height: 44px; padding-left: .9rem; padding-right: .9rem; }
  .thumb { width: 88px; height: 88px; }
  main a:not(.btn):not(.stretched-link) { padding-top: .25rem; padding-bottom: .25rem; }
}

/* Загрузка фото: две большие кнопки — камера и галерея */
.photo-pick { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.photo-pick label { margin: 0; cursor: pointer; }
.photo-pick input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photo-picked { font-size: .9rem; color: #198754; min-height: 1.2em; }

/* Кнопка установки приложения появляется, только когда браузер разрешает */
.js-install-btn[hidden], .js-install-help[hidden] { display: none !important; }
@media (display-mode: standalone) { .js-install-help { display: none !important; } }

/* Страница «Как установить» */
.install-steps svg { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto .75rem; }
.install-steps .step-num { width: 32px; height: 32px; border-radius: 50%; background: var(--app-blue); color: #fff;
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-bottom: .4rem; }

.install-tabs .nav-link { padding-left: .4rem; padding-right: .4rem; white-space: nowrap; }
@media (max-width: 767.98px) { .install-steps svg { max-width: 170px; } }

.min-w-0 { min-width: 0; }
.new-password .font-monospace { letter-spacing: .05em; }
.role-pick .btn { display: block; padding: .6rem .9rem; }
.role-pick .btn-check:checked + .btn .small { color: rgba(255,255,255,.85); }
.role-pick .btn .small { color: var(--bs-secondary-color); }

/* Шапка: название и имя пользователя в одну строку, имя обрезается */
.app-navbar > .container-lg { flex-wrap: nowrap; }
.app-navbar .navbar-brand { flex-shrink: 0; }
.app-navbar .navbar-user { min-width: 0; }
.app-navbar .navbar-nav { flex-wrap: nowrap; white-space: nowrap; }
@media (min-width: 768px) and (max-width: 1199.98px) {
  .app-navbar .navbar-nav .nav-link { padding-left: .4rem; padding-right: .4rem; }
  .app-navbar .navbar-user { max-width: 9rem; }
}

/* Логотип: белый в синей шапке, фирменного цвета на странице входа (scripts/make_icons.py) */
.app-navbar .navbar-brand { gap: .45rem; padding-top: 0; padding-bottom: 0; }
.brand-logo { height: 46px; width: auto; display: block; margin: -4px 0; }
.brand-suffix { font-weight: 600; font-size: 1rem; opacity: .9; letter-spacing: .02em; }
.login-logo { width: 193px; max-width: 60vw; height: auto; }
@media (max-width: 767.98px) { .brand-logo { height: 40px; margin: -2px 0; } }
.big-switch .form-check-input { width: 2.6em; height: 1.4em; margin-top: .1em; }
.big-switch .form-check-label { margin-left: .4rem; }

/* ---------- Сводка супер админа ---------- */
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 16px; }
.panel, .kpi, .mini-kpi { background: #fff; border-radius: .75rem; box-shadow: 0 1px 3px rgba(20, 40, 80, .08); }
.kpi, .mini-kpi { color: #343a40; text-decoration: none; transition: box-shadow .15s, transform .15s; min-width: 0; }
.kpi:hover, .kpi:focus-visible, .mini-kpi:hover, .mini-kpi:focus-visible { color: #343a40; box-shadow: 0 .4rem 1rem rgba(20, 40, 80, .12); transform: translateY(-1px); }

/* 4 денежные карточки с мини-графиком */
.money-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 16px; }
.kpi { display: flex; flex-direction: column; padding: 16px 18px 10px; }
.kpi-label, .kpi-value, .kpi-delta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-label { font-size: .9rem; color: #6c757d; line-height: 1.3; }
.kpi-value { font-size: 1.75rem; font-weight: 800; line-height: 1.25; margin: 4px 0 2px; color: #343a40; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: .85rem; font-weight: 600; line-height: 1.35; min-height: 1.35em; }
.delta-good { color: #198754; }
.delta-bad { color: #dc3545; }
.delta-muted { color: #6c757d; font-weight: 400; }
.spark { position: relative; height: 44px; margin: 6px -6px 0; }

/* остальные 4 показателя — строкой */
.mini-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.mini-kpi { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "label value" "sub sub"; align-items: baseline; column-gap: .75rem; padding: 10px 16px; }
.mini-label { grid-area: label; font-size: .9rem; color: #6c757d; white-space: nowrap; }
.mini-value { grid-area: value; justify-self: end; font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-sub { grid-area: sub; font-size: .8rem; color: #6c757d; min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chart-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: 24px 0 12px; }
.chart-toolbar .filter-pills { padding-bottom: 0; }

.dash-charts { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: stretch; }
.dash-bottom { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; margin-top: 16px; }
.panel { display: flex; flex-direction: column; min-width: 0; padding: 16px 18px; }
.panel-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .5rem; font-size: 1.1rem; font-weight: 700; margin: 0 0 10px; }
.panel-note { font-size: .8rem; font-weight: 400; color: #6c757d; }
.panel-count { font-size: .8rem; font-weight: 700; color: #6c757d; background: #eef0f4; border-radius: 999px; padding: .1rem .55rem; }
.panel-empty { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 140px; color: #198754; font-size: 1.1rem; font-weight: 600; text-align: center; }

.chart-box { position: relative; flex: 1; min-height: 220px; }
.chart-box-lg { height: 300px; }
.chart-box-donut { height: 300px; }
.chart-box-workers { min-height: 180px; flex: none; }
.chart-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  color: #6c757d; font-size: .95rem; font-weight: 600;
}
.chart-empty[hidden] { display: none; }
.chart-box-donut .chart-empty { padding-bottom: 0; }

/* «Требует внимания» */
.att-list { list-style: none; margin: 0; padding: 0; }
.att-row {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "tag num right" "what what what";
  align-items: center; column-gap: 8px; row-gap: 2px; padding: 8px 0; border-top: 1px solid #eef0f4; color: inherit; text-decoration: none;
}
.att-list li:first-child .att-row { border-top: 0; }
.att-row:hover .att-what { text-decoration: underline; }
.att-tag { grid-area: tag; font-size: .75rem; font-weight: 700; text-align: center; border-radius: 999px; padding: .15rem .5rem; white-space: nowrap; }
.att-danger { background: #fde2e4; color: #b02a37; }
.att-urgent { background: #ffe5d0; color: #a14a00; }
.att-primary { background: #dbe7ff; color: #1f4fbf; }
.att-secondary { background: #eceef2; color: #495057; }
.att-num { grid-area: num; font-weight: 800; }
.att-what { grid-area: what; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.att-right { grid-area: right; text-align: right; white-space: nowrap; color: #6c757d; font-size: .85rem; }

@media (max-width: 1199.98px) {
  .money-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-charts { grid-template-columns: 1fr; }
  .dash-bottom { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-attention { grid-column: 1 / -1; }
  /* на всю ширину «Требует внимания» читается одной строкой */
  .panel-attention .att-row { grid-template-columns: 8.2rem auto minmax(0, 1fr) auto; grid-template-areas: "tag num what right"; }
}
@media (max-width: 991.98px) {
  .mini-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-kpis > :last-child { grid-column: 1 / -1; }  /* 5-я карточка на всю ширину — сетка ровная */
}
@media (max-width: 767.98px) {
  .dash-head { margin-bottom: 12px; }
  .money-kpis, .mini-kpis { gap: 10px; }
  .mini-kpis { margin-top: 10px; }
  .kpi { padding: 12px 12px 8px; border-radius: .65rem; }
  .kpi-label { font-size: .8rem; }
  .kpi-value { font-size: 1.3rem; margin: 2px 0 1px; }
  .kpi-delta { font-size: .75rem; }
  .spark { height: 34px; margin-top: 4px; }
  .mini-kpi { padding: 8px 12px; }
  .mini-label { font-size: .8rem; }
  .mini-value { font-size: 1.1rem; }
  .mini-sub { font-size: .72rem; }
  .chart-toolbar { margin: 18px 0 10px; }
  .dash-charts, .dash-bottom { gap: 12px; }
  .dash-bottom { grid-template-columns: 1fr; margin-top: 12px; }
  .panel { padding: 14px 14px; }
  .chart-box-lg { height: 240px; }
  .chart-box-donut { height: 260px; }
  main a.kpi { padding-top: 12px; padding-bottom: 8px; }
  main a.mini-kpi { padding-top: 8px; padding-bottom: 8px; }
  main a.att-row { padding-top: 10px; padding-bottom: 10px; }
}
@media (max-width: 575.98px) {
  .panel-attention .att-row { grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "tag num right" "what what what"; }
}

/* Отчёт «Ждут оплаты»: до 992px — карточками (колонок много), кнопки на всю ширину */
@media (max-width: 991.98px) {
  .awaiting-table thead { display: none; }
  .awaiting-table, .awaiting-table tbody { display: block; width: 100%; }
  .awaiting-table tr { display: block; border: 1px solid #e3e7ee; border-radius: .6rem; padding: .4rem 0; margin-bottom: .6rem; background: #fff; }
  .awaiting-table td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 0; padding: .3rem .75rem; text-align: right; }
  .awaiting-table td[data-label]::before { content: attr(data-label); color: #6c757d; text-align: left; flex: none; }
  .table-mobile-cards td.awaiting-actions, .awaiting-table td.awaiting-actions { display: block; text-align: center; padding-top: .5rem; }
}
@media (min-width: 992px) { .awaiting-actions { width: 13rem; } }
.client-suggest { position: absolute; left: 0; right: 0; z-index: 20; margin-top: -0.5rem; max-height: 320px; overflow-y: auto; }
.client-suggest .list-group-item { min-height: 44px; }

/* Список «Заявки» + панель заказа справа */
.order-list .order-row { border-left: 5px solid transparent; padding: .6rem .9rem; }
.order-list .order-row.is-urgent { border-left-color: #dc3545; }
.order-list .order-row.is-overdue .deadline { color: #dc3545; font-weight: 700; }
.order-list .order-row.active-row { background: #e8f0fe; border-left-color: #0d6efd; }
.order-list .order-row.active-row.is-urgent { border-left-color: #dc3545; }
.order-list .order-desc { max-width: 100%; }
.order-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
.order-panel-empty { border: 2px dashed #dee2e6; border-radius: .5rem; padding: 2.5rem 1.5rem; }
.order-panel.htmx-request { opacity: .6; transition: opacity .15s; }
@media (max-width: 767.98px) {
  .order-list .order-row { min-height: 44px; }
}

/* Видеоинструкция */
.help-video { display: block; width: 100%; max-height: 78vh; background: #000; border-radius: .5rem; }
.help-video.is-vertical { width: auto; max-width: 100%; margin: 0 auto; }
.help-link { white-space: nowrap; }
