:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #d8dee6;
  --border-strong: #c5ced8;
  --text: #17212f;
  --muted: #657386;
  --navy: #13324f;
  --navy-2: #1f4b73;
  --accent: #0f766e;
  --danger: #b42318;
  --warning: #b25e09;
  --success: #137333;
  --shadow: 0 12px 28px rgba(20, 33, 46, 0.08);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.admin-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  color: #f7fafc;
  background: #10283f;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand,
.public-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #ffffff;
  background: var(--navy-2);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  flex: 0 0 auto;
}

.brand-mark img {
  display: block;
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.brand strong,
.public-brand strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
}

.brand small,
.public-brand small {
  display: block;
  margin-top: 3px;
  color: #b9c5d2;
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 4px;
}

.side-nav a,
.side-footer a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 40px;
  padding: 0 11px;
  color: #d9e2ec;
  border-radius: 7px;
}

.side-nav a i,
.side-footer a i {
  width: 18px;
  color: #9eb4c8;
  text-align: center;
}

.side-nav a.active,
.side-nav a:hover,
.side-footer a:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.side-nav a.active i,
.side-nav a:hover i {
  color: #ffffff;
}

.side-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 76px;
  padding: 14px 26px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.topbar h1,
.page-title h1 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.2;
  color: var(--text);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.breadcrumb a {
  color: var(--navy-2);
}

.user-menu {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  white-space: nowrap;
}

.user-name {
  color: var(--muted);
}

.content {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px 26px 42px;
}

.public-body {
  background: var(--bg);
}

.public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 0 28px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}

.public-brand {
  color: var(--text);
}

.public-brand .brand-mark {
  background: var(--navy);
}

.public-brand small {
  color: var(--muted);
}

.public-header nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.public-header nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
}

.public-main {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.page-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-title p {
  margin: 5px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.mt-16 {
  margin-top: 16px;
}

.mini-stats-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  min-height: 112px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card-danger {
  background: #fff7f6;
  border-color: #f2c6c2;
}

.stat-card-danger .stat-label,
.stat-card-danger .stat-value {
  color: #9f1d15;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  margin-top: 12px;
  font-size: 24px;
  font-weight: 750;
  color: var(--text);
}

.stat-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 16px;
}

.panel-body {
  padding: 16px;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 16px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table-wrap-static {
  overflow-x: visible;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: #455569;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  background: #f7f9fb;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table .cell-right,
.cell-right {
  text-align: right;
}

.data-table .cell-actions {
  white-space: nowrap;
  text-align: right;
}

.muted {
  color: var(--muted);
}

.strong {
  font-weight: 700;
}

.badge,
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-active,
.badge-paid,
.badge-income,
.role-superadmin {
  color: #0f5132;
  background: #dff3e7;
  border: 1px solid #b7e4c7;
}

.badge-left,
.badge-expense,
.badge-locked {
  color: #842029;
  background: #f8d7da;
  border: 1px solid #f1b9bf;
}

.badge-open,
.badge-partial,
.role-admin {
  color: #664d03;
  background: #fff3cd;
  border: 1px solid #ead889;
}

.badge-unpaid,
.badge-archived,
.role-viewer {
  color: #8f1d18;
  background: #fdebea;
  border: 1px solid #f2c1bd;
}

.cycle-history-table {
  min-width: 0;
}

.cycle-history-table th:first-child,
.cycle-history-table td:first-child {
  width: 58%;
}

.cycle-history-table .cell-main {
  min-width: 0;
}

.cycle-link,
.cycle-period {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
}

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
}

.btn {
  padding: 0 13px;
}

.icon-btn {
  width: 36px;
  padding: 0;
  color: var(--navy);
  background: #ffffff;
  border-color: var(--border);
}

.icon-btn.danger-icon {
  color: var(--danger);
}

.btn-primary {
  color: #ffffff;
  background: var(--navy-2);
  border-color: var(--navy-2);
}

.btn-secondary {
  color: var(--navy);
  background: #ffffff;
  border-color: var(--border-strong);
}

.btn-danger {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.btn-success {
  color: #ffffff;
  background: var(--success);
  border-color: var(--success);
}

.btn-small,
.icon-btn.btn-small {
  min-height: 30px;
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-btn.btn-small {
  width: 30px;
  padding: 0;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.filter-bar,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--border);
}

.filter-bar .wide,
.form-grid .wide {
  grid-column: span 2;
}

.field {
  display: grid;
  gap: 6px;
}

.checkbox-field {
  align-content: start;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.field-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.field label {
  color: #42526a;
  font-size: 12px;
  font-weight: 700;
}

.required-mark {
  color: var(--danger);
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--navy-2);
  box-shadow: 0 0 0 3px rgba(31, 75, 115, 0.12);
}

.form-actions,
.filter-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
}

.form-card {
  max-width: 980px;
}

.summary-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.summary-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.summary-list li:last-child {
  border-bottom: 0;
}

.progress-bar {
  height: 10px;
  overflow: hidden;
  background: #edf2f7;
  border-radius: 5px;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #ffffff;
}

.flash-success {
  color: #0f5132;
  background: #edf8f0;
  border-color: #b7e4c7;
}

.flash-error {
  color: #842029;
  background: #fff0f1;
  border-color: #f1b9bf;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #eef2f6;
}

.login-box {
  width: min(420px, 100%);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-header {
  padding: 22px;
  border-bottom: 1px solid var(--border);
}

.login-header h1 {
  margin: 14px 0 4px;
  font-size: 22px;
}

.login-header p {
  margin: 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.empty-state {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

pre {
  overflow: auto;
  padding: 12px;
  text-align: left;
  white-space: pre-wrap;
  background: #f7f9fb;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.confirm-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.confirm-dialog form,
.dialog-content {
  padding: 22px;
}

.dialog-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--warning);
  background: #fff3cd;
  border-radius: 8px;
}

.confirm-dialog h2 {
  margin: 14px 0 6px;
  font-size: 18px;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.payment-form {
  display: none;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) auto;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

tr.editing .payment-form {
  display: grid;
}

.payment-form .field {
  gap: 4px;
}

.payment-form .field input {
  min-height: 32px;
}

.nowrap {
  white-space: nowrap;
}

@media (max-width: 1120px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .filter-bar,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-wrap-static {
    overflow-x: auto;
  }

  .cycle-history-table {
    min-width: 620px;
  }
}

@media (max-width: 820px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .public-header,
  .page-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-menu,
  .public-header nav {
    flex-wrap: wrap;
  }

  .content,
  .public-main {
    padding: 18px 14px 32px;
  }
}

@media (max-width: 560px) {
  .stats-grid,
  .filter-bar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .filter-bar .wide,
  .form-grid .wide {
    grid-column: auto;
  }

  .payment-form {
    grid-template-columns: 1fr;
  }
}
