/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-ctl);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 13px; white-space: nowrap; transition: .15s ease;
}
.btn:hover { background: var(--primary-50); border-color: var(--primary-100); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--primary-700); border-color: var(--primary-700); color: #fff; }
.btn-primary:hover { background: var(--primary-800); border-color: var(--primary-800); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--primary-50); border-color: transparent; }
.btn-subtle { background: var(--primary-50); border-color: var(--primary-100); color: var(--primary-800); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-icon:hover { color: var(--text); background: var(--primary-50); }
.btn-icon.sm { width: 28px; height: 28px; }
.btn-block { width: 100%; }

/* Form controls */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field-label {
  font-size: 12px; font-weight: 600; color: var(--text-muted); letter-spacing: .01em;
}
.field .hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.45; }
.field .error-text { font-size: 12px; color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-ctl);
  background: var(--surface); color: var(--text); font-size: 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary-500); box-shadow: 0 0 0 3px var(--primary-100);
}
.input:disabled, .select:disabled { background: var(--primary-50); color: var(--text-muted); }
.textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input.mono, .money-input input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.input-invalid { border-color: var(--danger) !important; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox input, .radio input { width: 15px; height: 15px; accent-color: var(--primary-700); cursor: pointer; }
.search-input { position: relative; }
.search-input svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-faint); pointer-events: none; }
.search-input .input { padding-left: 33px; }
.money-input { position: relative; }
.money-input .prefix {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-family: var(--font-mono); font-size: 13px; pointer-events: none;
}
.money-input input { padding-left: 26px; text-align: right; }
.form-error {
  padding: 9px 12px; border-radius: 8px; background: var(--danger-bg); color: var(--danger);
  font-size: 12.5px; border: 1px solid #F6C9CE;
}
.segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--primary-50); border: 1px solid var(--border); gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px;
  font-size: 12.5px; font-weight: 550; color: var(--text-muted);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--primary-800); box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.segmented button.credit[aria-pressed="true"] { color: var(--success); }
.segmented button.debit[aria-pressed="true"] { color: var(--danger); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }
.card-header {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 650; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-card) var(--radius-card); }
.panel { padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Badges & chips */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 600; line-height: 1.7; white-space: nowrap;
  background: var(--primary-50); color: var(--primary-700); border: 1px solid var(--primary-100);
}
.badge-green { background: var(--success-bg); color: var(--success); border-color: #C6EAD9; }
.badge-red { background: var(--danger-bg); color: var(--danger); border-color: #F6C9CE; }
.badge-amber { background: var(--warning-bg); color: var(--warning); border-color: #F5E3B9; }
.badge-grey { background: #F1F4F9; color: var(--text-muted); border-color: var(--border); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-pill);
  background: #F1F4F9; border: 1px solid var(--border); font-size: 11px; color: var(--text-muted);
}
.chip button { border: 0; background: none; padding: 0; color: var(--text-faint); display: flex; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--primary-600); flex: none;
  letter-spacing: .02em;
}
.avatar.lg { width: 42px; height: 42px; font-size: 15px; border-radius: 12px; }
.avatar.sm { width: 24px; height: 24px; font-size: 9.5px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -7px; border: 2px solid var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* Tables */
.table-wrap { overflow: auto; border-radius: 0 0 var(--radius-card) var(--radius-card); }
.table { font-size: 13px; }
.table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s ease; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--primary-50); }
.table .right { text-align: right; }
.table .strong-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.table.compact tbody td { padding: 7px 12px; }
.table .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.table-empty td { padding: 36px 12px; text-align: center; color: var(--text-muted); }
.sort-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; display: inline-flex; gap: 4px; align-items: center; text-transform: inherit; letter-spacing: inherit; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pagination .pages { display: flex; align-items: center; gap: 6px; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  border: 0; background: none; padding: 10px 12px; font-size: 13px; font-weight: 550; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary-700); border-bottom-color: var(--primary-700); }
.tab .count { margin-left: 5px; font-size: 11px; color: var(--text-faint); }

/* Toolbar / filters */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .search-input { width: 260px; max-width: 100%; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .select, .filters .input { height: 34px; min-height: 34px; width: auto; min-width: 130px; font-size: 12.5px; }
.result-count { font-size: 12px; color: var(--text-muted); }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.stat-label { font-size: 11.5px; color: var(--text-muted); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.stat-label svg { width: 14px; height: 14px; color: var(--text-faint); }
.stat-value { font-size: 21px; font-weight: 650; letter-spacing: -.02em; font-family: var(--font-mono); font-variant-numeric: tabular-nums; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value.smaller { font-size: 18px; }
.stat-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.delta { font-weight: 600; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

/* Modal / slide-over */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 31, 68, .38);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade-in .15s ease;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 48px); overflow: auto;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop-in .15s ease;
}
.modal.lg { max-width: 760px; }
.modal.xl { max-width: 980px; }
.modal-header { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; }
.modal-header h2 { flex: 1; font-size: 16px; }
.modal-header .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-weight: 400; }
.modal-body { padding: 4px 20px 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; flex-wrap: wrap; }
.modal-footer .left { margin-right: auto; }
.slideover-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 31, 68, .32);
  display: flex; justify-content: flex-end; animation: fade-in .15s ease;
}
.slideover {
  width: 100%; max-width: 520px; height: 100%; background: var(--surface);
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: slide-in .18s ease;
}
.slideover.wide { max-width: 640px; }
.slideover-header { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.slideover-header h2 { flex: 1; font-size: 16px; }
.slideover-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.slideover-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface-2); flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.99); } }
@keyframes slide-in { from { transform: translateX(24px); opacity: .6; } }

