:root {
    --app-primary: #3558f4;
    --app-primary-dark: #2444cd;
    --app-primary-soft: #eef1ff;
    --app-ink: #17213a;
    --app-muted: #68738b;
    --app-border: #e5e9f2;
    --app-surface: #ffffff;
    --app-canvas: #f5f7fb;
    --sidebar-width: 268px;
    --topbar-height: 72px;
    --app-shadow: 0 14px 38px rgba(30, 48, 92, .09);
}

html { min-height: 100%; }
body {
    min-height: 100vh;
    color: var(--app-ink);
    background: var(--app-canvas);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { text-underline-offset: .18em; }
.form-control, .form-select, .input-group-text, .btn { border-radius: .68rem; }
.form-control, .form-select {
    border-color: #dce2ee;
    min-height: 44px;
}
.form-control:focus, .form-select:focus {
    border-color: rgba(53, 88, 244, .5);
    box-shadow: 0 0 0 .22rem rgba(53, 88, 244, .12);
}
.input-group > :not(:first-child) { margin-left: -1px; }
.input-group > .input-group-text:first-child { border-radius: .68rem 0 0 .68rem; }
.input-group > .form-control:not(:last-child) { border-radius: 0; }
.input-group > .form-control:last-child { border-radius: 0 .68rem .68rem 0; }
.input-group > .btn:last-child { border-radius: 0 .68rem .68rem 0; }
.input-group-text { background: #f8f9fc; color: #778198; border-color: #dce2ee; }
.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-dark);
    --bs-btn-hover-border-color: var(--app-primary-dark);
    --bs-btn-active-bg: var(--app-primary-dark);
    --bs-btn-active-border-color: var(--app-primary-dark);
    box-shadow: 0 8px 18px rgba(53, 88, 244, .18);
}
.alert { border: 0; border-radius: .85rem; }

