/* Тальне-Сервіс — дизайн-система. Сучасний, чистий, без зайвого. */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f4f6f5;
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --border: #e2e6e4;
  --text: #10201c;
  --text-dim: #5b6b66;
  --text-faint: #8b9994;
  --brand: #0f9d70;
  --brand-dark: #0b7a57;
  --brand-light: #d9f5e9;
  --accent: #0ea5e9;
  --danger: #e0473e;
  --danger-bg: #fdeceb;
  --warn: #d99a1f;
  --warn-bg: #fdf3dd;
  --ok: #0f9d70;
  --ok-bg: #e3f7ee;
  --shadow-sm: 0 1px 2px rgba(16, 32, 28, 0.06);
  --shadow-md: 0 6px 20px -6px rgba(16, 32, 28, 0.15);
  --shadow-lg: 0 20px 50px -12px rgba(16, 32, 28, 0.25);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Manrope', var(--font);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1210;
    --bg-alt: #0f1a17;
    --surface: #131f1c;
    --surface-2: #1a2925;
    --border: #24352f;
    --text: #eaf3f0;
    --text-dim: #a6b8b2;
    --text-faint: #6f8680;
    --brand: #21c98a;
    --brand-dark: #17a674;
    --brand-light: #123527;
    --accent: #38bdf8;
    --danger: #f36b62;
    --danger-bg: #2a1614;
    --warn: #e8b34a;
    --warn-bg: #2b2311;
    --ok: #21c98a;
    --ok-bg: #102a20;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 24px -6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { padding: 0; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 800; line-height: 1.2; margin: 0 0 .4em; letter-spacing: -0.01em; }
h1 { font-size: 2rem; } h2 { font-size: 1.5rem; } h3 { font-size: 1.15rem; } h4 { font-size: 1rem; }
p { margin: 0 0 1em; color: var(--text-dim); }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { padding-left: 1.2em; }
small { color: var(--text-faint); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Тло-декор для публічних сторінок */
.bg-mesh {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(1200px 600px at 15% -10%, var(--brand-light), transparent 60%),
              radial-gradient(900px 500px at 100% 0%, rgba(14,165,233,0.10), transparent 60%),
              var(--bg);
}

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

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: 12px; border: 1px solid transparent;
  font-family: var(--font); font-weight: 600; font-size: .92rem; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  text-decoration: none; line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: 0 10px 24px -8px rgba(15,157,112,.55); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-sm { padding: 7px 12px; font-size: .82rem; border-radius: 9px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Картки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow-sm);
}
.card-glass {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; position: relative; overflow: hidden;
}
.stat-card .label { font-size: .78rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-card .value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 800; margin-top: 6px; }
.stat-card .sub { font-size: .82rem; color: var(--text-dim); margin-top: 4px; }
.stat-card.accent-brand::before, .stat-card.accent-danger::before, .stat-card.accent-warn::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.stat-card.accent-brand::before { background: var(--brand); }
.stat-card.accent-danger::before { background: var(--danger); }
.stat-card.accent-warn::before { background: var(--warn); }

/* ---------- Бейджі боргу ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--text-dim); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- Форми ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field .hint { font-size: .78rem; color: var(--text-faint); margin-top: 4px; }
input, select, textarea {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-alt); color: var(--text); font-family: var(--font); font-size: .93rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------- Таблиці ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .89rem; }
thead th {
  text-align: left; padding: 12px 16px; background: var(--surface-2); color: var(--text-dim);
  font-weight: 700; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 0;
}
tbody td { padding: 12px 16px; border-top: 1px solid var(--border); }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-link { cursor: pointer; }

/* ---------- Навігація ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 75%, transparent); border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 6px 24px; max-width: 1180px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; color: var(--text); }
.brand-logo { height: 46px; width: auto; display: block; flex: none; }
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-links a { padding: 8px 14px; border-radius: 9px; color: var(--text-dim); font-weight: 600; font-size: .88rem; }
.nav-links a:hover, .nav-links a.active { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ---------- Адмін-лейаут з боковим меню ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.admin-sidebar .brand { padding: 6px 10px 20px; }
.admin-sidebar .brand-logo { height: 51.69px; }
.admin-sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-dim); font-weight: 600; font-size: .89rem;
}
.admin-sidebar a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.admin-sidebar a.active { background: var(--brand-light); color: var(--brand-dark); }
.admin-main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.admin-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.admin-sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

@media (max-width: 860px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: relative; flex-direction: row; overflow-x: auto; }
  .admin-sidebar .brand { display: none; }
  .admin-main { padding: 20px 16px 60px; }
}

/* ---------- Картка абонента (у стилі паперового обліку) ---------- */
.record-card { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.record-field { background: var(--surface); padding: 12px 16px; }
.record-field .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; margin-bottom: 3px; }
.record-field .v { font-size: .95rem; font-weight: 600; }
.record-field .v.empty { color: var(--text-faint); font-weight: 400; font-style: italic; }

