/* Reuse Profit & Loss visual system for Cashbook page */
/* ═══════════════════════════════════════════════════════
   Profit & Loss Statement — Modern Compact Design
   ═══════════════════════════════════════════════════════ */

.pnl-wrap {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 100%;
    background: #f0f2f8;
    font-size: 0.78rem;
    color: #1a1f36;
}

/* ── Top bar ── */
.pnl-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #1e2d5a 0%, #2e4494 100%);
    color: #fff;
    padding: 0.45rem 1rem;
    gap: 1rem;
    box-shadow: 0 2px 6px rgba(0,0,0,.18);
    position: relative;
    flex-shrink: 0;
    z-index: 2;
    flex-wrap: wrap;
}
.pnl-topbar-left { display: flex; align-items: center; gap: 0.55rem; }
.pnl-topbar-icon { font-size: 1.15rem; opacity: 0.85; }
.pnl-topbar-title { display: block; font-size: 0.88rem; font-weight: 700; letter-spacing: 0.01em; }
.pnl-topbar-sub   { display: block; font-size: 0.62rem; opacity: 0.7; margin-top: 0.05rem; }

.pnl-top-actions { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }

.pnl-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    padding: 0.26rem 0.75rem;
    border: none;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .14s, background .14s;
    white-space: nowrap;
}
.pnl-btn--back  { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.pnl-btn--back:hover  { background: rgba(255,255,255,.25); color: #fff; }
.pnl-btn--print { background: #4b5563; color: #fff; }
.pnl-btn--print:hover { opacity: 0.85; }
.pnl-btn--pdf   { background: #dc2626; color: #fff; }
.pnl-btn--pdf:hover { opacity: 0.85; }
.pnl-btn--excel { background: #16a34a; color: #fff; }
.pnl-btn--excel:hover { opacity: 0.85; }

/* ── Body ── */
.pnl-body {
    flex: 1 1 auto;
    position: relative;
    z-index: 1;
    padding: 0.65rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* ── Filter card ── */
.pnl-filter-card {
    background: #fff;
    border: 1px solid #e2e7f3;
    border-radius: 8px;
    padding: 0.55rem 0.85rem;
    box-shadow: 0 1px 3px rgba(30,45,90,.05);
}
.pnl-filter-row {
    display: flex;
    align-items: flex-end;
    gap: 0.85rem;
    flex-wrap: wrap;
}
.pnl-field-group { display: flex; flex-direction: column; gap: 0.18rem; }
.pnl-field-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #8492b4;
}
.pnl-field-wrap {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid #d8dff0;
    border-radius: 6px;
    padding: 0 0.45rem;
    background: #f7f9fd;
    min-height: 1.8rem;
    min-width: 120px;
}
.pnl-field-ico { font-size: 0.72rem; color: #8492b4; flex-shrink: 0; }
.pnl-field-input {
    border: none;
    background: transparent;
    font-size: 0.78rem;
    color: #1a1f36;
    width: 80px;
    outline: none;
    padding: 0.1rem 0;
}
.pnl-field-input::-webkit-inner-spin-button,
.pnl-field-input::-webkit-outer-spin-button { -webkit-appearance: none; }

.pnl-gen-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.32rem 1rem;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity .14s;
    white-space: nowrap;
    min-height: 1.8rem;
}
.pnl-gen-btn:hover:not(:disabled) { opacity: 0.88; }
.pnl-gen-btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── KPI strip ── */
.pnl-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}
@media (max-width: 900px) { .pnl-kpi-strip { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .pnl-kpi-strip { grid-template-columns: 1fr; } }

.pnl-kpi {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: #fff;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e7f3;
    box-shadow: 0 1px 3px rgba(30,45,90,.05);
    position: relative;
    overflow: hidden;
}
.pnl-kpi::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    border-radius: 3px 0 0 3px;
}
.pnl-kpi--revenue::before { background: #2e4494; }
.pnl-kpi--cogs::before    { background: #dc2626; }
.pnl-kpi--gross::before   { background: #0891b2; }
.pnl-kpi--profit::before  { background: #16a34a; }
.pnl-kpi--loss::before    { background: #dc2626; }

.pnl-kpi-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    opacity: 0.75;
}
.pnl-kpi--revenue .pnl-kpi-icon { color: #2e4494; }
.pnl-kpi--cogs    .pnl-kpi-icon { color: #dc2626; }
.pnl-kpi--gross   .pnl-kpi-icon { color: #0891b2; }
.pnl-kpi--profit  .pnl-kpi-icon { color: #16a34a; }
.pnl-kpi--loss    .pnl-kpi-icon { color: #dc2626; }

.pnl-kpi-body { display: flex; flex-direction: column; gap: 0.04rem; min-width: 0; }
.pnl-kpi-label {
    font-size: 0.59rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #8492b4;
    white-space: nowrap;
}
.pnl-kpi-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: #1a1f36;
    white-space: nowrap;
}

/* ── Report card ── */
.pnl-report-card {
    background: #fff;
    border: 1px solid #e2e7f3;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(30,45,90,.06);
    overflow: hidden;
}

/* ── States ── */
.pnl-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 3rem 2rem;
    color: #8492b4;
    text-align: center;
}
.pnl-state--loading { gap: 0.6rem; }
.pnl-state-icon { font-size: 2rem; opacity: 0.4; }
.pnl-state-title { font-size: 0.85rem; font-weight: 600; color: #4b5563; }
.pnl-state-sub { font-size: 0.72rem; color: #9ca3af; }

.pnl-spinner {
    width: 1.4rem;
    height: 1.4rem;
    border: 2px solid #e2e7f3;
    border-top-color: #2e4494;
    border-radius: 50%;
    animation: pnl-spin .7s linear infinite;
}
.pnl-spinner-sm {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: pnl-spin .7s linear infinite;
}
@keyframes pnl-spin { to { transform: rotate(360deg); } }

/* ── Print header ── */
.pnl-print-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.9rem 0.5rem;
    border-bottom: 2px solid #e2e7f3;
    gap: 1rem;
    flex-wrap: wrap;
}
.pnl-print-company { display: flex; align-items: center; gap: 0.6rem; }
.pnl-print-logo {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #e2e7f3;
    flex-shrink: 0;
}
.pnl-print-name { font-size: 0.88rem; font-weight: 700; color: #1a1f36; }
.pnl-print-sub  { font-size: 0.62rem; color: #8492b4; margin-top: 0.05rem; }

.pnl-print-meta {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    text-align: right;
    font-size: 0.62rem;
    color: #8492b4;
}

/* ── Table ── */
.pnl-table-wrap { overflow-x: auto; }

.pnl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.68rem;
    line-height: 1.15;
}

.pnl-table thead tr {
    background: linear-gradient(135deg, #1e2d5a 0%, #2e4494 100%);
    position: sticky;
    top: 0;
    z-index: 2;
}
.pnl-table thead th {
    padding: 0.28rem 0.4rem;
    font-size: 0.56rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.055em;
    color: rgba(255,255,255,.85);
    white-space: nowrap;
    border: none;
}
.pnl-th-label { text-align: left; min-width: 200px; width: 22%; position: sticky; left: 0; background: linear-gradient(135deg, #1e2d5a 0%, #2e4494 100%); z-index: 3; }
.pnl-th-total { text-align: right; min-width: 80px; background: rgba(255,255,255,.08); }

/* Row types */
.pnl-table tbody tr { border-bottom: 1px solid #f0f3fa; }
.pnl-table tbody tr:last-child { border-bottom: none; }

.pnl-tr--data td { padding: 0.18rem 0.4rem; }
.pnl-tr--data:hover { background: #f7f9fd; }

.pnl-tr--subtotal {
    background: #eff6ff;
}
.pnl-tr--subtotal td {
    padding: 0.2rem 0.4rem;
    font-weight: 700;
    border-top: 1px solid #bfdbfe;
    border-bottom: 1px solid #bfdbfe;
}

.pnl-tr--grand {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
}
.pnl-tr--grand td {
    padding: 0.24rem 0.4rem;
    font-weight: 800;
    font-size: 0.75rem;
    border-top: 2px solid #16a34a;
    border-bottom: 2px solid #16a34a;
    color: #14532d;
}

/* Cells */
.pnl-td-label {
    white-space: nowrap;
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 1;
    min-width: 200px;
}
.pnl-td-total { text-align: right; white-space: nowrap; font-weight: 600; background: #fafbfe; }
.pnl-label-leaf { color: #374151; }

/* Cashbook extensions */
.pnl-field-wrap--date { min-width: 260px; padding: 0 0.5rem; }
.pnl-date-input { width: 100%; min-width: 180px; }
.cb-kpi-strip .pnl-kpi-val { font-size: 0.9rem; }

.pnl-tr--expandable .pnl-td-label { display: flex; align-items: center; gap: 0.35rem; }
.cb-expand-btn {
    width: 18px; height: 18px; flex-shrink: 0;
    border: 1px solid #cbd5e1; border-radius: 4px;
    background: #fff; color: #2e4494;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.62rem; cursor: pointer; padding: 0;
    transition: background .12s, border-color .12s;
}
.cb-expand-btn:hover { background: #eff6ff; border-color: #93c5fd; }
.cb-expand-spacer { width: 18px; flex-shrink: 0; display: inline-block; }
.cb-acct-count { font-size: 0.58rem; color: #94a3b8; font-weight: 500; margin-left: 0.15rem; }

.cb-detail-hidden { display: none !important; }
tr.cb-detail-hidden { display: none !important; }

/* Smart grid toolbar */
.cb-grid-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.45rem 0.65rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e7f3;
}
.cb-grid-search-wrap {
    position: relative;
    flex: 1;
    min-width: 160px;
    max-width: 280px;
}
.cb-grid-search-wrap i {
    position: absolute;
    left: 0.45rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.72rem;
    pointer-events: none;
}
.cb-grid-search {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 0.28rem 0.45rem 0.28rem 1.55rem;
    font-size: 0.72rem;
    background: #fff;
}
.cb-grid-search:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}
.cb-grid-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    margin-left: auto;
}
.cb-grid-btn {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #475569;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.22rem 0.55rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
}
.cb-grid-btn:hover { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; }
.cb-grid-meta {
    font-size: 0.62rem;
    color: #64748b;
    white-space: nowrap;
}

.pnl-tr--expandable { cursor: pointer; }
.pnl-tr--expandable.cb-section-collapsed .cb-expand-btn i::before { content: "+"; }
.pnl-tr--expandable.cb-section-expanded .cb-expand-btn i { transform: rotate(0deg); }

.pnl-tr--detail { background: #f8fafc; }
.pnl-tr--detail td { padding: 0.14rem 0.4rem; font-size: 0.64rem; border-bottom: 1px solid #eef2f7; }
.pnl-tr--detail:hover { background: #f1f5f9; }
.cb-line-code {
    font-family: ui-monospace, monospace;
    font-size: 0.6rem; color: #64748b;
    margin-right: 0.35rem;
}
.cb-line-name { color: #374151; }
.cb-line-ledger {
    margin-left: 0.35rem; color: #2e4494; opacity: 0.7;
    text-decoration: none; font-size: 0.7rem;
}
.cb-line-ledger:hover { opacity: 1; }
.pnl-td-total--detail { font-weight: 500; color: #4b5563; }

/* ── Print overrides ── */
@media print {
    .pnl-topbar,
    .pnl-filter-card,
    .pnl-kpi-strip { display: none !important; }

    .pnl-body { padding: 0; }
    .pnl-report-card { border: none; box-shadow: none; }

    .pnl-table { font-size: 0.6rem; }
    .pnl-table thead tr { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .pnl-tr--subtotal,
    .pnl-tr--grand { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    .cb-expand-btn { display: none; }
    .cb-expand-spacer { display: none; }
    .cb-detail-hidden { display: table-row !important; }
    .cb-line-ledger { display: none; }
    .cb-instructions,
    .cb-modal-backdrop { display: none !important; }
}

/* Instructions banner */
.cb-instructions {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.55rem;
    background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    font-size: 0.68rem;
    color: #334155;
    line-height: 1.45;
}
.cb-instructions__icon {
    width: 28px; height: 28px; flex-shrink: 0;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #93c5fd;
    color: #2563eb;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.95rem;
}
.cb-instructions__title { display: block; font-size: 0.72rem; color: #1e3a5f; margin-bottom: 0.2rem; }
.cb-instructions__list { margin: 0; padding-left: 1.1rem; }
.cb-instructions__list li { margin-bottom: 0.12rem; }
.cb-instructions kbd {
    display: inline-block;
    padding: 0.05rem 0.3rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    font-size: 0.62rem;
    font-family: inherit;
    box-shadow: 0 1px 0 #e2e8f0;
}

/* Drillable account rows */
.cb-line-drillable { cursor: pointer; }
.cb-line-drillable:hover { background: #e0f2fe !important; }
.cb-line-drill-hint {
    margin-left: 0.3rem;
    color: #94a3b8;
    font-size: 0.62rem;
    opacity: 0;
    transition: opacity .12s;
}
.cb-line-drillable:hover .cb-line-drill-hint { opacity: 1; }

/* Account detail modal */
.cb-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.cb-modal {
    width: min(960px, 100%);
    max-height: min(88vh, 820px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}
.cb-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1e2d5a 0%, #2e4494 100%);
    color: #fff;
}
.cb-modal__title-wrap { display: flex; gap: 0.55rem; align-items: flex-start; }
.cb-modal__badge {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
}
.cb-modal__title { margin: 0; font-size: 1rem; font-weight: 700; }
.cb-modal__sub { margin: 0.15rem 0 0; font-size: 0.68rem; opacity: 0.9; }
.cb-modal__code {
    font-family: ui-monospace, monospace;
    background: rgba(255,255,255,.12);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
}
.cb-modal__close {
    border: none;
    background: rgba(255,255,255,.12);
    color: #fff;
    width: 32px; height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.cb-modal__close:hover { background: rgba(255,255,255,.22); }

.cb-modal__loading,
.cb-modal__empty {
    padding: 2rem;
    text-align: center;
    color: #64748b;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.cb-modal__kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.45rem;
    padding: 0.55rem 1rem 0;
}
.cb-modal__kpi {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.4rem 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.cb-modal__kpi--accent {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-color: #93c5fd;
}
.cb-modal__kpi-label { font-size: 0.6rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.03em; }
.cb-modal__kpi strong { font-size: 0.82rem; color: #1e293b; }

.cb-modal__toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    border-bottom: 1px solid #eef2f7;
}
.cb-hint {
    margin-left: auto;
    font-size: 0.62rem;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.cb-modal__table-wrap {
    flex: 1;
    overflow: auto;
    padding: 0 1rem;
}
.cb-modal__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.66rem;
}
.cb-modal__table thead tr {
    background: #f1f5f9;
    position: sticky;
    top: 0;
    z-index: 1;
}
.cb-modal__table th,
.cb-modal__table td {
    padding: 0.28rem 0.35rem;
    border-bottom: 1px solid #eef2f7;
    text-align: left;
    white-space: nowrap;
}
.cb-modal__table th.num,
.cb-modal__table td.num { text-align: right; }
.cb-modal__row { cursor: pointer; }
.cb-modal__row:hover { background: #f8fafc; }
.cb-modal__row.is-expanded { background: #eff6ff; }
.cb-modal__pill {
    display: inline-block;
    padding: 0.08rem 0.35rem;
    border-radius: 999px;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 0.6rem;
    font-weight: 600;
}
.cb-modal__ref { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.cb-modal__exp { color: #94a3b8; width: 24px; }
.cb-modal__no-rows { text-align: center; color: #94a3b8; padding: 1rem !important; }
.cb-modal__detail-row td { background: #f8fafc; padding: 0 !important; border-bottom: 1px solid #e2e8f0; }
.cb-modal__detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.4rem 0.55rem;
    font-size: 0.62rem;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}
.cb-modal__detail-meta i { color: #64748b; margin-right: 0.15rem; }
.cb-modal__subtable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.62rem;
}
.cb-modal__subtable th,
.cb-modal__subtable td { padding: 0.22rem 0.55rem; border-bottom: 1px solid #eef2f7; }
.cb-modal__subtable tr.is-focus { background: #eff6ff; font-weight: 600; }
.cb-modal__focus-tag {
    margin-left: 0.35rem;
    font-size: 0.55rem;
    text-transform: uppercase;
    color: #2563eb;
    background: #dbeafe;
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
    font-weight: 700;
}

.cb-modal__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
}
.cb-modal__link {
    margin-right: auto;
    font-size: 0.68rem;
    color: #2563eb;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.cb-modal__link:hover { text-decoration: underline; }
.cb-modal__btn {
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    border-radius: 6px;
    padding: 0.3rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
}
.cb-modal__btn:hover { background: #f1f5f9; }

@media (max-width: 720px) {
    .cb-modal__kpis { grid-template-columns: 1fr; }
    .cb-hint { display: none; }
    .cb-modal__table { font-size: 0.6rem; }
}
