/* ==========================================================
   1. Змінні (палітра, розміри) — міняйте кольори тут
   ========================================================== */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --border: #e7e2d8;
  --text: #1f2933;
  --muted: #6b7280;

  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #d9f2ee;

  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --neutral: #475569;
  --neutral-soft: #e8ecf1;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;

  --sidebar-w: 250px;
  --topbar-h: 64px;
  --radius: 14px;

  /* Перевизначення Bootstrap */
  --bs-primary: var(--accent);
  --bs-primary-rgb: 15, 118, 110;
  --bs-body-font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bs-body-color: var(--text);
  --bs-body-bg: var(--bg);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-dark);
}

/* ==========================================================
   2. Базові стилі та елементи Bootstrap
   ========================================================== */
body { background: var(--bg); color: var(--text); }

.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-dark);
  --bs-btn-hover-border-color: var(--accent-dark);
  --bs-btn-active-bg: var(--accent-dark);
  --bs-btn-active-border-color: var(--accent-dark);
  --bs-btn-focus-shadow-rgb: 15, 118, 110;
  font-weight: 600;
  border-radius: 10px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  font-weight: 600;
}
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent-dark); }

.form-control {
  border-radius: 10px;
  border-color: var(--border);
  padding: .6rem .85rem;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 .2rem rgba(15, 118, 110, .15);
}

/* ==========================================================
   3. Каркас: сайдбар, верхня панель, контент
   ========================================================== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex; flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
  overflow-y: auto;               /* на низьких екранах меню прокручується */
  overscroll-behavior: contain;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 24px;
  font-weight: 800; font-size: 1.1rem; color: var(--text);
}
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 1.1rem;
}

.menu { display: flex; flex-direction: column; gap: 4px; }
.menu-link {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.menu-link i { font-size: 1.1rem; }
.menu-link:hover { background: var(--bg); color: var(--text); }
.menu-link.active { background: var(--accent-soft); color: var(--accent-dark); }
.menu-link.active::before {
  content: ''; position: absolute; left: -14px; top: 8px; bottom: 8px;
  width: 4px; border-radius: 0 4px 4px 0; background: var(--accent);
}

.topbar {
  position: sticky; top: 0; z-index: 1030;
  margin-left: var(--sidebar-w);
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px;
}
.topbar-title { font-weight: 700; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 14px; margin-left: auto; }

.user-chip { display: flex; align-items: center; gap: 10px; line-height: 1.2; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-dark);
  display: grid; place-items: center; font-weight: 800;
}
.user-name { font-weight: 700; font-size: .92rem; }
.user-role { font-size: .78rem; color: var(--muted); }

.burger {
  display: none;
  border: 1px solid var(--border); background: var(--surface);
  width: 40px; height: 40px; border-radius: 10px; font-size: 1.3rem;
}

.content {
  margin-left: var(--sidebar-w);
  padding: 32px 40px;
  max-width: 1400px;
}

.page-title { font-weight: 800; margin-bottom: 4px; }
.page-subtitle { color: var(--muted); margin-bottom: 28px; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  z-index: 1035;
}

/* ==========================================================
   4. Компоненти: картки статистики, список, бейджі
   ========================================================== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 22px;
}
.stat-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.5rem; flex-shrink: 0;
}
.stat-icon.accent { background: var(--accent-soft); color: var(--accent); }
.stat-icon.warn   { background: var(--warn-soft);   color: var(--warn); }
.stat-icon.ok     { background: var(--ok-soft);     color: var(--ok); }
.stat-label { color: var(--muted); font-size: .88rem; font-weight: 600; }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }

.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-title { font-weight: 700; }
.list-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.list-side { text-align: right; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.list-side strong { display: block; color: var(--text); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.status {
  display: inline-block;
  padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; margin-right: 8px;
}
.status-new      { background: var(--neutral-soft); color: var(--neutral); }
.status-progress { background: var(--warn-soft);    color: var(--warn); }
.status-done     { background: var(--ok-soft);      color: var(--ok); }
.status-cancel   { background: var(--danger-soft);  color: var(--danger); }

/* ==========================================================
   5. Сторінки входу та реєстрації
   ========================================================== */
.auth-body {
  min-height: 100vh;
  min-height: 100dvh;             /* враховує панелі мобільного браузера */
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 15% 10%, var(--accent-soft) 0, transparent 40%),
    radial-gradient(circle at 85% 90%, var(--warn-soft) 0, transparent 40%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 10px 30px rgba(31, 41, 51, .06);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand .brand-logo { margin: 0 auto 10px; width: 52px; height: 52px; font-size: 1.5rem; border-radius: 14px; }
.auth-brand h4 { font-weight: 800; margin: 0; }

/* ==========================================================
   Сторінки довідників
   ========================================================== */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 8px; flex-wrap: wrap;
}
.page-head .page-subtitle { margin-bottom: 20px; }

