/* CRM and OA agent-run ledgers. The module is intentionally namespaced so it can be mounted independently. */
.arl-shell {
    --arl-ink: #1d2939;
    --arl-muted: #667085;
    --arl-border: #dfe5ee;
    --arl-soft: #f6f8fc;
    --arl-primary: #4656c9;
    --arl-primary-dark: #3443ad;
    color: var(--arl-ink);
    font-family: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

.arl-shell *,
.arl-detail-mask * {
    box-sizing: border-box;
}

.arl-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 18px;
    padding: 24px 26px;
    border: 1px solid #e2e7f0;
    border-radius: 18px;
    background: linear-gradient(135deg, #fff 0%, #f5f7ff 100%);
    box-shadow: 0 10px 30px rgba(30, 45, 80, .05);
}

.arl-eyebrow {
    margin-bottom: 7px;
    color: #596bdb;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.arl-hero h2 {
    margin: 0;
    font-size: clamp(22px, 2vw, 30px);
    line-height: 1.25;
    letter-spacing: -.02em;
}

.arl-hero p {
    max-width: 760px;
    margin: 9px 0 0;
    color: var(--arl-muted);
    font-size: 13px;
    line-height: 1.7;
}

.arl-trust {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 7px;
    max-width: 360px;
}

.arl-trust span {
    padding: 7px 10px;
    border: 1px solid #dce2f4;
    border-radius: 999px;
    background: rgba(255, 255, 255, .82);
    color: #526079;
    font-size: 11px;
    white-space: nowrap;
}

.arl-filter-card,
.arl-ledger-card {
    border: 1px solid var(--arl-border);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(31, 43, 68, .045);
}

.arl-filter-card {
    margin-bottom: 16px;
    padding: 18px 20px;
}

.arl-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
    align-items: end;
    gap: 12px;
}

.arl-filters label,
.arl-page-size {
    display: grid;
    gap: 7px;
    min-width: 0;
}

.arl-filters label > span,
.arl-page-size > span {
    color: #596579;
    font-size: 11px;
    font-weight: 750;
}

.arl-filters select,
.arl-filters input,
.arl-page-size select {
    width: 100%;
    min-height: 40px;
    padding: 0 11px;
    border: 1px solid #d5dce8;
    border-radius: 10px;
    outline: 0;
    background: #fff;
    color: #273347;
    font: inherit;
    font-size: 13px;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.arl-filters select:focus,
.arl-filters input:focus,
.arl-page-size select:focus {
    border-color: #7b88e4;
    box-shadow: 0 0 0 3px rgba(70, 86, 201, .12);
}

.arl-filter-actions {
    display: flex;
    gap: 8px;
}

.arl-button,
.arl-page-button,
.arl-link-button,
.arl-detail-close {
    border: 0;
    font: inherit;
    cursor: pointer;
}

.arl-button {
    min-height: 40px;
    padding: 0 15px;
    border: 1px solid #d4dbe7;
    border-radius: 10px;
    background: #fff;
    color: #354157;
    font-size: 13px;
    font-weight: 720;
    white-space: nowrap;
}

.arl-button:hover {
    border-color: #b9c3d5;
    background: #f8f9fc;
}

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

.arl-button--primary:hover {
    border-color: var(--arl-primary-dark);
    background: var(--arl-primary-dark);
}

.arl-ledger-card {
    min-height: 430px;
    overflow: hidden;
}

.arl-ledger-card > header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    min-height: 82px;
    padding: 20px 22px 17px;
    border-bottom: 1px solid #e5e9f0;
}

.arl-ledger-card > header h3 {
    margin: 0;
    font-size: 16px;
}

.arl-ledger-card > header p {
    margin: 6px 0 0;
    color: var(--arl-muted);
    font-size: 12px;
    line-height: 1.55;
}

.arl-ledger-card > header > strong {
    color: #4b5abc;
    font-size: 12px;
    white-space: nowrap;
}

