:root {
  --main-bg: #f8f9fa;
  --main-color: #222;
  --accent: #2e7d32;
  --header-bg: #fff;
  --table-header: #e9ecef;
  --modal-bg: rgba(0,0,0,0.55);
  --border: rgba(0,0,0,0.08);
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
}

body.dark {
  --main-bg: #181a1b;
  --main-color: #f1f1f1;
  --header-bg: #23272a;
  --table-header: #2e3236;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 2px 10px rgba(0,0,0,0.35);
}

/* критично: hidden має реально ховати елемент (інакше модалка перекриває весь екран) */
[hidden], .modal[hidden] { display: none !important; }

body {
  background: var(--main-bg);
  color: var(--main-color);
  font-family: 'Segoe UI', Arial, sans-serif;
  margin: 0;
}

header {
  background: var(--header-bg);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

h1 { font-size: 1.2rem; margin: 0; }

nav ul {
  display: flex;
  gap: .5rem;
  list-style: none;
  padding: 0;
  margin: 0;
  flex-wrap: wrap;
}

nav a {
  color: var(--main-color);
  text-decoration: none;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 1.14rem;
  font-weight: 800;
  line-height: 1.2;
}

nav a.active, nav a:focus {
  background: var(--accent);
  color: #fff;
}

main {
  padding: 2rem;
  max-width: 1200px;
  margin: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

th, td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--table-header);
  text-align: left;
  font-weight: 600;
}

tr:last-child td { border-bottom: none; }

button, input[type="search"], input, select, textarea {
  margin: 0.25rem 0;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.18);
  font-size: 1rem;
  background: var(--header-bg);
  color: var(--main-color);
}

body.dark button, body.dark input, body.dark select, body.dark textarea {
  border-color: rgba(255,255,255,0.18);
}

button { cursor: pointer; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.icon {
  border-radius: 999px;
  width: 42px;
  height: 42px;
  padding: 0;
}

button.danger {
  background: #b00020;
  border-color: #b00020;
  color: #fff;
}

button:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea { width: 100%; box-sizing: border-box; font-family: ui-monospace, Consolas, monospace; }

label { display:block; margin: .35rem 0; }
label > input, label > select, label > textarea { width: 100%; box-sizing: border-box; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 1rem 0;
}

.card {
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.04);
}

.card .value { font-size: 1.6rem; font-weight: 800; }
.card .label { font-size: 0.9rem; opacity: .8; }

.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--table-header);
  border: 1px solid var(--border);
  font-size: .85rem;
}

.muted { opacity: .75; }

.row { display:flex; align-items:center; gap:.5rem; }


.company-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .5rem 1rem;
}
.company-grid label{ margin: 0; }

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--modal-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal > div {
  background: var(--header-bg);
  color: var(--main-color);
  padding: 1rem 1rem 1.25rem;
  border-radius: 14px;
  min-width: 320px;
  max-width: 980px;
  width: min(980px, 92vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--border);
}

.hr { height:1px; background: var(--border); margin: .75rem 0; }

iframe.preview {
  width: 100%;
  height: 60vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

@media (max-width: 768px) {
  main { padding: 1rem; }
  header { flex-direction: column; align-items: flex-start; }
}


/* ECS logo in header */
.brand{display:flex;align-items:center;gap:12px;}
.brand-logo{height:48px;width:auto;display:block;}
.brand-text{display:flex;flex-direction:column;gap:2px;}
@media (max-width:768px){.brand-logo{height:40px;}}

/* ===== Економіка ===== */

#dashboard {
  max-width: 1100px;
  margin: 0 auto;
}

#dashboard h2 {
  margin-bottom: 20px;
}

#economy-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 16px;
  margin: 20px 0 28px;
}

#economy-cards > div {
  background: var(--header-bg);
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
  font-weight: 600;
}

#dashboard h3 {
  margin-top: 28px;
  margin-bottom: 12px;
}

