:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #697386;
  --line: #dfe4ec;
  --soft-line: #edf0f5;
  --surface: #ffffff;
  --canvas: #f5f7fb;
  --navy: #12284c;
  --navy-2: #203d70;
  --accent: #d5a11e;
  --accent-2: #0f8b8d;
  --danger: #c2413d;
  --success: #207a4e;
  --warning: #a06400;
  --shadow: 0 18px 45px rgba(28, 38, 63, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(18, 40, 76, 0.94), rgba(15, 139, 141, 0.82)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 34px);
}

.login-panel {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-lockup.compact {
  margin-bottom: 28px;
}

.crest {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--navy), var(--navy-2));
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
  border: 2px solid var(--accent);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: clamp(24px, 3vw, 34px);
}

h3 {
  font-size: 18px;
}

.form-stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.16);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 800;
  padding: 9px 13px;
}

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

.primary-button:hover {
  background: #0d1e39;
}

.secondary-button {
  background: #fff;
  color: var(--navy);
  border-color: var(--line);
}

.secondary-button:hover {
  border-color: var(--navy-2);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.ghost-button:hover {
  color: var(--ink);
  background: rgba(18, 40, 76, 0.07);
}

.danger-button {
  background: #fff;
  color: var(--danger);
  border-color: rgba(194, 65, 61, 0.34);
}

.icon-button {
  width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  min-height: 42px;
  text-align: left;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 10px 12px;
}

.nav-button:hover,
.nav-button.active {
  color: var(--navy);
  background: #eef4fb;
}

.sidebar-logout {
  margin-top: auto;
  justify-self: end;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}

.period-badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  display: none;
  max-width: min(360px, calc(100vw - 48px));
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 700;
}

.toast.show {
  display: block;
}

.content {
  display: grid;
  gap: 20px;
}

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

.stat-card,
.panel,
.table-shell,
.empty-state,
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 26px rgba(28, 38, 63, 0.06);
}

.stat-card {
  min-height: 118px;
  display: grid;
  align-content: space-between;
  padding: 16px;
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.stat-value {
  margin: 12px 0 0;
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 900;
}

.stat-foot {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.panel {
  padding: 18px;
}

.panel-header,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.branch-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.branch-metric {
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcff;
}

.branch-metric strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
}

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

.debt-item,
.payment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--soft-line);
}

.debt-item:first-child,
.payment-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.item-title {
  display: block;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.amount {
  font-weight: 900;
  color: var(--navy);
  white-space: nowrap;
}

.amount.danger {
  color: var(--danger);
}

.amount.success {
  color: var(--success);
}

.toolbar {
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-toolbar {
  align-items: flex-end;
  margin-bottom: 0;
}

.compact-field {
  min-width: 170px;
}

.compact-field input {
  min-height: 38px;
}

.search-input {
  width: min(320px, 100%);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  gap: 3px;
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 7px 10px;
}

.segmented button.active {
  color: #fff;
  background: var(--navy);
}

.table-shell {
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--soft-line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fbfcff;
}

td {
  font-size: 14px;
}

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

.row-title {
  font-weight: 900;
}

.row-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-paid,
.status-active,
.status-credit {
  background: rgba(32, 122, 78, 0.12);
  color: var(--success);
}

.status-partial {
  background: rgba(160, 100, 0, 0.13);
  color: var(--warning);
}

.status-unpaid,
.status-inactive {
  background: rgba(194, 65, 61, 0.11);
  color: var(--danger);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(8, 14, 28, 0.55);
}

.modal-panel {
  width: min(760px, 100%);
  max-height: min(92vh, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  overflow: auto;
  padding: 20px;
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.payment-history {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.settings-panel {
  max-width: 560px;
}

.settings-form {
  display: grid;
  gap: 14px;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.settings-section h4 {
  margin: 0;
  font-size: 15px;
}

.payment-history h4 {
  margin: 0 0 12px;
}

.loading {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

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

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand-lockup.compact {
    margin-bottom: 12px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-button {
    flex: 0 0 auto;
    min-width: 104px;
    text-align: center;
    white-space: nowrap;
  }

  .sidebar-logout {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .stats-grid,
  .branch-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .toolbar-group {
    align-items: stretch;
  }

  .toolbar-group,
  .toolbar-group > *,
  .primary-button,
  .secondary-button,
  .danger-button,
  .search-input {
    width: 100%;
  }

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