.search-bar { display: flex; gap: 8px; max-width: 520px; }

.list-link { color: inherit; text-decoration: none; }
.list-link:hover { background: var(--bg); }

.back-link {
  display: inline-block; margin-bottom: 14px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9rem;
}
.back-link:hover { color: var(--accent-dark); }

.info-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px; padding: 20px 22px;
}
.info-grid span {
  display: block; color: var(--muted); font-size: .78rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: 2px;
}
.info-wide { grid-column: 1 / -1; }

.form-panel { max-width: 640px; padding: 24px 26px; }

.btn-danger { border-radius: 10px; font-weight: 600; }

/* ==========================================================
   Обладнання: фільтри та коментарі
   ========================================================== */
.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.3fr auto auto;
  gap: 8px;
}

.comment { padding: 14px 22px; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
  font-size: .85rem;
}
.comment-head span { color: var(--muted); }
.btn-x {
  border: 0; background: transparent; color: var(--muted);
  padding: 2px 6px; border-radius: 6px;
}
.btn-x:hover { background: var(--danger-soft); color: var(--danger); }

@media (max-width: 991.98px) {
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar input[name="q"] { grid-column: 1 / -1; }
}

/* ==========================================================
   6. Адаптивність (планшети та телефони)
   ========================================================== */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 30px rgba(0,0,0,.15); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }

  .topbar { margin-left: 0; padding: 0 16px; }
  .content { margin-left: 0; padding: 20px 16px; }
  .burger { display: grid; place-items: center; margin-right: 12px; }
  .menu-link.active::before { display: none; }
}

@media (max-width: 575.98px) {
  .user-info { display: none; }          /* на телефоні лишаємо тільки аватар */
  .page-title { font-size: 1.5rem; }
  .stat-value { font-size: 1.7rem; }
  .list-item { flex-direction: column; align-items: flex-start; gap: 6px; }
  .list-side { text-align: left; }
  .auth-card { padding: 28px 20px; }
}

/* Історія статусів */
.timeline { list-style: none; margin: 0; padding: 10px 22px; }
.timeline li {
  padding: 8px 0; font-size: .88rem; color: var(--muted);
  border-bottom: 1px dashed var(--border);
}
.timeline li:last-child { border-bottom: 0; }
.timeline strong { color: var(--text); }

/* ==========================================================
   Маршрути
   ========================================================== */
.route-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.route-bar .form-control, .route-bar .form-select { width: auto; }

.route-item { align-items: flex-start; }
.route-num {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent-dark);
  display: grid; place-items: center; font-weight: 800;
}
.route-main { flex: 1; min-width: 0; }
.route-actions {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; justify-content: flex-end;
}
.is-cancelled { opacity: .55; }

@media (max-width: 575.98px) {
  .route-item { flex-direction: row; flex-wrap: wrap; }
  .route-actions { width: 100%; justify-content: flex-start; }
}

/* ==========================================================
   Склад і списання запчастин
   ========================================================== */