#wasteChart {
  display: block;
  max-height: 260px;
  margin-bottom: 28px;
}

#economy-operations-table,
#economy-waste-table,
#economy-contractors-table,
#economy-rates {
  background: var(--header-bg);
  border: 1px dashed #cfcfcf;
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 18px;
  color: #666;
}

body.dark #economy-cards > div,
body.dark #economy-operations-table,
body.dark #economy-waste-table,
body.dark #economy-contractors-table,
body.dark #economy-rates {
  border-color: #3a3a3a;
  color: var(--main-color);
}

@media (max-width: 900px) {
  #economy-cards {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 600px) {
  #economy-cards {
    grid-template-columns: 1fr;
  }
}

#economy-filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin: 0 0 22px;
  padding: 16px;
  background: var(--header-bg);
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}

#economy-filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

#economy-filters input,
#economy-filters select {
  padding: 0.55rem 0.7rem;
  border: 1px solid #bbb;
  border-radius: 8px;
  background: var(--main-bg);
  color: var(--main-color);
  font-size: 0.95rem;
}

#economy-apply-filters {
  height: 40px;
  margin: 0;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
}

body.dark #economy-filters {
  border-color: #3a3a3a;
}

@media (max-width: 1100px) {
  #economy-filters {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  #economy-apply-filters {
    width: 100%;
  }
}

@media (max-width: 600px) {
  #economy-filters {
    grid-template-columns: 1fr;
  }
}

.economy-table-wrap {
  background: var(--header-bg);
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  overflow-x: auto;
  margin-bottom: 22px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}

.economy-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.95rem;
}

.economy-table th,
.economy-table td {
  padding: 12px 14px;
  border: 1px solid #e5e5e5;
  text-align: left;
}

.economy-table th {
  background: var(--table-header);
  font-weight: 700;
}

.economy-table tbody td[colspan] {
  color: #777;
  text-align: center;
  padding: 18px;
}

body.dark .economy-table-wrap {
  border-color: #3a3a3a;
}

.economy-chart-card {
  background: var(--header-bg);
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 32px;
  height: 280px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}

.economy-chart-card canvas {
  width: 100% !important;
  height: 240px !important;
  max-height: 240px !important;
}

body.dark .economy-chart-card {
  border-color: #3a3a3a;
}

.economy-card-title {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 8px;
}

.economy-card-value {
  font-size: 1.25rem;
  font-weight: 700;
}

body.dark .economy-card-title {
  color: #cfcfcf;
}

/* ===== Економіка: дрібне вирівнювання таблиць ===== */

#economy-rates td:nth-child(6),
#economy-rates th:nth-child(6) {
  white-space: nowrap;
  min-width: 95px;
}

.economy-table td[style*="text-align:right"],
.economy-table th[style*="text-align:right"] {
  white-space: nowrap;
}

/* Друк електронного паспорта секції */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  html,
  body {
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    color: black !important;
    overflow: visible !important;
  }

  body > *:not(#modal) {
    display: none !important;
  }

  #modal {
    display: block !important;
    position: static !important;
    inset: auto !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    overflow: visible !important;
  }

  #modal > div {
    position: static !important;
    width: auto !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: white !important;
    color: black !important;
    font-size: 12px !important;
    line-height: 1.35 !important;
  }

  #modal h3 {
    margin: 0 0 10px 0 !important;
    font-size: 16px !important;
  }

  #modal .card {
    border: 1px solid #ddd !important;
    border-radius: 6px !important;
    padding: 10px !important;
    margin: 0 0 8px 0 !important;
    box-shadow: none !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  #modal p {
    margin: 8px 0 0 0 !important;
  }

  #modal .toolbar,
  #modal button {
    display: none !important;
  }
}



/* ===== Верхнє меню: читабельніші вкладки ===== */
header nav a {
  font-size: 1.28rem !important;
  font-weight: 900 !important;
  letter-spacing: 0.01em;
  padding: 0.6rem 1.05rem !important;
}