/* Authentication */
.auth-body {
    background:
        radial-gradient(circle at 10% 10%, rgba(75, 105, 255, .16), transparent 32%),
        radial-gradient(circle at 88% 88%, rgba(25, 178, 148, .12), transparent 29%),
        linear-gradient(145deg, #f8f9ff 0%, #f3f6fb 52%, #edf2f8 100%);
}
.auth-main { min-height: 100vh; display: grid; align-items: center; }
.auth-card, .error-card {
    width: min(100%, 476px);
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(222, 227, 240, .9);
    border-radius: 1.35rem;
    box-shadow: 0 26px 70px rgba(35, 50, 91, .13);
    overflow: hidden;
}
.auth-card-accent { height: 5px; background: linear-gradient(90deg, var(--app-primary), #7657f6, #1fb99a); }
.auth-card-body { padding: 2.2rem 2.35rem; }
.auth-card-footer { padding: 1rem 1.5rem; text-align: center; color: var(--app-muted); background: #fafbfe; border-top: 1px solid var(--app-border); font-size: .8rem; }
.auth-logo {
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    border-radius: 1.15rem;
    color: #fff;
    background: linear-gradient(145deg, #4265ff, #2949dc);
    box-shadow: 0 12px 30px rgba(53, 88, 244, .3);
    font-size: 1.65rem;
    margin-bottom: 1.2rem;
}
.auth-brand { margin-bottom: 1.75rem; }
.auth-brand h1 { font-size: clamp(1.35rem, 4vw, 1.75rem); font-weight: 760; letter-spacing: -.035em; margin-bottom: .45rem; }
.auth-eyebrow, .page-eyebrow { color: var(--app-primary); font-size: .72rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; margin-bottom: .4rem; }
.auth-form .form-label { color: #35405a; font-weight: 650; font-size: .9rem; }
.auth-form .input-group-lg > .form-control, .auth-form .input-group-lg > .input-group-text, .auth-form .input-group-lg > .btn { font-size: 1rem; min-height: 50px; }
.auth-submit { min-height: 50px; font-weight: 680; }
.auth-alert { width: min(100%, 476px); }
.password-toggle { border-color: #dce2ee; color: #69758f; }
.password-toggle:hover { color: var(--app-primary); background: var(--app-primary-soft); border-color: #cbd4ff; }

/* Protected application shell */
.app-shell { min-height: 100vh; }
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    color: #dce2f5;
    background: linear-gradient(180deg, #17213c 0%, #111a30 100%);
    border-right: 1px solid rgba(255, 255, 255, .05);
    transition: transform .25s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: .8rem; min-height: var(--topbar-height); padding: .8rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { flex: 0 0 auto; display: grid; place-items: center; width: 40px; height: 40px; border-radius: .78rem; color: #fff; background: linear-gradient(145deg, #5572ff, #3454ec); box-shadow: 0 8px 20px rgba(34, 61, 206, .4); }
.brand-copy { min-width: 0; display: flex; flex-direction: column; }
.brand-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; color: #fff; }
.brand-copy small { color: #9ca8c8; font-size: .72rem; }
.sidebar-nav { padding: 1.1rem .75rem; }
.sidebar-caption { margin: 1.35rem .75rem .5rem; color: #7783a4; font-size: .65rem; letter-spacing: .13em; font-weight: 750; text-transform: uppercase; }
.sidebar-link { display: flex; align-items: center; gap: .8rem; color: #b8c2dd; padding: .72rem .8rem; margin-bottom: .2rem; border-radius: .72rem; text-decoration: none; font-size: .89rem; font-weight: 560; }
.sidebar-link i { width: 1.3rem; text-align: center; font-size: 1rem; }
.sidebar-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.sidebar-link.active { color: #fff; background: linear-gradient(100deg, rgba(72, 99, 247, .92), rgba(79, 101, 225, .72)); box-shadow: 0 9px 20px rgba(15, 24, 57, .28); }
.sidebar-footer { margin-top: auto; padding: 1rem 1.2rem; border-top: 1px solid rgba(255,255,255,.06); color: #8995b4; font-size: .75rem; }
.sidebar-backdrop { display: none; }
.app-content { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar { position: sticky; top: 0; z-index: 1020; min-height: var(--topbar-height); padding: .75rem 1.5rem; display: flex; align-items: center; background: rgba(255,255,255,.93); border-bottom: 1px solid var(--app-border); backdrop-filter: blur(12px); }
.topbar-title { font-size: .95rem; font-weight: 700; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; font-size: 1.35rem; }
.user-chip { align-items: center; gap: .65rem; padding-right: .8rem; border-right: 1px solid var(--app-border); }
.user-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #6079f7, #3555e5); font-size: .8rem; font-weight: 800; }
.user-chip > span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.user-chip strong { font-size: .78rem; }
.user-chip small { color: var(--app-muted); font-size: .67rem; }
.logout-button { min-height: 38px; }
.main-content { padding: 1.5rem; }
.content-narrow { max-width: 820px; margin: 0 auto; }
.page-heading { margin-bottom: 1.45rem; }
.page-heading h1 { font-weight: 760; letter-spacing: -.035em; font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: .35rem; }
.page-heading p:last-child { color: var(--app-muted); margin-bottom: 0; }
.status-pill { display: inline-flex; align-items: center; gap: .4rem; color: #14775f; background: #e6f8f1; border: 1px solid #c8eee3; border-radius: 999px; padding: .48rem .75rem; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.business-card { box-shadow: var(--app-shadow); border-radius: 1rem; }
.security-card { display: flex; gap: 1rem; align-items: flex-start; padding: 1.25rem; background: #fff; border: 1px solid var(--app-border); border-radius: .95rem; box-shadow: 0 10px 26px rgba(34, 50, 89, .055); }
.security-icon { flex: 0 0 auto; display: grid; place-items: center; width: 46px; height: 46px; border-radius: .85rem; font-size: 1.1rem; }
.security-icon-primary { color: #3558f4; background: #edf0ff; }
.security-icon-success { color: #14846a; background: #e8f8f3; }
.security-icon-warning { color: #bd7510; background: #fff4de; }
.security-card small { display: block; color: var(--app-muted); font-size: .72rem; margin-bottom: .2rem; }
.security-card strong { display: block; font-size: .98rem; overflow-wrap: anywhere; }
.security-card p { color: var(--app-muted); margin: .15rem 0 0; font-size: .8rem; }
.control-item { display: flex; align-items: center; gap: .75rem; min-height: 48px; padding: .75rem .9rem; border: 1px solid var(--app-border); background: #fafbfe; border-radius: .75rem; font-size: .86rem; }
.control-item > i:first-child { color: var(--app-primary); font-size: 1rem; }
.password-rules { color: #5f6980; background: #f6f8fc; border: 1px solid var(--app-border); border-radius: .75rem; padding: 1rem 1.15rem; font-size: .84rem; }

/* Dashboard */
.dashboard-header { margin-bottom: .85rem; }
.dashboard-header h1 { margin: 0 0 .3rem; font-size: clamp(1.55rem, 3vw, 2.15rem); font-weight: 780; letter-spacing: -.04em; }
.dashboard-header p:last-child { margin: 0; color: var(--app-muted); }
.dashboard-date-filter { width: min(100%, 330px); }
.dashboard-date-filter .form-label { display: block; margin: 0 0 .28rem; color: var(--app-muted); font-size: .72rem; font-weight: 700; }
.dashboard-date-filter .input-group { flex-wrap: nowrap; }
.dashboard-date-filter .form-control { min-width: 145px; }
.dashboard-refresh-button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; border: 1px solid var(--app-border); color: #58637a; white-space: nowrap; }
.dashboard-refresh-button:hover { color: var(--app-primary); background: var(--app-primary-soft); border-color: #d6dcff; }
.dashboard-refresh-button.is-refreshing i { animation: dashboard-spin .8s linear infinite; }
.dashboard-refresh-button.refresh-success { color: #117d62; background: #e7f8f2; border-color: #c5eddf; }
.dashboard-refresh-button.refresh-failed { color: #c03d4e; background: #fff0f2; border-color: #f5ccd2; }
.dashboard-updated-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; color: #8992a7; font-size: .7rem; }
.dashboard-updated-row > span { display: inline-flex; align-items: center; }
.live-dot { width: 7px; height: 7px; margin-right: .4rem; border-radius: 50%; background: #1eb58e; box-shadow: 0 0 0 4px rgba(30,181,142,.12); }
.dashboard-metrics-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .85rem; margin-bottom: 1.4rem; }
.metric-card { position: relative; min-width: 0; padding: 1rem; overflow: hidden; background: #fff; border: 1px solid var(--app-border); border-radius: .95rem; box-shadow: 0 9px 25px rgba(30, 47, 86, .05); }
.metric-card::after { content: ""; position: absolute; right: -28px; bottom: -32px; width: 82px; height: 82px; border-radius: 50%; background: var(--metric-soft); opacity: .85; }
.metric-card-top { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; min-height: 36px; margin-bottom: .75rem; }
.metric-icon { display: grid; place-items: center; width: 36px; height: 36px; color: var(--metric-color); background: var(--metric-soft); border-radius: .72rem; font-size: .96rem; }
.metric-card p { position: relative; z-index: 1; min-height: 2.15em; margin: 0 0 .25rem; color: #6e7890; font-size: .72rem; font-weight: 650; line-height: 1.15; }
.metric-card > strong { position: relative; z-index: 1; display: block; overflow: hidden; color: #1c2741; font-size: clamp(1rem, 1.65vw, 1.35rem); font-weight: 780; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.metric-card > small { position: relative; z-index: 1; display: block; margin-top: .35rem; overflow: hidden; color: #98a0b3; font-size: .62rem; text-overflow: ellipsis; white-space: nowrap; }
.metric-card-primary { --metric-color: #3558f4; --metric-soft: #edf0ff; }
.metric-card-success { --metric-color: #138366; --metric-soft: #e7f8f1; }
.metric-card-violet { --metric-color: #7751d5; --metric-soft: #f1ebff; }
.metric-card-warning { --metric-color: #b87614; --metric-soft: #fff3dc; }
.metric-card-teal { --metric-color: #118d91; --metric-soft: #e5f8f7; }
.metric-card-danger { --metric-color: #d3485a; --metric-soft: #ffedf0; }
.metric-card-blue { --metric-color: #3179cd; --metric-soft: #eaf4ff; }
.metric-card-indigo { --metric-color: #515dc9; --metric-soft: #eceeff; }
.metric-card-cyan { --metric-color: #1586ae; --metric-soft: #e7f7fc; }
.metric-card-orange { --metric-color: #d36527; --metric-soft: #fff0e6; }
.metric-alert-dot { width: 8px; height: 8px; border-radius: 50%; background: #e65364; box-shadow: 0 0 0 4px rgba(230,83,100,.12); }
.metric-value-flash { animation: metric-flash .75s ease; }
.dashboard-panel { border-radius: 1rem; box-shadow: 0 10px 30px rgba(31, 48, 89, .065); overflow: hidden; }
.dashboard-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.25rem; background: #fff; border: 0; }
.panel-eyebrow { margin: 0 0 .22rem; color: #929aab; font-size: .64rem; font-weight: 760; letter-spacing: .1em; text-transform: uppercase; }
.dashboard-panel-header h2 { margin: 0; font-size: 1rem; font-weight: 750; letter-spacing: -.015em; }
.panel-icon { flex: 0 0 auto; display: grid; place-items: center; width: 38px; height: 38px; border-radius: .75rem; }
.panel-icon-primary { color: #3558f4; background: #edf0ff; }
.panel-icon-teal { color: #138577; background: #e6f8f3; }
.panel-icon-success { color: #168060; background: #e8f8f1; }
.panel-icon-violet { color: #7150ca; background: #f0ebff; }
.panel-icon-danger { color: #cf4659; background: #ffedf0; }
.panel-icon-warning { color: #bf7413; background: #fff3df; }
.panel-count { color: #7c879d; background: #f4f6fa; border-radius: 999px; padding: .35rem .6rem; font-size: .66rem; font-weight: 700; }
.dashboard-chart-wrap { position: relative; height: 280px; }
.summary-lines > div, .collection-modes > div { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .48rem 0; color: #6f7990; font-size: .78rem; border-bottom: 1px dashed #e7eaf1; }
.summary-lines strong, .collection-modes strong { color: #26314a; font-size: .79rem; }
.summary-lines .summary-net { margin-top: .3rem; padding: .7rem .75rem; color: #31405e; background: #f2f5ff; border: 0; border-radius: .65rem; }
.summary-net strong { color: var(--app-primary); }
.collection-modes { margin-top: 1rem; }
.collection-modes > p { margin: 0 0 .15rem; color: #3d4861; font-size: .72rem; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.collection-modes > div { padding: .33rem 0; font-size: .71rem; border: 0; }
.collection-modes strong { font-size: .71rem; }
.dashboard-table { font-size: .76rem; }
.dashboard-table thead th { padding: .65rem 1rem; color: #858ea2; background: #fafbfc; border-color: var(--app-border); font-size: .62rem; font-weight: 760; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.dashboard-table tbody td { padding: .78rem 1rem; color: #5f6980; border-color: #edf0f5; }
.dashboard-table tbody tr:last-child td { border-bottom: 0; }
.dashboard-table td > strong:not(.table-primary-text) { display: block; max-width: 170px; overflow: hidden; color: #34405a; font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-table td > small { display: block; max-width: 170px; overflow: hidden; color: #929bad; font-size: .65rem; text-overflow: ellipsis; white-space: nowrap; }
.table-primary-text { color: var(--app-primary); }
.status-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 57px; padding: .27rem .48rem; border-radius: 999px; font-size: .62rem; font-weight: 750; }
.status-badge-success { color: #117659; background: #e6f7f0; }
.status-badge-warning { color: #a9680d; background: #fff2d9; }
.status-badge-danger { color: #c33d51; background: #ffeaed; }
.status-badge-secondary { color: #687287; background: #eef0f4; }
.dashboard-list-body { padding: .25rem 1.25rem .8rem; }
.activity-list, .customer-balance-list, .stock-alert-list { display: flex; flex-direction: column; }
.activity-item { display: flex; align-items: center; gap: .75rem; padding: .68rem 0; border-bottom: 1px solid #edf0f5; }
.activity-item:last-child { border-bottom: 0; }
.activity-icon { flex: 0 0 auto; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #168060; background: #e8f8f1; }
.activity-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.activity-copy strong, .customer-balance-item strong, .stock-alert-item strong { overflow: hidden; color: #34405a; font-size: .74rem; text-overflow: ellipsis; white-space: nowrap; }
.activity-copy span, .activity-copy small { overflow: hidden; color: #8992a5; font-size: .63rem; text-overflow: ellipsis; white-space: nowrap; }
.activity-amount { flex: 0 0 auto; color: #11785b; font-size: .76rem; white-space: nowrap; }
.rank-list { margin: 0; padding: 0; list-style: none; }
.rank-list li { display: flex; align-items: center; gap: .7rem; padding: .66rem 0; border-bottom: 1px solid #edf0f5; }
.rank-list li:last-child { border: 0; }
.rank-number { flex: 0 0 auto; display: grid; place-items: center; width: 27px; height: 27px; border-radius: .55rem; color: #6550ac; background: #f0ebff; font-size: .65rem; font-weight: 800; }
.rank-list li > div:nth-child(2) { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.rank-list li > div:nth-child(2) strong { overflow: hidden; color: #34405a; font-size: .73rem; text-overflow: ellipsis; white-space: nowrap; }
.rank-list li > div:nth-child(2) span, .rank-value span { color: #929bad; font-size: .61rem; }
.rank-value { flex: 0 0 auto; display: flex; flex-direction: column; text-align: right; }
.rank-value strong { color: #3f4a61; font-size: .68rem; }
.customer-balance-item, .stock-alert-item { display: flex; align-items: center; gap: .7rem; min-width: 0; padding: .68rem 0; border-bottom: 1px solid #edf0f5; }
.customer-balance-item:last-child, .stock-alert-item:last-child { border: 0; }
.customer-initial { flex: 0 0 auto; display: grid; place-items: center; width: 33px; height: 33px; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #687bf0, #4659cd); font-size: .68rem; font-weight: 800; }
.customer-balance-item > div:nth-child(2), .stock-alert-item > div:nth-child(2) { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.customer-balance-item span, .stock-alert-item span { color: #929bad; font-size: .62rem; }
.customer-balance-value, .stock-value { flex: 0 0 auto; display: flex; flex-direction: column; text-align: right; }
.customer-balance-value strong { color: #d04758; }
.stock-indicator { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; }
.stock-indicator-out { background: #d9485b; box-shadow: 0 0 0 4px #ffeaed; }
.stock-indicator-critical { background: #e4872d; box-shadow: 0 0 0 4px #fff0e1; }
.stock-indicator-low { background: #dfa81f; box-shadow: 0 0 0 4px #fff6d9; }
.dashboard-empty { display: flex; min-height: 220px; align-items: center; justify-content: center; flex-direction: column; padding: 2rem; text-align: center; color: #9aa3b5; }
.dashboard-empty.compact { min-height: 240px; }
.dashboard-empty i { margin-bottom: .65rem; color: #c2c8d4; font-size: 2rem; }
.dashboard-empty strong { color: #59647a; font-size: .82rem; }
.dashboard-empty span { margin-top: .15rem; font-size: .7rem; }
@keyframes dashboard-spin { to { transform: rotate(360deg); } }
@keyframes metric-flash { 0%, 100% { color: #1c2741; } 45% { color: var(--app-primary); } }

/* Errors */
.error-card { padding: 2.5rem 2rem; }
.error-code { color: rgba(53,88,244,.12); font-size: 5.5rem; font-weight: 850; line-height: .9; letter-spacing: -.08em; }
.error-icon { display: grid; place-items: center; width: 58px; height: 58px; margin-top: -1.2rem; margin-bottom: 1.2rem; border-radius: 50%; color: #e59924; background: #fff4df; font-size: 1.5rem; }
.error-card h1 { font-size: 1.55rem; font-weight: 760; }
.error-card > p { color: var(--app-muted); }

@media (max-width: 1399.98px) {
    .dashboard-metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: 18px 0 45px rgba(8, 16, 39, .25); }
    .app-content { margin-left: 0; }
    .sidebar-open .app-sidebar { transform: translateX(0); }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 1035; background: rgba(12, 19, 39, .48); backdrop-filter: blur(2px); }
    .sidebar-open { overflow: hidden; }
}

@media (max-width: 767.98px) {
    .dashboard-metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-updated-row { align-items: flex-start; flex-direction: column; gap: .25rem; }
    .dashboard-chart-wrap { height: 240px; }
}

@media (max-width: 575.98px) {
    .auth-card-body { padding: 1.6rem 1.25rem; }
    .auth-card, .error-card { border-radius: 1rem; }
    .topbar { padding: .65rem .85rem; }
    .main-content { padding: 1rem .85rem 1.5rem; }
    .business-card .card-body { padding: 1.2rem !important; }
    .logout-button { width: 40px; padding-left: .5rem; padding-right: .5rem; }
    .dashboard-date-filter { width: 100%; }
    .dashboard-refresh-button { width: 100%; }
    .dashboard-panel-header { padding: 1rem; }
    .dashboard-list-body { padding-left: 1rem; padding-right: 1rem; }
    .metric-card { padding: .85rem; }
    .metric-card > strong { font-size: 1rem; }
    .metric-card > small { display: none; }
    .activity-amount { font-size: .68rem; }
}

@media (max-width: 380px) {
    .dashboard-metrics-grid { grid-template-columns: 1fr; }
    .metric-card p { min-height: auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
