:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e5e9;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --danger: #dc2626;
  --paid: #16a34a;
  --partial: #d97706;
  --unpaid: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  animation: page-fade-in .2s ease;
  transition: opacity .15s ease;
}

@keyframes page-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Ставится через JS перед уходом на другую страницу, чтобы текущая страница
   плавно погасла вместо резкого обрыва в белый экран при смене документа. */
html.page-leaving body {
  opacity: 0;
}

/* Плавные переходы между страницами (Chrome/Edge; в остальных браузерах просто игнорируется) */
@view-transition {
  navigation: auto;
}

#page-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--primary);
  z-index: 9999;
  opacity: 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
}
.topbar a { color: #fff; }
.topbar nav a { margin-right: 18px; opacity: 0.9; }
.topbar nav a.active { opacity: 1; font-weight: 600; text-decoration: underline; }
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar .brand a { display: inline-flex; align-items: center; gap: 8px; }
.brand-icon { height: 28px; width: auto; }
.topbar .user { opacity: 0.85; font-size: 13px; }

.container {
  max-width: 1180px;
  margin: 24px auto;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: .03em; }
th a.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
th a.sort-link:hover { color: var(--text); }
th a.sort-link .arrow { opacity: .6; margin-left: 2px; }
tr:hover td { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-outline { background: transparent; color: var(--primary); }
.btn-outline:hover { background: #eef2ff; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

.badge { display: inline-flex; align-items: center; justify-content: center; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1; color: #fff; text-align: center; white-space: nowrap; }
.badge-paid { background: var(--paid); }
.badge-partial { background: var(--partial); }
.badge-unpaid { background: var(--unpaid); }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters .form-row { margin-bottom: 0; min-width: 160px; }

.bulk-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.bulk-actions .bulk-select { width: auto; min-width: 180px; }

.row-actions { text-align: right; white-space: nowrap; }
.row-actions > *:not(:first-child) { margin-left: 8px; }

.muted { color: var(--muted); }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.items-table input { padding: 6px 8px; }
.right { text-align: right; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 16px; }
.page-header h1 { margin: 0; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Таблицы прокручиваются по горизонтали внутри своего блока, а не ломают
   вёрстку всей страницы — актуально в первую очередь на узких экранах. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== Мобильные экраны ===== */
@media (max-width: 720px) {
  .container { margin: 12px auto; padding: 0 12px; }
  .card { padding: 14px; }
  h1 { font-size: 19px; }
  h2 { font-size: 16px; }

  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 16px; }
  .topbar nav { display: flex; flex-wrap: wrap; gap: 6px 14px; }
  .topbar .user { font-size: 12px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 0; }

  .filters { gap: 10px; }
  .filters .form-row { min-width: 0; flex: 1 1 140px; }

  /* На iOS Safari поле с font-size меньше 16px вызывает автозум при фокусе */
  input[type=text], input[type=number], input[type=date], input[type=password],
  input[type=email], select, textarea, .btn {
    font-size: 16px;
  }

  table { font-size: 13px; }
  th, td { padding: 8px 6px; }
}

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; margin: 0; padding: 0; }
}