header nav a.active {
  font-weight: 900 !important;
}

/* ===== Header / navigation readability improvements ===== */
header {
  align-items: flex-start;
  gap: 1.5rem;
  padding: 1.15rem 1.75rem;
}

.brand {
  flex: 0 0 520px;
  max-width: 520px;
  gap: 14px;
}

.brand-logo {
  height: 62px;
}

.brand-text h1 {
  font-size: 1.35rem;
  line-height: 1.15;
  margin-bottom: .15rem;
}

#product-tagline {
  font-size: 1.02rem;
  line-height: 1.35;
}

#company-header {
  font-size: 1.02rem;
  line-height: 1.35;
}

nav {
  flex: 1 1 auto;
  padding-top: .15rem;
}

nav ul {
  gap: .75rem 1rem;
  row-gap: .85rem;
  align-items: center;
  line-height: 1.2;
}

nav li {
  display: flex;
  align-items: center;
}

nav a {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  line-height: 1.15;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  padding: .5rem 1rem;
}

#theme-toggle,
#logout-btn,
button[id*="logout"],
button[onclick*="logout"] {
  flex: 0 0 auto;
}

@media (max-width: 1100px) {
  header {
    align-items: flex-start;
  }

  .brand {
    flex-basis: 420px;
    max-width: 420px;
  }

  .brand-logo {
    height: 56px;
  }

  nav ul {
    row-gap: .75rem;
  }
}

@media (max-width: 768px) {
  header {
    gap: .85rem;
  }

  .brand {
    flex-basis: auto;
    max-width: 100%;
  }

  .brand-logo {
    height: 48px;
  }

  nav a {
    min-height: 38px;
    font-size: 1rem;
  }
}


/* ===== Налаштування: таблиця користувачів ===== */
#user-management-card {
  overflow-x: auto;
}

#user-management-card table {
  min-width: 980px;
  table-layout: fixed;
}

#user-management-card th:nth-child(1),
#user-management-card td:nth-child(1) {
  width: 170px;
}

#user-management-card th:nth-child(2),
#user-management-card td:nth-child(2) {
  width: 170px;
}

#user-management-card th:nth-child(3),
#user-management-card td:nth-child(3) {
  width: 145px;
}

#user-management-card th:nth-child(4),
#user-management-card td:nth-child(4) {
  width: 160px;
  min-width: 160px;
}

#user-management-card th:nth-child(5),
#user-management-card td:nth-child(5) {
  width: 170px;
}

#user-management-card th:nth-child(6),
#user-management-card td:nth-child(6) {
  width: 300px;
}

#user-management-card select[data-role],
#user-management-card input[data-display-name],
#user-management-card input[data-password] {
  width: 100%;
  box-sizing: border-box;
}

#user-management-card td:nth-child(4) .badge {
  white-space: nowrap;
}

#user-management-card td:nth-child(6) button {
  padding: 0.4rem 0.55rem;
  font-size: 0.92rem;
}

/* ===== Адмін: позначка тестової компанії ===== */
#test-company-admin-card label.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#test-company-admin-card input[type="checkbox"] {
  width: auto !important;
  min-width: auto !important;
  margin: 0;
}


/* ===== Швидке введення журналу: галочки ===== */
.quick-choice-list {
  margin-top: 0.5rem;
  border: 1px solid #d6dde8;
  border-radius: 10px;
  padding: 0.5rem;
  max-height: 330px;
  overflow: auto;
  background: #fff;
}

.quick-choice-list label {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.35rem 0.25rem;
  border-bottom: 1px solid #edf1f5;
}

.quick-choice-list label:last-child {
  border-bottom: 0;
}

.quick-choice-list input[type="checkbox"] {
  width: auto !important;
  min-width: auto !important;
  margin-top: 0.18rem;
}