.stock-low { background: #fffbeb; }
.stock-qty { font-size: 1.05rem; white-space: nowrap; margin-right: 6px; }
.restock-form { display: flex; gap: 6px; }
.restock-form input { width: 96px; }

.part-form {
  display: grid; grid-template-columns: 1fr 120px auto; gap: 8px;
  padding: 16px 22px; border-top: 1px solid var(--border);
}

@media (max-width: 575.98px) {
  .part-form { grid-template-columns: 1fr; }
}

/* ==========================================================
   Налаштування та двоетапна автентифікація
   ========================================================== */
.settings-card { padding: 24px 26px; }
.settings-card h5 { font-weight: 800; margin-bottom: 4px; }

.status-accent { background: var(--accent-soft); color: var(--accent-dark); }

.step {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 12px; font-weight: 600;
}
.step span {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: .85rem;
}

.qr-box {
  display: flex; gap: 20px; align-items: center; flex-wrap: wrap;
  padding: 16px; border: 1px dashed var(--border); border-radius: var(--radius);
}
.qr-box img { border-radius: 8px; background: #fff; }
.secret-key {
  font-family: ui-monospace, Consolas, monospace; font-weight: 700;
  background: var(--bg); padding: 10px 14px; border-radius: 10px;
  letter-spacing: .08em; word-break: break-all;
}

.otp-input {
  font-size: 1.6rem; font-weight: 700; text-align: center;
  letter-spacing: .4em; max-width: 280px;
}
.auth-card .otp-input { max-width: 100%; }
.otp-form .otp-input { margin: 0; }

/* ==========================================================
   Вкладки, звіти, списання
   ========================================================== */
.tabs {
  display: flex; gap: 6px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 10px 16px; color: var(--muted); font-weight: 700;
  text-decoration: none; border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.tab small {
  background: var(--bg); border-radius: 999px; padding: 1px 8px;
  margin-left: 4px; color: var(--muted);
}

.writeoff-box { background: #fff7ed; border-color: #fed7aa; }

.report-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.report-card {
  padding: 22px; display: flex; flex-direction: column; gap: 10px;
  color: inherit; text-decoration: none;
}
.report-card:hover { border-color: var(--accent); }
.report-card h5 { font-weight: 800; margin: 0; }

.preset-links { display: flex; gap: 14px; flex-wrap: wrap; font-size: .88rem; }
.preset-links a { color: var(--accent-dark); font-weight: 600; text-decoration: none; }
.preset-links a:hover { text-decoration: underline; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th {
  background: var(--accent); color: #fff; padding: 10px 12px;
  text-align: left; white-space: nowrap;
}
.data-table th.text-end { text-align: right; }
.data-table td {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tbody tr:nth-child(even) { background: var(--bg); }
.data-table tfoot td { font-weight: 800; background: var(--accent-soft); }

/* ==========================================================
   Дашборд
   ========================================================== */
.kpi-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.stat-icon.neutral { background: var(--neutral-soft); color: var(--neutral); }
.stat-icon.danger  { background: var(--danger-soft);  color: var(--danger); }

/* Вибір періоду */
.seg {
  display: inline-flex; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.seg a {
  padding: 7px 14px;
  border-radius: 9px;
  font-weight: 700;
  font-size: .85rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg a:hover { background: var(--bg); color: var(--text); }
.seg a.active { background: var(--accent); color: #fff; }

/* Графіки */
.chart-grid {
  display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr));
}
.chart-wide { grid-column: 1 / -1; }
.chart-card { padding: 18px 20px; }
.chart-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-bottom: 12px;
}
.chart-head h6 { font-weight: 800; margin: 0; font-size: 1rem; }
.chart-box { position: relative; height: 270px; }
.chart-wide .chart-box { height: 300px; }

@media (max-width: 991.98px) {
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 575.98px) {
  .chart-box, .chart-wide .chart-box { height: 240px; }
  .seg { width: 100%; justify-content: space-between; }
}

/* Блок «Потребують поповнення» */
.link-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-dark);
  font-size: .82rem; font-weight: 700;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}
.link-pill:hover { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent-dark); }

.low-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.low-row:last-child { border-bottom: 0; }
.chart-empty {
  height: 100%; min-height: 110px; display: grid; place-items: center;
  color: var(--muted); font-weight: 600; text-align: center;
}

/* ==========================================================
   Мобільні покращення
   ========================================================== */
/* Пошукові поля у рядках фільтрів */
.search-input { min-width: 260px; }

/* Компактна форма в один рядок (вимкнення 2FA) */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .form-control { flex: 1 1 220px; max-width: 320px; }

/* На сенсорних екранах маленькі кнопки-іконки мають бути зручними для пальця */
@media (pointer: coarse) {
  .btn-x {
    min-width: 36px; min-height: 36px;
    display: inline-grid; place-items: center;
  }
}

@media (max-width: 991.98px) {
  /* Поки відкрите бічне меню, сторінка під ним не прокручується */
  body.sidebar-open { overflow: hidden; }
}

@media (max-width: 575.98px) {
  /* 16px — щоб iOS не збільшував сторінку під час введення */
  .form-control, .form-select, .form-control-sm { font-size: 16px; }

  /* Поля пошуку займають увесь рядок */
  .route-bar .search-input,
  .route-bar > input[type="text"] { flex: 1 1 100%; min-width: 0; }

  /* Ключові показники — по два в ряд замість восьми високих карток */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-grid .stat {
    flex-direction: column; align-items: flex-start;
    gap: 10px; padding: 14px;
  }
  .kpi-grid .stat-icon { width: 40px; height: 40px; font-size: 1.2rem; border-radius: 12px; }
  .kpi-grid .stat-label { font-size: .8rem; }
  .kpi-grid .stat-value { font-size: 1.4rem; }

  /* «#17 15.11.2026» та «2 підрозділів» в один рядок */
  .list-side strong { display: inline; margin-right: 6px; }
}