/* App-wide styles */
:root {
    --sidebar-width: 240px;
    --topbar-height: 56px;
}

body { background: #f5f6f8; }

/* ---------------------------------------------------------------- app shell: top bar + left sidebar */
.app-topbar { min-height: var(--topbar-height); }
/* keep the top bar on screen while scrolling. The bar's own sticky-top can't work because its wrapper is only
   as tall as the bar, so the wrapper sticks. z-index sits above the offcanvas backdrop (1040) so the phone menu
   (inside this wrapper) still shows above its backdrop. */
.app-shell { position: sticky; top: 0; z-index: 1046; }

.app-sidebar .sidebar-inner {
    background: #1f2429;
    width: 100%;
    min-height: 100%;
    padding: .75rem .5rem 2rem;
}
.sidebar-nav .nav-link {
    color: #c8ced4;
    padding: .5rem .75rem;
    border-radius: .375rem;
    font-size: .95rem;
}
.sidebar-nav .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .07); }
.sidebar-nav .nav-link.active { color: #fff; background: #0d6efd; }

/* group headers with a chevron that turns when open */
.sidebar-nav .group-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: .25rem;
    color: #e9ecef;
    font-weight: 600;
}
.sidebar-nav .group-toggle::after {
    content: "";
    width: .5rem;
    height: .5rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform .15s ease;
    margin-left: .5rem;
}
.sidebar-nav .group-toggle.collapsed::after { transform: rotate(-45deg); }
.sidebar-nav .sub-nav { padding-left: .75rem; }
/* never wrap links into side-by-side columns while a group is animating open/closed */
.sidebar-nav,
.sidebar-nav .sub-nav { flex-wrap: nowrap; }
.sidebar-nav .sub-nav .nav-link { font-size: .9rem; padding: .35rem .75rem; }

