/* ui.css — app-wide look (same visual language as the warranty_requests redesign).
   Loaded on every page after Bootstrap. Restyles the shared building blocks pages already use
   (DataTables, .tile-card, Bootstrap tables/forms/buttons/modals) and adds .ui-* components
   for page headers, panels and badges. */
:root {
  --ui-navy: #203f66;
  --ui-blue: #1673f9;
  --ui-blue-dark: #155fc2;
  --ui-ink: #243247;
  --ui-title: #203650;
  --ui-muted: #718096;
  --ui-line: #e3e9f0;
  --ui-line-soft: #edf1f5;
  --ui-head-bg: #f2f5f9;
  --ui-red: #dc3545;
  --ui-amber: #b77908;
  --ui-green: #198754;
  --ui-shadow: 0 3px 12px rgba(23, 52, 82, .055);
  --ui-radius: 11px;

  /* DataTables paints stripes/hover as a translucent overlay of these colours (5% / 7.5%) */
  --dt-row-stripe: 70, 100, 140;
  --dt-row-hover: 22, 115, 249;

  /* Bootstrap theme hooks */
  --bs-primary: #1673f9;
  --bs-primary-rgb: 22, 115, 249;
  --bs-link-color: #1673f9;
  --bs-link-color-rgb: 22, 115, 249;
  --bs-border-radius: 6px;
}

/* ---------- Page layout ---------- */
.app-container { max-width: 1800px; padding: 22px 24px 40px; }
.app-content { color: var(--ui-ink); }
/* Accounting tables used a serif face for client columns; keep everything in the UI font */
.app-content th,
.app-content td { font-family: var(--font-sans); }