.arl-table-scroll {
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.arl-table-scroll:focus-visible {
    outline: 3px solid rgba(70, 86, 201, .16);
    outline-offset: -3px;
}

.arl-table {
    width: 100%;
    min-width: 1040px;
    border-collapse: collapse;
    table-layout: fixed;
}

.arl-table th,
.arl-table td {
    padding: 14px 13px;
    border-bottom: 1px solid #e9edf3;
    text-align: left;
    vertical-align: middle;
    overflow-wrap: anywhere;
}

.arl-table th {
    background: #fafbfc;
    color: #697386;
    font-size: 11px;
    font-weight: 750;
    letter-spacing: .02em;
}

.arl-table th:nth-child(1) { width: 23%; }
.arl-table th:nth-child(2) { width: 17%; }
.arl-table th:nth-child(3) { width: 11%; }
.arl-table th:nth-child(4) { width: 18%; }
.arl-table th:nth-child(5) { width: 13%; }
.arl-table th:nth-child(6) { width: 13%; }
.arl-table th:nth-child(7) { width: 8%; }

.arl-table tbody tr:hover {
    background: #fbfcff;
}

.arl-table td strong,
.arl-table td span,
.arl-table td small,
.arl-table td time {
    display: block;
}

.arl-table td strong,
.arl-table td time {
    color: #2c384b;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.45;
}

.arl-table td small,
.arl-primary-cell > span {
    margin-top: 4px;
    color: #7a8495;
    font-size: 10px;
    line-height: 1.45;
}

.arl-status {
    display: inline-flex !important;
    width: fit-content;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    padding: 5px 8px;
    border: 1px solid #dce1ea;
    border-radius: 999px;
    background: #f6f7f9;
    color: #566174;
    font-size: 10px;
    font-weight: 750;
    line-height: 1;
    white-space: nowrap;
}

.arl-status i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.arl-status--success { border-color: #bee4d0; background: #eefaf3; color: #17814d; }
.arl-status--danger { border-color: #f0c9ca; background: #fff3f3; color: #b33b42; }
.arl-status--progress { border-color: #c7d8f5; background: #f1f6ff; color: #3169b3; }
.arl-status--warning { border-color: #eed7aa; background: #fff9ec; color: #9a6516; }

.arl-link-button {
    padding: 7px 9px;
    border-radius: 8px;
    background: #eef1ff;
    color: #4050bc;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.arl-link-button:hover {
    background: #e2e7ff;
}

.arl-link-button:disabled,
.arl-page-button:disabled,
.arl-button:disabled {
    cursor: not-allowed;
    opacity: .48;
}

.arl-state {
    display: flex;
    min-height: 290px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 20px;
    text-align: center;
}

.arl-state strong {
    margin-top: 12px;
    font-size: 15px;
}

.arl-state p {
    max-width: 520px;
    margin: 7px 0 16px;
    color: var(--arl-muted);
    font-size: 12px;
    line-height: 1.65;
}

.arl-state-icon {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 50%;
    background: #f1f3f9;
    color: #657087;
    font-size: 20px;
    font-weight: 800;
}

.arl-state--error .arl-state-icon {
    background: #fff0f0;
    color: #bd4046;
}

.arl-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #e0e4f6;
    border-top-color: var(--arl-primary);
    border-radius: 50%;
    animation: arl-spin .8s linear infinite;
}

@keyframes arl-spin { to { transform: rotate(360deg); } }

.arl-pagination {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 12px 18px;
    border-top: 1px solid #e5e9f0;
    background: #fcfcfd;
}

.arl-pagination p {
    margin: 0;
    color: #6c7687;
    font-size: 11px;
}

.arl-page-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.arl-page-button {
    min-width: 32px;
    height: 32px;
    padding: 0 9px;
    border: 1px solid #d9dfe9;
    border-radius: 8px;
    background: #fff;
    color: #505c70;
    font-size: 11px;
}

.arl-page-button:hover:not(:disabled),
.arl-page-button.is-current {
    border-color: #8995e4;
    background: #eef0ff;
    color: #3e4db4;
}

.arl-page-gap {
    padding: 0 3px;
    color: #9098a7;
}

.arl-page-size {
    grid-template-columns: auto 82px;
    align-items: center;
    justify-content: end;
}

.arl-page-size select {
    min-height: 34px;
}

.arl-detail-mask {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(21, 28, 43, .48);
    backdrop-filter: blur(3px);
}

.arl-detail {
    display: flex;
    width: min(820px, calc(100vw - 36px));
    max-height: calc(100dvh - 36px);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e0e5ee;
    border-radius: 18px;
    background: #fff;
    color: #263247;
    font-family: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    box-shadow: 0 30px 100px rgba(20, 28, 45, .3);
}

.arl-detail > header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 21px 24px 17px;
    border-bottom: 1px solid #e3e7ee;
}

.arl-detail > header h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.35;
}

.arl-detail > header p {
    margin: 6px 0 0;
    color: #707b8e;
    font-size: 11px;
}

.arl-detail-close {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 9px;
    background: #f3f5f8;
    color: #5b6678;
    font-size: 22px;
    line-height: 1;
}

.arl-detail-close:hover {
    background: #e9ecf2;
}

.arl-detail-tabs {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 9px 20px;
    overflow-x: auto;
    border-bottom: 1px solid #e4e8ef;
    background: #fafbfc;
}

.arl-detail-tabs button {
    padding: 8px 13px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #626e82;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}

.arl-detail-tabs button[aria-selected="true"] {
    background: #e9edff;
    color: #3d4cb3;
}

.arl-detail-tabs button:focus-visible,
.arl-detail-close:focus-visible,
.arl-button:focus-visible,
.arl-page-button:focus-visible,
.arl-link-button:focus-visible {
    outline: 3px solid rgba(70, 86, 201, .2);
    outline-offset: 2px;
}

.arl-detail-body {
    min-height: 310px;
    padding: 22px 24px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.arl-detail-body [hidden] {
    display: none;
}

.arl-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
}

.arl-facts > div {
    min-width: 0;
    padding: 13px 14px;
    border: 1px solid #e2e7ef;
    border-radius: 11px;
    background: #fafbfc;
}

.arl-facts > div.is-wide {
    grid-column: 1 / -1;
}

.arl-facts dt {
    margin-bottom: 6px;
    color: #798396;
    font-size: 10px;
    font-weight: 700;
}

.arl-facts dd {
    margin: 0;
    color: #2f3b4e;
    font-size: 12px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.arl-audit-note {
    margin-bottom: 14px;
    padding: 13px 15px;
    border: 1px solid #d5ddef;
    border-radius: 11px;
    background: #f5f7fc;
}

.arl-audit-note strong {
    font-size: 12px;
}

.arl-audit-note p {
    margin: 5px 0 0;
    color: #657187;
    font-size: 11px;
    line-height: 1.65;
}

.arl-detail > footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding: 13px 24px;
    border-top: 1px solid #e1e6ed;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 -8px 22px rgba(25, 39, 66, .05);
}

.arl-detail > footer span {
    margin-right: auto;
    color: #7a8494;
    font-size: 10px;
}

@media (max-width: 1080px) {
    .arl-filters { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    .arl-filter-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

@media (max-width: 720px) {
    .arl-hero { display: block; padding: 20px; border-radius: 14px; }
    .arl-trust { justify-content: flex-start; max-width: none; margin-top: 16px; }
    .arl-filter-card { padding: 15px; }
    .arl-filters { grid-template-columns: 1fr; }
    .arl-filter-actions { grid-column: auto; }
    .arl-filter-actions .arl-button { flex: 1; }
    .arl-ledger-card { min-height: 380px; border-radius: 14px; }
    .arl-ledger-card > header { min-height: 0; padding: 17px; }
    .arl-table-scroll { overflow: visible; }
    .arl-table { min-width: 0; table-layout: auto; }
    .arl-table thead { display: none; }
    .arl-table tbody,
    .arl-table tr,
    .arl-table td { display: block; width: 100%; }
    .arl-table tbody { padding: 12px; }
    .arl-table tr { margin-bottom: 12px; padding: 5px 13px; border: 1px solid #e1e6ee; border-radius: 12px; background: #fff; }
    .arl-table tr:last-child { margin-bottom: 0; }
    .arl-table td { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-bottom: 1px solid #edf0f4; }
    .arl-table td::before { content: attr(data-label); color: #7a8496; font-size: 10px; font-weight: 750; }
    .arl-table td:last-child { border-bottom: 0; }
    .arl-table td > * { min-width: 0; }
    .arl-pagination { grid-template-columns: 1fr; justify-items: center; }
    .arl-pagination p { text-align: center; }
    .arl-page-controls { max-width: 100%; flex-wrap: wrap; }
    .arl-page-size { justify-content: center; }
    .arl-detail-mask { padding: 8px; }
    .arl-detail { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); border-radius: 14px; }
    .arl-detail > header,
    .arl-detail-body { padding: 17px; }
    .arl-detail-tabs { justify-content: flex-start; }
    .arl-facts { grid-template-columns: 1fr; }
    .arl-facts > div.is-wide { grid-column: auto; }
    .arl-detail > footer { padding: 12px 17px; }
}

@media (prefers-reduced-motion: reduce) {
    .arl-spinner { animation: none; }
    .arl-filters select,
    .arl-filters input,
    .arl-page-size select { transition: none; }
}