/* Dropdown menus */
.dropdown { position: relative; }
.menu {
  position: absolute; z-index: 90; min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); animation: pop-in .12s ease;
}
.menu.right { right: 0; top: calc(100% + 6px); }
.menu.left { left: 0; top: calc(100% + 6px); }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px;
  border: 0; background: none; border-radius: 7px; text-align: left; font-size: 13px; color: var(--text);
}
.menu-item:hover { background: var(--primary-50); }
.menu-item.danger { color: var(--danger); }
.menu-item svg { width: 15px; height: 15px; color: var(--text-faint); }
.menu-item.danger svg { color: var(--danger); }
.menu-item[aria-checked="true"] { background: var(--primary-50); font-weight: 600; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.menu-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 7px 10px 4px; font-weight: 600; }

/* Toast */
.toast-region {
  position: fixed; z-index: 200; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px;
  background: var(--primary-900); color: #fff; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 13px; animation: toast-in .18s ease; line-height: 1.45;
}
.toast svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast button { margin-left: auto; border: 0; background: none; color: rgba(255,255,255,.7); padding: 0 0 0 6px; }
.toast.leaving { opacity: 0; transform: translateY(4px); transition: .18s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Empty / skeleton */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 44px 20px; gap: 8px;
}
.empty .icon-wrap {
  width: 46px; height: 46px; border-radius: 12px; background: var(--primary-50);
  display: flex; align-items: center; justify-content: center; color: var(--primary-500); margin-bottom: 4px;
}
.empty .icon-wrap svg { width: 22px; height: 22px; }
.empty h3 { font-size: 14px; }
.empty p { font-size: 12.5px; color: var(--text-muted); max-width: 340px; }
.skeleton { position: relative; overflow: hidden; background: #EEF2F8; border-radius: 6px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* Permission matrix */
.matrix-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.matrix { font-size: 12px; min-width: 620px; }
.matrix th, .matrix td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.matrix thead th { background: var(--surface-2); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
.matrix thead th:first-child { background: var(--surface-2); }
.matrix input { width: 14px; height: 14px; accent-color: var(--primary-700); }
.matrix tr.module-row td { background: var(--primary-50); font-weight: 600; }

/* Charts */
.chart { width: 100%; }
.chart svg { width: 100%; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; font-size: 11.5px; color: var(--text-muted); }
.chart-legend .dot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; margin-right: 5px; }
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 8px; }
.bar-chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 3px; min-width: 0; }
.bar-chart .bars { display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 100%; }
.bar-chart .bar { width: 45%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-chart .bar.income { background: var(--success); opacity: .85; }
.bar-chart .bar.expense { background: var(--danger); opacity: .75; }
.bar-chart .lbl { text-align: center; font-size: 9.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut { width: 128px; height: 128px; flex: none; }
.legend-list { display: flex; flex-direction: column; gap: 7px; font-size: 12px; flex: 1; min-width: 140px; }
.legend-list li { display: flex; align-items: center; gap: 7px; }
.legend-list .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.legend-list .val { margin-left: auto; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); }
.sparkline { width: 100%; height: 44px; }

/* Misc */
.kbd {
  font-family: var(--font-mono); font-size: 10.5px; padding: 1px 5px; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-muted);
  box-shadow: 0 1px 0 var(--border-strong);
}
.callout {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: 9px; font-size: 12.5px;
  background: var(--primary-50); border: 1px solid var(--primary-100); color: var(--primary-800);
}
.callout svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.callout.warn { background: var(--warning-bg); border-color: #F3E1B5; color: #7A5A16; }
.callout.danger { background: var(--danger-bg); border-color: #F6C9CE; color: #8F2230; }
.callout.success { background: var(--success-bg); border-color: #C6EAD9; color: #0C5B42; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.definition { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.definition:last-child { border-bottom: 0; }
.definition dt { color: var(--text-muted); }
.definition dd { margin: 0; font-weight: 550; text-align: right; }
.kpi-strip { display: flex; gap: 24px; flex-wrap: wrap; }
.kpi-strip .kpi { min-width: 120px; }
.kpi-strip .kpi .lbl { font-size: 11px; color: var(--text-muted); }
.kpi-strip .kpi .val { font-family: var(--font-mono); font-size: 15px; font-weight: 600; margin-top: 2px; }
.progress { height: 6px; border-radius: 999px; background: var(--primary-50); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--primary-500); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.split-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h3 { font-size: 14px; margin: 0; letter-spacing: -.01em; }
@media (max-width: 900px) { .split-2 { grid-template-columns: 1fr; } }

/* Filter bars, audit diffs */
.filter-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filter-bar .field { min-width: 140px; }
.filter-bar .field .select, .filter-bar .field .input { min-width: 140px; }
.activity-detail td { background: var(--surface-2); padding: 0 12px 12px !important; }
.activity-diff { padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.diff-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.diff-label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: 4px; }
.diff-grid pre { margin: 0; padding: 9px 10px; max-height: 220px; overflow: auto; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.btn-icon.open svg { transform: rotate(180deg); }
@media (max-width: 680px) { .diff-grid { grid-template-columns: 1fr; } }