.quick-choice-list .quick-choice-text {
  line-height: 1.35;
}


/* ===== Mobile phone layout: журнал і шапка на смартфоні ===== */
@media (max-width: 640px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    font-size: 14px;
  }

  header {
    padding: 8px 10px !important;
    gap: 6px !important;
    align-items: stretch !important;
  }

  .brand {
    width: 100%;
    gap: 8px !important;
    align-items: center !important;
  }

  .brand-logo {
    height: 30px !important;
    max-width: 42px;
  }

  .brand-text {
    min-width: 0;
    gap: 0 !important;
  }

  .brand-text h1 {
    font-size: 1rem !important;
    line-height: 1.1 !important;
    margin: 0 !important;
  }

  #product-tagline {
    display: none !important;
  }

  #company-header {
    max-width: calc(100vw - 84px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .78rem !important;
    line-height: 1.15 !important;
    margin-top: 1px !important;
  }

  header nav {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  header nav ul {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    width: max-content;
    min-width: 100%;
    margin: 0 !important;
    padding: 2px 0 4px !important;
  }

  header nav li {
    flex: 0 0 auto;
  }

  header nav a {
    display: inline-block;
    padding: 7px 9px !important;
    font-size: .86rem !important;
    line-height: 1.1 !important;
    white-space: nowrap;
  }

  #theme-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 7px !important;
    min-height: 28px;
  }

  main {
    padding: 10px !important;
  }

  h2 {
    font-size: 1.15rem;
    line-height: 1.2;
    margin-top: .25rem;
  }

  h3 {
    font-size: 1rem;
    line-height: 1.2;
  }

  .company-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .toolbar {
    gap: 8px !important;
  }

  .toolbar button,
  form button,
  button,
  input,
  select,
  textarea {
    max-width: 100%;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  table {
    min-width: 720px;
  }

  .card,
  section {
    max-width: 100%;
  }

  .table-wrap,
  .economy-table-wrap,
  .list,
  .records-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== Desktop layout: ширша робоча область на ПК / ноутбуку ===== */
@media (min-width: 1000px) {
  main {
    max-width: min(1680px, calc(100vw - 64px)) !important;
    width: 100%;
    padding-left: 2rem;
    padding-right: 2rem;
  }

  main > section {
    width: 100%;
  }

  #intake-journal,
  #documents,
  #production,
  #operations,
  #processing-batches,
  #reports,
  #contractors,
  #settings {
    max-width: none !important;
  }

  #intake-journal .card,
  #documents .card,
  #production .card,
  #operations .card,
  #processing-batches .card,
  #reports .card,
  #contractors .card,
  #settings .card {
    max-width: none !important;
  }

  #intake-journal .company-grid {
    grid-template-columns: repeat(5, minmax(170px, 1fr));
    gap: .65rem 1rem;
  }

  #intake-journal textarea {
    min-height: 76px;
  }
}

@media (min-width: 1000px) and (max-width: 1350px) {
  #intake-journal .company-grid {
    grid-template-columns: repeat(4, minmax(170px, 1fr));
  }
}

/* ===== EcoReport Workshop environment banner ===== */
.ecoreport-workshop-banner {
  display: none;
}

html.ecoreport-workshop-mode .ecoreport-workshop-banner {
  position: sticky;
  top: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 18px;
  background: #8b1e1e;
  color: #ffffff;
  border-bottom: 3px solid #f0b429;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
}

html.ecoreport-workshop-mode .ecoreport-workshop-banner strong {
  letter-spacing: 0.04em;
}

html.ecoreport-workshop-mode .ecoreport-workshop-banner span {
  font-weight: 500;
}

@media (max-width: 760px) {
  html.ecoreport-workshop-mode .ecoreport-workshop-banner {
    flex-direction: column;
    gap: 3px;
    padding: 8px 12px;
    font-size: 13px;
  }
}