/* ---------- Квитанція ---------- */
.invoice {
  background: #fff; color: #0a0a0a; border: 2px solid #0a0a0a; border-radius: 4px; padding: 0; max-width: 760px; margin: 0 auto;
  font-size: 13px;
}
.invoice table { font-size: 13px; }
.invoice-head { display: grid; grid-template-columns: 1fr auto; border-bottom: 2px solid #0a0a0a; }
.invoice-head .org { padding: 10px 14px; border-right: 2px solid #0a0a0a; font-weight: 700; }
.invoice-head .period { padding: 10px 14px; text-align: right; }
.invoice-row { display: grid; grid-template-columns: 140px 1fr; border-bottom: 1px solid #0a0a0a; }
.invoice-row > div { padding: 8px 14px; border-right: 1px solid #0a0a0a; }
.invoice-row > div:last-child { border-right: none; }
.invoice .city { text-align: center; font-weight: 800; font-size: 1.3em; }
.invoice-table { width: 100%; border-collapse: collapse; }
.invoice-table th, .invoice-table td { border: 1px solid #0a0a0a; padding: 6px 8px; text-align: center; }
.invoice-total { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 2px solid #0a0a0a; font-weight: 800; font-size: 1.15em; }
.invoice-total .amount { margin-left: auto; }
.invoice-note { padding: 8px 14px; border-top: 1px solid #0a0a0a; font-size: .85em; }
.invoice-footer { display: flex; gap: 16px; align-items: center; padding: 12px 14px; }
.invoice-footer .req { flex: 1; font-size: .85em; }
.invoice-actions { display: flex; gap: 10px; justify-content: center; margin: 20px 0; }

@media print {
  body * { visibility: hidden; }
  .invoice, .invoice *, .legal-doc, .legal-doc *, .bulk-invoice-sheet, .bulk-invoice-sheet * { visibility: visible; }
  .invoice { position: absolute; top: 0; left: 0; margin: 0; border-width: 1px; }
  .legal-doc { position: absolute; top: 0; left: 0; margin: 0; }
  .invoice-actions, .topbar, .no-print { display: none !important; }

  /* Масовий друк квитанцій — не одна на весь аркуш, а стопкою по 3.
     Усі властивості нижче — з !important: у файлі нижче є загальні (не print)
     правила з такою самою специфічністю (.bulk-invoice-slot, .bulk-invoice-slot
     .invoice), і оскільки вони йдуть ПІЗНІШЕ в каскаді, вони переб'ють ці
     print-правила без !important (перевірено рендером — це і була причина
     того, що шрифт лишався 12px, а не 9px, і поля не стискались). */
  .bulk-invoice-sheet { position: absolute !important; top: 0 !important; left: 0 !important; margin: 0 !important; width: 100% !important; }
  .bulk-invoice-sheet .invoice { position: static !important; margin: 0 auto !important; font-size: 9px !important; max-width: 100% !important; border-width: 1px !important; }
  .bulk-invoice-slot { height: auto !important; overflow: visible !important; margin-bottom: 1.5mm !important; page-break-inside: avoid !important; }
  /* Розділювач сторінок має бути буквально без власної висоти/полів — інакше сам
     переносить наступний рядок на порожню сторінку. */
  .bulk-page-break { page-break-after: always !important; height: 0 !important; margin: 0 !important; padding: 0 !important; border: none !important; line-height: 0 !important; }
  .bulk-page-break::after { content: none !important; }

  .bulk-invoice-slot .invoice-head .org, .bulk-invoice-slot .invoice-head .period { padding: 2px 8px !important; }
  .bulk-invoice-slot .invoice-row { grid-template-columns: 100px 1fr !important; }
  .bulk-invoice-slot .invoice-row > div { padding: 1px 8px !important; }
  .bulk-invoice-slot .invoice-table th, .bulk-invoice-slot .invoice-table td { padding: 1px 4px !important; }
  .bulk-invoice-slot .invoice-total { padding: 2px 8px !important; font-size: 1.05em !important; }
  .bulk-invoice-slot .invoice-note { padding: 1px 8px !important; font-size: .68em !important; line-height: 1.15 !important; }
  .bulk-invoice-slot .invoice-footer { padding: 2px 8px !important; gap: 8px !important; align-items: center !important; }
  .bulk-invoice-slot .invoice-footer .req { font-size: 1em !important; line-height: 1.25 !important; }
  .bulk-invoice-slot .qr-box { padding: 2px !important; border-radius: 4px !important; flex: none !important; }
  .bulk-invoice-slot .qr-box svg { width: 62px !important; height: 62px !important; display: block !important; }

  @page { size: A4 portrait; margin: 7mm; }
}

/* ---------- Кнопка «Оплатити» в кабінеті абонента ---------- */
.pay-block { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.pay-qr { background: #fff; padding: 10px; border-radius: 12px; box-shadow: var(--shadow-sm); flex: none; line-height: 0; }
.pay-details { flex: 1; min-width: 220px; }

/* ---------- Масовий друк квитанцій ---------- */
.bulk-invoice-sheet { max-width: 800px; margin: 0 auto; }
.bulk-invoice-slot { margin-bottom: 18px; }
.bulk-invoice-slot .invoice { font-size: 12px; }
.bulk-page-break { border-top: 2px dashed #b8b8b8; margin: 4px 0 22px; position: relative; }
.bulk-page-break::after { content: "— розрив сторінки при друку —"; position: absolute; top: -9px; left: 50%; transform: translateX(-50%); background: var(--surface, #fff); padding: 0 8px; font-size: .72rem; color: var(--text-faint, #888); }

/* ---------- Рахунок / Акт надання послуг (юрособи) ---------- */
.legal-doc { background: #fff; color: #0a0a0a; max-width: 800px; margin: 0 auto; font-size: 13px; padding: 24px 28px; }
.legal-doc h2 { font-size: 1.15em; margin: 0 0 4px; }
.legal-doc-num { font-weight: 700; }
.legal-doc-req { font-size: .82em; line-height: 1.5; border: 1px solid #0a0a0a; padding: 10px 12px; margin-bottom: 14px; white-space: pre-line; }
.legal-doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.legal-doc-party { border: 1px solid #0a0a0a; padding: 8px 12px; font-size: .85em; }
.legal-doc-party .role { font-weight: 700; text-transform: uppercase; font-size: .78em; margin-bottom: 4px; }
.legal-doc-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: .85em; }
.legal-doc-table th, .legal-doc-table td { border: 1px solid #0a0a0a; padding: 6px 8px; text-align: center; }
.legal-doc-table td:nth-child(2) { text-align: left; }
.legal-doc-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; margin-bottom: 10px; font-size: .92em; }
.legal-doc-totals .grand { font-weight: 800; font-size: 1.1em; }
.legal-doc-words { font-size: .88em; font-style: italic; border-top: 1px solid #0a0a0a; padding-top: 8px; margin-bottom: 16px; }
.legal-doc-note { font-size: .82em; margin-bottom: 22px; }
.legal-doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.legal-doc-sign-block { font-size: .85em; }
.legal-doc-sign-line { margin-top: 34px; border-top: 1px solid #0a0a0a; padding-top: 4px; display: flex; justify-content: space-between; gap: 10px; }
.legal-doc-sign-line span { font-size: .78em; color: #444; }
.legal-doc-mp { margin-top: 6px; font-size: .78em; color: #444; }
.legal-doc-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }

/* ---------- Утиліти ---------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-0 { margin-top: 0 !important; } .mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-dim { color: var(--text-dim); } .text-faint { color: var(--text-faint); }
.text-right { text-align: right; } .text-center { text-align: center; }
.w-full { width: 100%; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-faint); }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.alert { padding: 12px 16px; border-radius: 10px; font-size: .88rem; margin-bottom: 16px; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.pill-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; width: fit-content; }
.pill-tabs a { padding: 7px 14px; border-radius: 9px; font-size: .85rem; font-weight: 600; color: var(--text-dim); }
.pill-tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 420px; padding: 36px; }
.login-logo { width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg, var(--brand), var(--accent)); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.6rem; margin: 0 auto 18px; box-shadow: var(--shadow-md); }

.qr-box { background: white; padding: 12px; border-radius: 12px; display: inline-block; box-shadow: var(--shadow-sm); }