/* ---------- Page header: title + subtitle left, main actions right ---------- */
.ui-pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.ui-pagehead h1 {
  font-size: 21px;
  line-height: 1.25;
  margin: 0;
  font-weight: 650;
  color: var(--ui-title);
}
.ui-subtitle { font-size: 12px; color: var(--ui-muted); margin-top: 5px; }
.ui-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Panels (and the older .tile-card, restyled to match) ---------- */
.ui-panel,
.tile-card {
  background: #fff;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.ui-panel-title,
.tile-card > h3:first-child,
.tile-card > .d-flex:first-child h3 {
  font-size: 15px;
  font-weight: 700;
  color: #273b52;
}

/* Two panels side by side (stacks on narrow screens) */
.ui-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.ui-grid-2 > .tile-card,
.ui-grid-2 > .ui-panel { margin-bottom: 0; }
@media (max-width: 991.98px) { .ui-grid-2 { grid-template-columns: 1fr; } }

/* Collapsible explanation ("how does this work?") */
.ui-help { padding: 0; }
.ui-help > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #1a4f9c;
}
.ui-help > summary::-webkit-details-marker { display: none; }
.ui-help > summary::before { content: "ⓘ  "; }
.ui-help[open] > summary { border-bottom: 1px solid var(--ui-line-soft); }
.ui-help-body { padding: 12px 18px 4px; font-size: 13px; color: #4a5a6e; }
.ui-help-body p { margin-bottom: 8px; }

/* ---------- Bootstrap cards, list groups, tabs (route optimizer, dashboards) ---------- */
.app-content .card {
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
}
.app-content .card-header { background: #f7f9fc; border-bottom-color: var(--ui-line); font-weight: 600; color: #273b52; }
.app-content .list-group-item.active { background: var(--ui-blue); border-color: var(--ui-blue); }
/* Tabs as a segmented control: every tab is visibly a tab inside one grey track; the active one is a raised white pill */
.app-content .nav-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: #e3e9f1;
  border: 1px solid #d6dfea;
  border-radius: 10px;
}
.app-content .nav-tabs .nav-item { margin: 0; }
.app-content .nav-tabs .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 7px 16px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #4a5a6e;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  transition: background .15s, color .15s, box-shadow .15s;
}
.app-content .nav-tabs .nav-link:hover:not(.active) { background: rgba(255, 255, 255, .6); color: var(--ui-title); }
.app-content .nav-tabs .nav-link:focus-visible { outline: 2px solid #83b5ff; outline-offset: 1px; }
.app-content .nav-tabs .nav-link.active {
  background: #fff;
  color: var(--ui-blue-dark);
  box-shadow: 0 1px 3px rgba(23, 52, 82, .14), 0 0 0 1px rgba(23, 52, 82, .05);
}
@media (max-width: 600px) {
  .app-content .nav-tabs { display: flex; }
  .app-content .nav-tabs .nav-item { flex: 1 1 auto; }
  .app-content .nav-tabs .nav-link { width: 100%; justify-content: center; padding: 7px 10px; }
}

/* ---------- Import / upload card (upload*.php, import_clients.php) ---------- */
.uploader-card {
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  box-shadow: var(--ui-shadow);
  margin-top: 24px;
}
.uploader-title { color: var(--ui-title); font-size: 21px; font-weight: 650; }
.uploader-subtitle { color: var(--ui-muted); font-size: 13px; }
.dropzone { border-radius: 10px; border-color: #c9d6e6; background: #f8fafd; }
.btn-import { background: var(--ui-blue); border-radius: 6px; padding: 10px 18px; }
.btn-import:hover { background: var(--ui-blue-dark); }

/* ---------- Summary metric cards ---------- */
.ui-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.ui-metric {
  position: relative;
  background: #fff;
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  box-shadow: var(--ui-shadow);
  padding: 14px 15px 13px;
  overflow: hidden;
}
.ui-metric::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: #cad5e2; }
.ui-metric.blue::before { background: var(--ui-blue); }
.ui-metric.red::before { background: #e05260; }
.ui-metric.amber::before { background: #e8ad24; }
.ui-metric.green::before { background: var(--ui-green); }
.ui-metric-label { font-size: 12px; color: #69788b; }
.ui-metric-value { font-size: 20px; font-weight: 700; color: var(--ui-title); font-variant-numeric: tabular-nums; margin-top: 4px; }
.ui-metric-foot { font-size: 11px; color: #8994a3; margin-top: 4px; }

/* ---------- Row actions: "Акции ▾" button + menu (actions_dropdown() in includes/functions.php) ---------- */
.ui-dd { display: inline-block; }
.ui-dd-toggle,
.wr .wr-action {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  color: #42546a;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.ui-dd-toggle:hover,
.ui-dd-toggle[aria-expanded="true"] { background: #f4f7fb; border-color: #9fb3c8; color: var(--ui-title); }

/* All dropdown menus */
.dropdown-menu {
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(19, 43, 69, .16);
  padding: 6px;
  font-size: 13px;
  min-width: 190px;
}
.dropdown-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 6px;
  padding: 7px 10px;
  color: #334155;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
}
.dropdown-menu .dropdown-item > .bi { font-size: 15px; width: 16px; text-align: center; color: #64748b; }
.dropdown-menu .dropdown-item:hover,
.dropdown-menu .dropdown-item:focus { background: #f0f6ff; color: var(--ui-title); }
.dropdown-menu .dropdown-item:hover > .bi { color: var(--ui-blue); }
.dropdown-menu .dropdown-item.text-danger,
.dropdown-menu .dropdown-item.text-danger > .bi { color: var(--ui-red) !important; }
.dropdown-menu .dropdown-item.text-danger:hover { background: #fff1f2; }
.dropdown-menu .dropdown-divider { margin: 5px 4px; border-color: var(--ui-line-soft); }
.dropdown-menu form { margin: 0; }

/* ---------- Avatars (photo or initial; see avatar_html() in includes/auth.php) ---------- */
.avatar-img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.sb-avatar, .hm-avatar, .profile-avatar, .ui-avatar-sm { overflow: hidden; }
.ui-avatar-sm {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: 10px;
  vertical-align: middle;
  border-radius: 50%;
  background: linear-gradient(135deg, #1673f9, #203f66);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

/* ---------- Badges ---------- */
.ui-badge { display: inline-flex; align-items: center; border-radius: 5px; padding: 4px 7px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.ui-badge-blue { background: #e8f1ff; color: #175bb4; }
.ui-badge-red { background: #fff1f2; color: #c62c3b; }
.ui-badge-green { background: #eaf8f0; color: #137547; }
.ui-badge-amber { background: #fff8e6; color: var(--ui-amber); }
.ui-badge-grey { background: #eef1f5; color: #5e6b79; }

/* ---------- Buttons ---------- */
.btn { border-radius: 6px; font-weight: 500; }
.btn-primary { --bs-btn-bg: #1673f9; --bs-btn-border-color: #1673f9; --bs-btn-hover-bg: #155fc2; --bs-btn-hover-border-color: #155fc2; --bs-btn-active-bg: #124f9f; --bs-btn-active-border-color: #124f9f; font-weight: 600; }
.btn-outline-primary { --bs-btn-color: #1673f9; --bs-btn-border-color: #9cc3ff; --bs-btn-hover-bg: #1673f9; --bs-btn-hover-border-color: #1673f9; }
.btn-outline-secondary { --bs-btn-color: #334155; --bs-btn-border-color: #d8e0e9; --bs-btn-hover-bg: #f4f7fb; --bs-btn-hover-color: #1f2937; --bs-btn-hover-border-color: #c7d2de; }

/* ---------- Forms ---------- */
.app-content .form-label { font-size: 12px; font-weight: 600; color: #536174; margin-bottom: 6px; }
.app-content .form-control,
.app-content .form-select { border-color: #d5dee8; border-radius: 6px; }
.app-content .form-control:focus,
.app-content .form-select:focus { border-color: #83b5ff; box-shadow: 0 0 0 3px rgba(22, 115, 249, .1); }

/* ---------- Modals ---------- */
.modal-content { border: 0; border-radius: 12px; box-shadow: 0 18px 50px rgba(19, 43, 69, .22); overflow: hidden; }
.modal-header { background: #f7f9fc; border-bottom: 1px solid var(--ui-line); padding: 14px 20px; }
.modal-title { font-size: 16px; font-weight: 700; color: var(--ui-title); }
.modal-footer { border-top: 1px solid var(--ui-line); background: #fbfcfe; }

/* ---------- Alerts ---------- */
.app-content .alert { border-radius: 9px; border-width: 1px; font-size: 14px; }

/* ---------- Tables: every DataTables table becomes a panel (like the declarations table) ---------- */
.app-content .dt-container {
  background: #fff;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
  padding: 14px 18px 12px;
  margin-bottom: 18px;
  font-size: 13px;
}
/* Already inside a panel/card, or on the page that styles its own table: no second frame */
.app-content .tile-card .dt-container,
.app-content .ui-panel .dt-container,
.app-content .modal .dt-container,
.wr .dt-container {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin-bottom: 0;
}
/* Wide tables scroll sideways inside their panel (not the whole page/panel) */
.app-content .table-responsive:has(> .dt-container),
.app-content .table-responsivessd:has(> .dt-container) { overflow: visible; }
.app-content .dt-container .dt-layout-row.dt-layout-table { overflow-x: auto; }
.app-content .dt-container .dt-layout-row { margin: 0 0 10px; }
.app-content .dt-container .dt-layout-row.dt-layout-table { margin: 0 -18px 0; }
.app-content .tile-card .dt-container .dt-layout-row.dt-layout-table,
.app-content .ui-panel .dt-container .dt-layout-row.dt-layout-table { margin: 0; }
.app-content .dt-container .dt-layout-row:last-child { margin: 10px 0 0; }

/* Length / search / info / paging */
.app-content .dt-length,
.app-content .dt-search,
.app-content .dt-info { color: #657387; font-size: 12px; }
.app-content .dt-length select,
.app-content .dt-search input {
  height: 34px;
  border: 1px solid #d5dee8;
  border-radius: 6px;
  font-size: 13px;
}
.app-content .dt-search input { min-width: 220px; }
.app-content .dt-paging .pagination { margin: 0; }
.app-content .dt-paging .page-link { font-size: 12px; padding: 5px 10px; color: #536174; border-color: #dce4ed; }
.app-content .dt-paging .page-item.active .page-link { background: var(--ui-blue); border-color: var(--ui-blue); color: #fff; }

/* Export buttons */
.app-content .dt-buttons { display: inline-flex; flex-wrap: wrap; gap: 8px; }
.app-content .dt-buttons .btn {
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 6px !important;
  color: #334155;
  background: #fff !important;
  border: 1px solid #d8e0e9 !important;
}
.app-content .dt-buttons .btn:hover { background: #f4f7fb !important; }

/* Table head + rows */
.app-content table.dataTable,
.app-content .ui-panel table.table,
.app-content .tile-card table.table {
  --bs-table-striped-bg: #fbfcfe;
  --bs-table-hover-bg: #f0f6ff;
  font-size: 12.5px;
}
.app-content table.dataTable thead th,
.app-content .ui-panel table.table thead th,
.app-content .tile-card table.table thead th {
  background: var(--ui-head-bg) !important;
  color: #58687b;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: .25px;
  padding: 12px 10px !important;
  border-bottom: 1px solid #dce4ed !important;
  vertical-align: bottom;
}
/* scrollX tables repeat the header inside the scroll body as an invisible sizing row: keep it zero-height */
.app-content .dt-scroll-body table.dataTable thead th,
.app-content .dt-scroll-body table.dataTable thead td {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-bottom-width: 0 !important;
}
.app-content table.dataTable tbody td,
.app-content .ui-panel table.table tbody td,
.app-content .tile-card table.table tbody td {
  padding: 10px !important;
  border-bottom: 1px solid var(--ui-line-soft) !important;
  vertical-align: middle;
}
.app-content table.dataTable tbody tr:hover > * { --bs-table-bg-state: #f0f6ff; }
.app-content table.dataTable.table-bordered,
.app-content table.dataTable.table-bordered > :not(caption) > * > * { border-left: 0; border-right: 0; }

/* Totals header rows used on several pages */
.app-content table.dataTable thead tr.dt-totals-row th {
  background: var(--ui-navy) !important;
  color: #fff;
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}

@media (max-width: 800px) {
  .app-container { padding: 14px 12px 30px; }
  .ui-pagehead h1 { font-size: 18px; }
  .app-content .dt-search input { min-width: 0; width: 100%; }
}

@media print {
  .app-content .dt-container { border: 0; box-shadow: none; padding: 0; }
  .ui-actions { display: none !important; }
}
