:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1f2937;
  --muted: #667085;
  --brand: #146c66;
  --brand-strong: #0f4f4b;
  --danger: #b42318;
  --warning: #b54708;
  --info: #175cd3;
  --ok: #067647;
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, sans-serif;
  overflow-x: hidden;
}
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
.app-shell { min-height: 100vh; display: flex; width: 100%; max-width: 100vw; }
.sidebar-backdrop { display: none; }
.sidebar {
  width: 232px;
  background: #101828;
  color: white;
  padding: 18px 14px;
  flex: 0 0 auto;
  transition: width .18s ease, transform .18s ease;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 12px;
}
.brand-link {
  display: grid;
  min-width: 0;
  color: white;
}
.brand-link:hover { text-decoration: none; }
.brand span { color: #9fb6b3; font-size: 12px; }
.nav { display: grid; gap: 4px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e6eaef;
  padding: 9px 10px;
  border-radius: 6px;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,.10); text-decoration: none; }
.nav a.active { color: white; box-shadow: inset 3px 0 0 #7cd4ca; }
.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 6px;
  background: rgba(255,255,255,.06);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.app-shell.sidebar-collapsed .sidebar { width: 76px; padding-left: 10px; padding-right: 10px; }
.app-shell.sidebar-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.app-shell.sidebar-collapsed .brand-link span,
.app-shell.sidebar-collapsed .brand-link strong,
.app-shell.sidebar-collapsed .nav-label { display: none; }
.app-shell.sidebar-collapsed .nav a { justify-content: center; padding-left: 6px; padding-right: 6px; }
.app-shell.sidebar-collapsed .nav a.active { box-shadow: inset 0 -3px 0 #7cd4ca; }
.main { flex: 1; min-width: 0; max-width: 100%; padding: 22px; overflow-x: clip; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.topbar-main { display: grid; gap: 8px; min-width: 0; }
.topbar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
.topbar form, .topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.breadcrumbs ol {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0;
  margin: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
}
.breadcrumbs li {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}
.breadcrumbs li + li::before {
  content: "/";
  margin-right: 5px;
  color: #98a2b3;
}
.breadcrumbs a {
  color: var(--muted);
  font-weight: 700;
}
.breadcrumbs span[aria-current="page"] {
  color: var(--text);
  font-weight: 800;
}
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--brand); color: var(--brand-strong); }
.sidebar .icon-button {
  width: 30px;
  min-width: 30px;
  height: 30px;
  border-color: rgba(255,255,255,.16);
  background: rgba(255,255,255,.08);
  color: white;
}
.collapse-mark::before {
  content: "<";
  display: block;
  font-weight: 900;
}
.app-shell.sidebar-collapsed .collapse-mark::before { content: ">"; }
.hamburger-mark {
  display: grid;
  gap: 4px;
}
.hamburger-mark span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}
.mobile-nav-toggle { display: none; }
.panel, .auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
  max-width: 100%;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  min-width: 0;
  flex-wrap: wrap;
}
.panel-header > * { min-width: 0; }
.panel-header h2, .panel h2 { margin: 0; font-size: 18px; }
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 6px; font-size: 22px; }
.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; min-width: 0; }
.split > * { min-width: 0; }
.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  scrollbar-gutter: stable;
  border-radius: 6px;
}
.table-wrap:focus-within {
  outline: 2px solid rgba(20, 108, 102, .18);
  outline-offset: 2px;
}
.table { width: 100%; min-width: 100%; border-collapse: collapse; background: white; }
.table th, .table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}
.table th { color: var(--muted); font-size: 12px; font-weight: 700; background: #f8fafc; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  background: white;
}
textarea { min-height: 92px; resize: vertical; }
label { display: grid; gap: 5px; color: var(--muted); font-weight: 600; }
.inline-field {
  width: auto;
  min-width: 150px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-stack { display: grid; gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; }
.repeat-section {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.repeat-section h2 { margin: 0; font-size: 16px; }
.repeat-list { display: grid; gap: 12px; }
.repeat-row {
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}
.repeat-remove { align-self: end; justify-self: start; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: white;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}
.button-sm {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}
.button:hover { background: var(--brand-strong); text-decoration: none; }
.button-muted {
  background: white;
  color: var(--text);
  border-color: var(--line);
}
.button-danger { background: var(--danger); border-color: var(--danger); }
.button-warning {
  background: #f79009;
  border-color: #f79009;
  color: #111827;
}
.button-warning:hover {
  background: #dc6803;
  border-color: #dc6803;
  color: #111827;
}
.alert {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: white;
}
.alert-success { border-color: #abefc6; color: var(--ok); }
.alert-danger { border-color: #fecdca; color: var(--danger); }
.toast-stack {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 1000;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 28px));
}
.toast {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 16px 36px rgba(16, 24, 40, .18);
  transition: opacity .18s ease, transform .18s ease;
}
.toast span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}
.toast button {
  width: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}
.toast-success { border-left-color: var(--ok); }
.toast-danger { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info { border-left-color: var(--info); }
.toast.is-hiding {
  opacity: 0;
  transform: translateY(-6px);
}
.is-busy {
  opacity: .78;
}
.is-busy button,
.is-busy input[type="submit"] {
  cursor: progress;
}
.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #eef2f6;
  color: var(--muted);
  white-space: nowrap;
}
.badge-ok { background: #dcfae6; color: var(--ok); }
.badge-danger { background: #fee4e2; color: var(--danger); }
.badge-warning { background: #fef0c7; color: var(--warning); }
.badge-info { background: #d1e9ff; color: var(--info); }
.badge-muted { background: #eef2f6; color: var(--muted); }
.details { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; margin: 0; }
.details dt { color: var(--muted); font-weight: 700; }
.details dd { margin: 0; }
.auth-panel { min-height: 100vh; display: grid; place-items: center; width: 100%; }
.auth-card { width: min(420px, 92vw); }
.auth-card h1 { margin-top: 0; }
.pagination { display: flex; gap: 5px; margin-top: 12px; }
.pagination a { border: 1px solid var(--line); padding: 6px 10px; border-radius: 6px; background: white; }
.pagination a.active { background: var(--brand); color: white; border-color: var(--brand); }
.nowrap { white-space: nowrap; }
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-height: 24px;
  margin-right: 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f8fafc;
  color: var(--muted);
  cursor: grab;
  font-weight: 800;
  letter-spacing: -2px;
  touch-action: none;
  user-select: none;
}
.is-sorting,
.is-sorting * {
  cursor: grabbing !important;
}
.is-dragging {
  opacity: .55;
  outline: 2px solid var(--brand);
}
.sort-saved {
  box-shadow: inset 0 0 0 2px #abefc6;
}
.sort-error {
  box-shadow: inset 0 0 0 2px #fecdca;
}
.legacy-summary { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-width: 0; max-width: 100%; }
.legacy-summary .table { margin: 0; }
.legacy-summary-title {
  background: var(--brand-strong);
  color: white;
  padding: 10px 12px;
  font-weight: 800;
}
.legacy-group-list {
  display: grid;
  gap: 14px;
  min-width: 0;
}
.legacy-project-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
  min-width: 0;
  max-width: 100%;
}
.legacy-project-block h3 {
  margin: 0 0 10px;
  font-size: 17px;
  color: var(--muted);
  max-width: 100%;
  overflow-wrap: anywhere;
}
.legacy-credit-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}
.legacy-credit-heading h2 { margin: 0; font-size: 26px; }
.legacy-credit-heading p { margin: 3px 0 0; color: var(--muted); }
.legacy-credit-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.legacy-credit-card { margin-bottom: 0; }
.legacy-credit-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}
.progress {
  height: 20px;
  overflow: hidden;
  border-radius: 6px;
  background: #e4e7ec;
  margin: 10px 0 14px;
}
.progress span {
  display: block;
  min-width: 34px;
  height: 100%;
  background: var(--brand);
  color: white;
  font-size: 12px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}
.summary-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.summary-line:first-of-type { border-top: 0; }
.summary-line.danger { color: var(--danger); }
.switch-inline, .checkbox-inline {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  width: auto;
  color: var(--text);
  font-weight: 600;
}
.switch-inline input, .checkbox-inline input {
  width: auto;
}
.bulk-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.table-sticky {
  max-height: calc(100vh - 260px);
  overflow: auto;
}
.table-sticky thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.legacy-credit-table th,
.legacy-credit-table td {
  white-space: nowrap;
  vertical-align: middle;
}
.extra-payment-row td {
  background: #fffbeb;
}
.muted { color: var(--muted); }
.state-icon {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  vertical-align: middle;
}
.state-ok { background: var(--ok); }
.state-info { background: var(--info); }
.state-warning { background: #f79009; }
.state-danger { background: var(--danger); }
.action-menu {
  position: relative;
  display: inline-block;
}
.action-menu summary {
  list-style: none;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-weight: 700;
}
.action-menu summary::-webkit-details-marker { display: none; }
.action-menu[open] summary {
  border-color: var(--brand);
}
.action-menu > div {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 5;
  display: grid;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 14px 30px rgba(16, 24, 40, .16);
}
.action-menu a,
.action-menu button {
  width: 100%;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  padding: 8px;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.action-menu a:hover,
.action-menu button:hover {
  background: #f2f4f7;
  text-decoration: none;
}
.action-menu hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  margin: 5px 0;
}
.danger-link { color: var(--danger) !important; }
.modal {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
}
.modal::backdrop {
  background: rgba(16, 24, 40, .45);
}
.modal form {
  display: grid;
  gap: 14px;
  padding: 16px;
}
.modal header,
.modal footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal header h3 { margin: 0; }
.modal header button {
  width: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.modal footer { justify-content: flex-end; }
.modal-summary {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}
.modal-summary div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.payment-form-panel h2 { margin-top: 0; }
.legacy-form-card {
  max-width: 620px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: white;
}
.legacy-form-wide {
  max-width: 840px;
}
.legacy-detail-list {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}
.message-preview {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #ffffff;
  color: var(--text);
  font-weight: 400;
}
.message-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}
.message-preview th,
.message-preview td {
  border-bottom: 1px solid var(--line);
  padding: 7px;
  text-align: left;
}
@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(304px, 86vw);
    height: 100vh;
    overflow-y: auto;
    transform: translateX(-100%);
    box-shadow: 18px 0 42px rgba(16, 24, 40, .28);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-visible {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(16, 24, 40, .42);
  }
  body.sidebar-mobile-open { overflow: hidden; }
  .sidebar-collapse-toggle { display: none; }
  .nav { grid-template-columns: 1fr; }
  .main { padding: 14px; }
  .panel { padding: 12px; }
  .topbar {
    display: grid;
    gap: 12px;
  }
  .topbar-main { gap: 10px; }
  .topbar-tools .button span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .topbar-user {
    justify-content: space-between;
    width: 100%;
  }
  .mobile-nav-toggle { display: inline-flex; }
  .split { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .details { grid-template-columns: 1fr; }
  .legacy-credit-summary { grid-template-columns: 1fr; }
  .legacy-credit-heading { display: block; }
  .table-wrap {
    margin-left: 0;
    margin-right: 0;
    padding-bottom: 4px;
  }
  .table-wrap .table {
    width: max-content;
    min-width: 100%;
  }
  .table-wrap .table th,
  .table-wrap .table td {
    white-space: nowrap;
  }
  .table-wrap .table td.wrap-cell,
  .table-wrap .table th.wrap-cell {
    white-space: normal;
    min-width: 220px;
  }
  .table-sticky {
    max-height: calc(100vh - 220px);
    overflow: auto;
  }
  .legacy-project-block {
    padding: 10px;
  }
  .legacy-project-block h3 {
    font-size: 15px;
    line-height: 1.35;
  }
}