/* below lg the sidebar is a Bootstrap offcanvas; give it the dark background */
@media (max-width: 991.98px) {
    .app-sidebar { background: #1f2429; width: 270px !important; }
    .app-sidebar .sidebar-inner { padding-top: 0; }
}

/* lg and up: fixed sidebar on the left, page content pushed right */
@media (min-width: 992px) {
    .app-sidebar {
        position: fixed;
        top: var(--topbar-height);
        bottom: 0;
        left: 0;
        width: var(--sidebar-width);
        overflow-y: auto;
        z-index: 1000;
    }
    .app-shell ~ main { margin-left: var(--sidebar-width); width: auto; max-width: none; }
}
/* every page's main gets breathing room under the top bar */
.app-shell ~ main { padding-top: 1.25rem; padding-bottom: 2rem; }

/* ---------------------------------------------------------------- data */
.amount { text-align: right; font-variant-numeric: tabular-nums; }
input.amount { text-align: left; } /* typing starts from the left in form fields; table columns stay right-aligned */
.reversed { color: #999; text-decoration: line-through; }
/* deactivated master rows stay visible but greyed (BR-7) */
tr.inactive > td { color: #999; }
/* reversed entries are shown greyed in the transactions list (F7) */
tr.reversed-row > td { color: #999; }
tr.reversed-row > td.amount { text-decoration: line-through; }
/* money column headings carry the currency label from Admin -> Settings, e.g. "Receive (Rs)" */
.data-table > thead th.amount::after { content: " (" var(--currency, "Rs") ")"; font-weight: 600; opacity: .7; }
/* why / who / when line under a reversed entry */
.data-table .reversed-note { color: #6b7280; font-size: .78rem; text-decoration: none; }

@media print {
    .app-shell, .no-print { display: none !important; }
    .app-shell ~ main { margin-left: 0 !important; padding: 0 !important; }
    body { background: #fff; }
}

/* dashboard account cards link to their cashbook */
.dash-card:hover { box-shadow: 0 .25rem .75rem rgba(0,0,0,.08); }

/* ---------------------------------------------------------------- new table style (Transactions page first) */
.stat-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-left: 4px solid #6c757d;
    border-radius: .6rem;
    padding: .75rem 1rem;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.stat-card .stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; }
.stat-card .stat-value { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-card.stat-in  { border-left-color: #198754; }
.stat-card.stat-in .stat-value { color: #198754; }
.stat-card.stat-out { border-left-color: #dc3545; }
.stat-card.stat-out .stat-value { color: #dc3545; }
.stat-card.stat-net { border-left-color: #0d6efd; }

.filter-card {
    background: #f0f6ff;
    border: 1px solid #cfe0f7;
    border-radius: .6rem;
    padding: .9rem 1rem;
}
.filter-card .form-label { font-size: .78rem; font-weight: 600; color: #4b5563; margin-bottom: .2rem; }
.more-filters-toggle { text-decoration: none; }
.more-filters-toggle::after { content: " \25B4"; }
.more-filters-toggle.collapsed::after { content: " \25BE"; }

.data-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: .6rem;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
/* long lists scroll inside the card so the column titles stay visible
   (.data-card is either the wrapper of .table-responsive or on the same element) */
.data-card .table-responsive,
.data-card.table-responsive { max-height: 70vh; overflow: auto; }
.data-card { margin-bottom: 1rem; }
.data-table { font-size: .92rem; }
.data-table > thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #dbe3ec;
    color: #1e293b;
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid #c3cfdc;
    padding: .65rem .75rem;
    white-space: nowrap;
}
.data-table > tbody td { padding: .6rem .75rem; border-color: #f1f5f9; }
.data-table > tbody tr:nth-child(even) > td { background: #fcfcfd; }
.data-table > tbody tr:hover > td { background: #eef4ff; }
.data-table > tfoot td {
    background: #f8fafc;
    font-weight: 600;
    padding: .7rem .75rem;
    border-top: 2px solid #e2e8f0;
    border-bottom: 0;
}
.data-table .cell-sub { font-size: .75rem; color: #94a3b8; }
.data-table .details-cell { max-width: 22rem; }
.data-table .amt-in  { color: #198754; font-weight: 600; }
.data-table .amt-out { color: #dc3545; font-weight: 600; }
.data-table .head-pill {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 1rem;
    background: #eef2f7;
    color: #334155;
    font-size: .8rem;
    white-space: nowrap;
}
.data-table .tag { font-size: .68rem; padding: .1rem .4rem; border-radius: .25rem; margin-left: .2rem; text-transform: uppercase; }
.data-table .tag-transfer { background: #e0f2fe; color: #0369a1; }
.data-table .tag-reversed { background: #e5e7eb; color: #4b5563; }
.data-table tr.reversed-row > td,
.data-table tr.reversed-row > td.amt-in,
.data-table tr.reversed-row > td.amt-out { color: #9ca3af; }
.data-table .empty-state { text-align: center; color: #6b7280; padding: 2.5rem 1rem; }

@media print {
    .stat-card, .data-card { box-shadow: none; }
    .data-table > thead th { position: static; }
    .data-card .table-responsive,
    .data-card.table-responsive { max-height: none; overflow: visible; }
    .filter-card, .form-card { border: 0; padding: 0; background: none; box-shadow: none; }
}

/* filter forms that are a Bootstrap .row: keep the box aligned with the page edges */
.filter-card.row { margin-left: 0; margin-right: 0; margin-top: 0; padding: .9rem .5rem; }

/* data-entry forms (New entry, Transfer, bills, masters, users) sit on a white card */
.form-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: .6rem;
    padding: 1.25rem 1.25rem .75rem;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
    margin-bottom: 1rem;
}
.form-card .form-label { font-weight: 600; color: #374151; }


/* ---------------------------------------------------------------- dashboard: tiles, charts */
.stat-card .stat-note { font-size: .75rem; color: #6b7280; margin-top: .15rem; }
.stat-card.stat-warn { border-left-color: #f59e0b; }
.section-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #64748b; margin: .25rem 0 .6rem; }

.chart-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: .6rem;
    padding: 1rem 1.1rem;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.chart-title { font-size: 1rem; font-weight: 600; margin: 0; }
.chart-legend { display: flex; gap: 1rem; font-size: .8rem; color: #475569; margin-top: .2rem; }
.key { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.key-in { background: #198754; }
.key-out { background: #dc3545; }

/* vertical grouped bars: one column per month, in + out side by side, anchored to the baseline */
.chart-bars {
    display: flex;
    align-items: stretch;
    gap: .35rem;
    height: 220px;
    padding-top: .5rem;
    border-bottom: 1px solid #cbd5e1;
    background-image: linear-gradient(to top, #f1f5f9 1px, transparent 1px);
    background-size: 100% 25%;
}
.chart-month { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; outline: none; cursor: default; }
.chart-pair { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.chart-bar { width: min(22px, 42%); border-radius: 4px 4px 0 0; transition: opacity .15s; }
.chart-bar.bar-in { background: #198754; }
.chart-bar.bar-out { background: #dc3545; }
.chart-label { text-align: center; font-size: .72rem; color: #64748b; padding-top: .3rem; position: absolute; bottom: -1.4rem; left: 0; right: 0; }
.chart-month.current .chart-label { color: #0f172a; font-weight: 700; }
.chart-bars { margin-bottom: 1.6rem; }
.chart-bars:hover .chart-month .chart-bar { opacity: .45; }
.chart-bars .chart-month:hover .chart-bar,
.chart-bars .chart-month:focus .chart-bar { opacity: 1; }
.chart-month:hover, .chart-month:focus { background: rgba(13, 110, 253, .05); border-radius: 4px; }
.chart-tip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    min-width: 10.5rem;
    background: #0f172a;
    color: #fff;
    font-size: .78rem;
    line-height: 1.5;
    padding: .5rem .65rem;
    border-radius: .4rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
    pointer-events: none;
    white-space: nowrap;
}
.chart-tip span { float: right; margin-left: .75rem; font-variant-numeric: tabular-nums; }
.chart-month:hover .chart-tip, .chart-month:focus .chart-tip { display: block; }
.chart-month:first-child .chart-tip { left: 0; transform: none; }
.chart-month:last-child .chart-tip { left: auto; right: 0; transform: none; }

/* horizontal bars: share of this month's spending per head */
.spend-row { display: block; padding: .45rem .5rem; margin: 0 -.5rem; border-radius: .4rem; text-decoration: none; color: inherit; }
a.spend-row:hover { background: #f1f5f9; }
.spend-track { height: 8px; background: #f1f5f9; border-radius: 4px; margin-top: .3rem; overflow: hidden; }
.spend-fill { height: 100%; background: #dc3545; border-radius: 4px; }

/* ================================================================ phones and small tablets (< 768px)
   Most use is on mobile: tables become cards, buttons become full-width and easy to tap. */
@media (max-width: 767.98px) {
    .app-shell ~ main { padding-top: .9rem; }
    main h1.h3 { font-size: 1.3rem; }

    /* inputs at 16px so iPhone Safari does not zoom in when a field is tapped */
    .form-control, .form-select, .form-control-sm, .form-select-sm { font-size: 16px; }
    .form-control, .form-select { min-height: 42px; }

    /* bigger menu button and sidebar links */
    .app-topbar .btn { padding: .35rem .7rem; }
    .sidebar-nav .nav-link { padding-top: .6rem; padding-bottom: .6rem; }

    /* page title row: buttons drop under the title instead of squeezing it */
    main > .d-flex.justify-content-between { flex-wrap: wrap; gap: .5rem; }
    main > .d-flex.justify-content-between > div { display: flex; flex-wrap: wrap; gap: .5rem; }

    /* forms: full-width buttons, Receive/Payment switch fills the row */
    .form-card { padding: 1rem 1rem .5rem; }
    .form-card .btn-group { display: flex; width: 100%; }
    .form-card .btn-group > .btn { flex: 1; padding-top: .55rem; padding-bottom: .55rem; }
    .form-card button[type="submit"],
    .form-card > .btn-link,
    .form-card > div:last-child > .btn { display: block; width: 100%; margin: 0 0 .5rem; padding-top: .6rem; padding-bottom: .6rem; }
    .form-card > div:last-child.mt-4 { margin-top: 1rem !important; }
    #paymentRunForm > button[type="submit"],
    #paymentRunForm > .btn-link { display: block; width: 100%; margin-bottom: .5rem; padding: .6rem; }
    .filter-card .btn { min-height: 42px; }

    /* ---- tables stay tables: compact, one line per value, swipe sideways when wider than the screen */
    .data-card.table-responsive,
    .data-card .table-responsive { max-height: none; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { font-size: .85rem; }
    .data-table > thead th { position: static; padding: .5rem .55rem; }
    .data-table > tbody td, .data-table > tfoot td { padding: .45rem .55rem; white-space: nowrap; }
    .data-table .details-cell { white-space: normal; min-width: 11rem; }
    .chart-bars { height: 180px; gap: .2rem; }
    .chart-tip { font-size: .74rem; min-width: 9rem; }
}
