:root {
  /* Фірмові кольори РОСТ: синій — з реальних файлів логотипу сайту (rost-logo-blue),
     зелений — смисловий акцент на самій назві "РОСТ" (зростання), не довільний вибір. */
  --rost-blue: #1a4d8f;
  --rost-blue-dark: #0f3568;
  --rost-blue-light: #e8f0fb;
  --rost-green: #2f9e5c;
  --rost-green-light: #e3f6ea;

  --bg: var(--tg-theme-bg-color, #f4f7fb);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #eaf0f8);
  --text: var(--tg-theme-text-color, #16233a);
  --hint: var(--tg-theme-hint-color, #6b7c93);
  --link: var(--tg-theme-link-color, var(--rost-blue));
  --button: var(--tg-theme-button-color, var(--rost-blue));
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --border: rgba(20, 40, 70, 0.08);
  --danger: #d64545;
  --success: var(--rost-green);
  --warn: #d9822b;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--secondary-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 24px;
  letter-spacing: -0.01em;
}

.brand-header {
  background: linear-gradient(135deg, var(--rost-blue) 0%, var(--rost-blue-dark) 100%);
  padding: 20px 16px 22px;
  border-radius: 0 0 20px 20px;
  color: #ffffff;
  position: relative;
  overflow: hidden;
}
.brand-header::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
}
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: relative;
}
.brand-logo { display: flex; align-items: center; gap: 10px; }
.brand-logo svg { display: block; }
.brand-title { font-size: 12px; font-weight: 600; opacity: 0.85; letter-spacing: 0.01em; margin: 0; }
.brand-subtitle { font-size: 16px; font-weight: 700; margin: 2px 0 0; white-space: nowrap; }
.user-badge {
  font-size: 12px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.15);
  padding: 5px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 12px 8px;
  margin-bottom: 4px;
  overflow-x: auto;
}
.tab {
  flex: 1;
  min-width: 0;
  padding: 9px 4px;
  border: none;
  background: transparent;
  color: var(--hint);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}
.tab.active { background: var(--section-bg); color: var(--rost-blue); box-shadow: 0 2px 6px var(--border); }
.badge {
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

main { padding: 0 12px; }
.panel { display: none; }
.panel.active { display: block; }

.filters { margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.filters input, .filters select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--section-bg);
  color: var(--text);
  font-size: 14px;
}
.filter-row { display: flex; gap: 8px; }
.filter-row select { flex: 1; }

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: 0 1px 3px var(--border);
  border: 1px solid transparent;
}
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.card-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.card-sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.card-row { display: flex; justify-content: space-between; font-size: 13px; margin-top: 5px; }
.card-row .label { color: var(--hint); }

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.pill-draft { background: #eaeef4; color: #566a85; }
.pill-under_review { background: #fdf1de; color: #a5680f; }
.pill-approved { background: var(--rost-green-light); color: #1f7a44; }
.pill-rejected { background: #fbe6e6; color: #b3261e; }

.card-actions { display: flex; gap: 8px; margin-top: 12px; }

.btn {
  flex: 1;
  padding: 11px 12px;
  border-radius: 11px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--rost-green); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: var(--secondary-bg); color: var(--text); }

.empty { text-align: center; color: var(--hint); padding: 44px 20px; font-size: 14px; }
.empty::before {
  content: "🌱";
  display: block;
  font-size: 28px;
  margin-bottom: 10px;
  opacity: 0.6;
}

.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; color: var(--hint); font-size: 14px; }
.pagination button {
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 12px;
  color: var(--rost-blue);
  font-weight: 600;
  cursor: pointer;
}
.pagination button:disabled { color: var(--hint); cursor: default; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--rost-blue-dark);
  color: #ffffff;
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  max-width: 90%;
  text-align: center;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(15, 53, 104, 0.3);
}

.modal {
  position: fixed; inset: 0;
  background: rgba(15, 25, 45, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
/* КРИТИЧНО: без цього правила модалка показується ЗАВЖДИ, ігноруючи атрибут hidden —
   тому що .modal { display: flex } і вбудоване [hidden] { display: none } мають однакову
   специфічність, а наше правило йде пізніше в каскаді й перемагає. Саме це й спричиняло
   баг "модалка відкрита одразу при вході в застосунок". */
.modal[hidden] {
  display: none;
}
.modal-card {
  background: var(--section-bg);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 22px;
}
.modal-card h3 { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.modal-hint { color: var(--hint); font-size: 13px; margin: 0 0 12px; }
.modal-card textarea {
  width: 100%;
  border-radius: 11px;
  border: 1px solid var(--border);
  padding: 11px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }

.section-hint { color: var(--hint); font-size: 13px; margin: 4px 0 10px; }

.doc-type-grid { display: flex; flex-direction: column; gap: 8px; }
.doc-type-btn {
  padding: 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--section-bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 2px var(--border);
}
.doc-type-btn:active { opacity: 0.7; }

.upload-box {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 15px;
  border: 1.5px dashed var(--border);
}
.upload-box input[type="file"] { width: 100%; color: var(--text); font-size: 13px; }
.upload-box textarea {
  width: 100%;
  margin-top: 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.discrepancy-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.discrepancy-item:last-child { border-bottom: none; }
.discrepancy-item .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-critical { background: var(--danger); }
.dot-normal { background: var(--warn); }

.route-choice { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.kb-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.kb-tab {
  flex: 1;
  padding: 9px;
  border: 1px solid var(--border);
  background: var(--section-bg);
  color: var(--hint);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.kb-tab.active { color: var(--rost-blue); border-color: var(--rost-blue); background: var(--rost-blue-light); }

.spinner-text { text-align: center; color: var(--hint); padding: 30px 0; font-size: 14px; }
