:root {
  --accent: #e8590c;
  --accent-hover: #c94b08;
  --accent-soft: #fff1e6;
  --sidebar-bg: #16181d;
  --sidebar-fg: #c9ccd3;
  --sidebar-active: rgba(232, 89, 12, 0.18);
  --page-bg: #f3f4f6;
  --card-border: #e4e6eb;
  --muted: #6b7280;
  --sidebar-width: 240px;
  --bs-body-font-size: 0.9375rem;
  --bs-link-color-rgb: 194, 65, 12;
  --bs-link-hover-color-rgb: 154, 52, 18;
}

body {
  background: var(--page-bg);
  font-size: var(--bs-body-font-size);
}

[x-cloak] { display: none !important; }

.app { display: flex; min-height: 100vh; }

/* Боковое меню */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
}
/* Bootstrap делает .offcanvas-lg прозрачным на широких экранах — возвращаем тёмный фон. */
.sidebar.offcanvas-lg { background-color: var(--sidebar-bg) !important; }
@media (min-width: 992px) {
  .sidebar { position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
}
@media (max-width: 991.98px) {
  .sidebar.offcanvas-lg { --bs-offcanvas-width: 270px; background: var(--sidebar-bg); }
}
.sidebar-brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.1rem 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.brand-name { color: #fff; font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.brand-sub { color: var(--accent); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; }
.sidebar-nav { padding: 0.6rem 0.5rem; flex: 1; overflow-y: auto; }
.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 0.75rem; margin-bottom: 2px;
  color: var(--sidebar-fg); text-decoration: none; border-radius: 0.5rem;
}
.sidebar-nav .nav-item i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar-nav .nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar-nav .nav-item.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav .nav-item.active i { color: var(--accent); }
.sidebar-user {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.8rem 1rem; border-top: 1px solid rgba(255, 255, 255, 0.07); color: #fff;
}
.avatar {
  width: 2.1rem; height: 2.1rem; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.min-w-0 { min-width: 0; }

/* Верхняя панель */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.25rem; background: #fff; border-bottom: 1px solid var(--card-border);
}
.topbar-search { position: relative; flex: 1; max-width: 560px; }
.topbar-search > i { position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar-search input { padding-left: 2.3rem; background: var(--page-bg); border-color: transparent; }
.topbar-search input:focus { background: #fff; }
.search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1030;
  background: #fff; border-radius: 0.6rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  max-height: 70vh; overflow-y: auto;
}
.search-dropdown:empty { display: none; }
.search-dropdown .search-group { padding: 0.4rem 0; border-bottom: 1px solid #f0f1f3; }
.search-dropdown .search-group:last-child { border-bottom: 0; }
.search-dropdown .search-title { font-size: 0.72rem; text-transform: uppercase; color: var(--muted); padding: 0.2rem 1rem; letter-spacing: 0.05em; }
.search-dropdown a { display: block; padding: 0.45rem 1rem; color: inherit; text-decoration: none; }
.search-dropdown a:hover { background: var(--accent-soft); }

.content { padding: 1.25rem; max-width: 1500px; width: 100%; }
@media (max-width: 575.98px) {
  .content { padding: 0.85rem 0.75rem 5rem; }
  .topbar { padding: 0.5rem 0.75rem; }
  .nav-pills .nav-link { padding: 0.35rem 0.65rem; font-size: 0.9rem; }
  .page-header h1 { font-size: 1.25rem; }
}

.toast-stack { position: fixed; top: 4.2rem; right: 1rem; z-index: 1090; width: min(420px, calc(100vw - 2rem)); }

/* Кнопки и элементы */
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover, .btn-accent:focus { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-outline-accent { border-color: var(--accent); color: var(--accent); }
.btn-outline-accent:hover { background: var(--accent); color: #fff; }
.text-accent { color: var(--accent) !important; }
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: #f4a26b; box-shadow: 0 0 0 0.2rem rgba(232, 89, 12, 0.15);
}
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-label { font-weight: 500; font-size: 0.875rem; margin-bottom: 0.3rem; color: #374151; }
.nav-pills .nav-link { color: #374151; }
.nav-pills .nav-link:hover { color: var(--accent); }
.nav-pills .nav-link.active { background: var(--accent); color: #fff; }
.nav-tabs .nav-link { color: #4b5563; }
.nav-tabs .nav-link.active { color: var(--accent); font-weight: 600; }

.page-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.page-header h1 { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-header .actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.page-sub { color: var(--muted); font-size: 0.9rem; }

.card { border-color: var(--card-border); border-radius: 0.75rem; }
.card-header { background: #fff; border-bottom-color: var(--card-border); font-weight: 600; border-radius: 0.75rem 0.75rem 0 0 !important; }
.card-title-sm { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: 0.6rem 0.75rem; }
.table thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; border-bottom-width: 1px; white-space: nowrap; }
.table-hover tbody tr { cursor: default; }
.row-link { cursor: pointer; }
.card > .table-responsive > .table tr:last-child td { border-bottom: 0; }

.status-badge {
  background: color-mix(in srgb, var(--status-color) 15%, white);
  color: color-mix(in srgb, var(--status-color) 80%, black);
  border: 1px solid color-mix(in srgb, var(--status-color) 35%, white);
  font-weight: 600;
}

.stat-card { padding: 1rem 1.1rem; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-card a.stretched-link { color: inherit; }

.dl-grid { display: grid; grid-template-columns: minmax(130px, 38%) 1fr; gap: 0.35rem 1rem; margin: 0; }
.dl-grid dt { color: var(--muted); font-weight: 400; }
.dl-grid dd { margin: 0; word-break: break-word; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: 0.5rem; opacity: 0.6; }

.overdue { color: #dc3545; font-weight: 600; }

/* Доска заказов */
.board { display: flex; gap: 0.85rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.board-column { flex: 1 0 235px; max-width: 320px; background: #e9ebef; border-radius: 0.75rem; padding: 0.6rem; max-height: calc(100vh - 170px); display: flex; flex-direction: column; }
.board-column-header { display: flex; align-items: center; gap: 0.4rem; padding: 0.2rem 0.3rem 0.6rem; font-weight: 600; }
.board-column-header .dot { width: 0.65rem; height: 0.65rem; border-radius: 50%; }
.board-cards { overflow-y: auto; min-height: 3rem; display: flex; flex-direction: column; gap: 0.5rem; }
.order-card { background: #fff; border-radius: 0.6rem; padding: 0.65rem 0.75rem; border: 1px solid var(--card-border); color: inherit; text-decoration: none; display: block; }
.order-card:hover { border-color: #f4a26b; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.order-card.is-overdue { border-left: 3px solid #dc3545; }
.order-card .meta { font-size: 0.8rem; color: var(--muted); }
.sortable-ghost { opacity: 0.4; }

/* Фото */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.6rem; }
.photo-grid .photo { position: relative; border-radius: 0.5rem; overflow: hidden; background: #e9ebef; aspect-ratio: 1; }
.photo-grid .photo img { width: 100%; height: 100%; object-fit: cover; }
.photo-grid .photo .photo-caption { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 0.7rem; padding: 0.15rem 0.35rem; }
.photo-grid .photo form { position: absolute; top: 0.2rem; right: 0.2rem; }
.upload-drop { border: 2px dashed #cfd3da; border-radius: 0.75rem; padding: 1rem; text-align: center; color: var(--muted); cursor: pointer; }
.upload-drop:hover { border-color: var(--accent); color: var(--accent); }

/* Строки заказа */
.lines-table td { vertical-align: middle; }
.lines-table .line-done td { color: var(--muted); }
.lines-table .line-done .line-name { text-decoration: line-through; }
.totals { font-size: 1rem; }
.totals .total-row { font-size: 1.2rem; font-weight: 700; }

.mobile-fab { position: fixed; right: 1rem; bottom: 1rem; z-index: 1030; border-radius: 50%; width: 3.5rem; height: 3.5rem; font-size: 1.5rem; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(232, 89, 12, 0.45); }

.ts-wrapper.form-select, .ts-wrapper.form-control { padding: 0; }
.ts-control { min-height: calc(1.5em + 0.75rem + 2px); }

.settings-tile { display: flex; gap: 0.9rem; padding: 1rem; color: inherit; text-decoration: none; height: 100%; }
.settings-tile i { font-size: 1.5rem; color: var(--accent); }
.settings-tile:hover { background: var(--accent-soft); }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

/* Переписка с клиентами */
.channel-badge { font-weight: 600; color: #fff; }
.chat-card { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; }
.chat-scroll { overflow-y: auto; flex: 1; background: #f7f8fa; }
.chat-feed { display: flex; flex-direction: column; gap: 0.45rem; }
.chat-day { align-self: center; font-size: 0.75rem; color: var(--muted); background: #eceef1; border-radius: 999px; padding: 0.1rem 0.7rem; margin: 0.4rem 0; }
.chat-msg { display: flex; }
.chat-msg.is-out { justify-content: flex-end; }
.chat-bubble { max-width: min(560px, 85%); border-radius: 0.9rem; padding: 0.55rem 0.8rem; background: #fff; border: 1px solid var(--card-border); word-wrap: break-word; }
.chat-msg.is-out .chat-bubble { background: var(--accent-soft); border-color: #f8d2b5; }
.chat-msg.is-staff .chat-bubble { background: #eef4ff; border-color: #cfe0ff; }
.chat-meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.25rem; text-align: right; }
.chat-buttons { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }
.chat-button { font-size: 0.78rem; border: 1px solid #f4a26b; color: var(--accent-hover); border-radius: 0.5rem; padding: 0.1rem 0.5rem; background: #fff; }
.preview-bubble { max-width: 100%; background: var(--accent-soft); border-color: #f8d2b5; }
@media (max-width: 991.98px) { .chat-card { height: calc(100vh - 140px); } }

/* Календарь загрузки */
.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 0.85rem; align-items: start; }
@media (max-width: 1199.98px) { .calendar-layout { grid-template-columns: minmax(0, 1fr); } }
.calendar-scroll { overflow-x: auto; }
.calendar { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; min-width: 820px; }
.calendar th, .calendar td { border-bottom: 1px solid var(--card-border); border-right: 1px solid #f0f1f3; vertical-align: top; }
.calendar thead th { font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 0.55rem 0.5rem; background: #fafbfc; text-align: center; }
.calendar thead th.today { color: var(--accent); }
.calendar .cal-head-row { width: 118px; padding: 0.6rem 0.75rem; font-weight: 600; background: #fff; position: sticky; left: 0; z-index: 1; }
.calendar .closed { background: #f6f7f9; }
.cal-cell { padding: 0.4rem; }
.cal-load { height: 5px; border-radius: 3px; background: #eceef1; overflow: hidden; }
.cal-load-bar { height: 100%; background: #20c997; }
.cal-load-bar.full { background: #fd7e14; }
.cal-load-bar.over { background: #dc3545; }
.cal-hours { font-size: 0.72rem; color: var(--muted); margin: 0.15rem 0 0.3rem; }
.cal-drop { min-height: 2.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.cal-chip { display: block; font-size: 0.78rem; line-height: 1.25; padding: 0.35rem 0.45rem; border-radius: 0.45rem; background: #fff; border: 1px solid var(--card-border); border-left: 3px solid var(--status-color); color: inherit; text-decoration: none; cursor: grab; }
.cal-chip:hover { border-color: #f4a26b; border-left-color: var(--status-color); }
.cal-chip.is-overdue { box-shadow: inset 0 0 0 1px #dc3545; }
.cal-chip-sub { color: var(--muted); font-size: 0.72rem; }
.cal-queue .cal-unscheduled { padding: 0.6rem; max-height: calc(100vh - 260px); overflow-y: auto; }

/* Покупатели техники */
.lead-card { background: #fff; border-radius: 0.6rem; padding: 0.6rem 0.7rem; border: 1px solid var(--card-border); color: inherit; text-decoration: none; display: block; }
.lead-card:hover { border-color: #f4a26b; }
.lead-card.is-overdue { border-left: 3px solid #dc3545; }
.lead-card .meta { font-size: 0.78rem; color: var(--muted); }
.avatar-xs { width: 1.5rem; height: 1.5rem; font-size: 0.62rem; }
.lead-stage { color: #fff; }
.stage-new { background: #6c757d; }
.stage-contacted { background: #0d6efd; }
.stage-viewing { background: #6610f2; }
.stage-deposit { background: #fd7e14; }
.stage-won { background: #198754; }
.stage-lost { background: #adb5bd; }

/* Задачи */
.task-row.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-row.is-overdue { border-left: 3px solid #dc3545; }
.task-check { width: 2rem; height: 2rem; padding: 0; border-radius: 50%; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}
