/* ============================================================
   Bila.lk — Printing Shop Management SaaS
   Brand accent   = ink blue -> cyan gradient   #4f46e5 -> #06b6d4
   Success        = green                       #22c55e
   Warning        = amber                        #f59e0b
   Danger         = red                           #ef4444
   Dark surfaces  = near-black                    #0b0c10 / #15171c / #1d2026
   Font           = Plus Jakarta Sans (Google Fonts)
   Shape language = pill buttons (999px radius), rounded 16px cards
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --brand-primary:      #4f46e5;
    --brand-primary-dark: #4338ca;
    --brand-cyan:         #06b6d4;
    --brand-gradient:     linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);

    --brand-success:      #22c55e;
    --brand-success-dark: #16a34a;
    --brand-warning:      #f59e0b;
    --brand-warning-dark: #d97706;
    --brand-danger:       #ef4444;
    --brand-danger-dark:  #dc2626;

    --brand-bg:         #0b0c10;
    --brand-surface:    #15171c;
    --brand-surface-2:  #1d2026;
    --brand-border:     rgba(255,255,255,.09);
    --brand-text:       #f4f4f5;
    --brand-text-muted: #9ca3af;
}

html, body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
body {
    background-color: var(--brand-bg);
    color: var(--brand-text);
}
h1, h2, h3, h4, h5, h6 { font-weight: 800; letter-spacing: -.01em; color: var(--brand-text); }
small, .text-muted { color: var(--brand-text-muted) !important; }
hr { border-color: var(--brand-border); opacity: 1; }
a { color: var(--brand-link, var(--brand-cyan)); }

/* ---------- Bootstrap overrides ---------- */
.btn-primary {
    background: var(--brand-gradient);
    border: none;
    color: #fff;
    border-radius: 999px;
    padding: .55rem 1.4rem;
    font-weight: 600;
}
.btn-primary:hover, .btn-primary:focus { background: var(--brand-primary-dark); color: #fff; }
.btn-outline-light { border-radius: 999px; }

.card {
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 16px;
    color: var(--brand-text);
}
.form-control, .form-select {
    background-color: var(--brand-surface-2);
    border: 1px solid var(--brand-border);
    color: var(--brand-text);
    border-radius: 10px;
}
.form-control:focus, .form-select:focus {
    background-color: var(--brand-surface-2);
    color: var(--brand-text);
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 .2rem rgba(79,70,229,.25);
}
.form-label { color: var(--brand-text-muted); font-weight: 600; font-size: .85rem; }
.form-control::placeholder { color: #6b7280; }

.alert-danger { background-color: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35); color: #fca5a5; }
.alert-success { background-color: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.35); color: #86efac; }
.alert-info { background-color: rgba(6,182,212,.12); border: 1px solid rgba(6,182,212,.35); color: #67e8f9; }

/* ---------- Auth pages (login / register) ---------- */
.auth-page-bg {
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;      /* clip the blurred blobs sideways only — vertical scrolling must work on tall forms */
    overflow-y: auto;
    padding: 1.5rem 0;
}
html:has(body.auth-page-bg) { overflow-y: auto; height: auto; }
.auth-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: .35;
    z-index: 0;
}
.auth-blob-1 { width: 420px; height: 420px; background: var(--brand-primary); top: -120px; left: -120px; }
.auth-blob-2 { width: 380px; height: 380px; background: var(--brand-cyan); bottom: -140px; right: -100px; }
.auth-brand-icon {
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ---------- App shell: sidebar + topbar ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    width: 250px;
    flex-shrink: 0;
    background-color: var(--brand-surface);
    border-right: 1px solid var(--brand-border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0;
}
.app-sidebar .brand {
    padding: 0 1.25rem 1.25rem;
    font-size: 1.25rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: .5rem;
    border-bottom: 1px solid var(--brand-border);
    margin-bottom: .75rem;
}
.app-sidebar .brand .bi { background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 1.4rem; }
.app-sidebar nav { flex: 1; overflow-y: auto; }
.app-sidebar .nav-section-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--brand-text-muted);
    padding: .75rem 1.25rem .35rem;
}
.app-sidebar .nav-link {
    color: var(--brand-text-muted);
    padding: .55rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    border-radius: 0;
    font-weight: 500;
    font-size: .92rem;
}
.app-sidebar .nav-link:hover { background-color: var(--brand-surface-2); color: var(--brand-text); }
.app-sidebar .nav-link.active {
    color: #fff;
    background: var(--brand-gradient);
    border-radius: 0 999px 999px 0;
    margin-right: .6rem;
}
.app-main { flex: 1; min-width: 0; }
.app-topbar {
    background-color: var(--brand-surface);
    border-bottom: 1px solid var(--brand-border);
    padding: .85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.app-content { padding: 1.5rem; }

.stat-card {
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 16px;
    padding: 1.25rem;
}
.stat-card .stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: var(--brand-gradient);
    color: #fff;
    font-size: 1.3rem;
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; }
.stat-card .stat-label { color: var(--brand-text-muted); font-size: .85rem; }

.badge-pill { border-radius: 999px; padding: .35rem .75rem; font-weight: 600; font-size: .78rem; }

/* Tables inside the dark theme: transparent background, theme text + borders
   (Bootstrap's default white table made light buttons/text unreadable). */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--brand-text);
    --bs-table-border-color: var(--brand-border);
    --bs-table-striped-bg: rgba(255, 255, 255, .03);
    --bs-table-hover-bg: rgba(255, 255, 255, .04);
    color: var(--brand-text);
}
.table > :not(caption) > * > * { background-color: transparent; color: inherit; border-bottom-color: var(--brand-border); }

/* ---------- Readability safety net (Phase 17) ----------
   Every Bootstrap part that defaults to a WHITE background is re-coloured for the dark theme,
   so light text can never land on white. */
html[data-bs-theme="dark"] { color-scheme: dark; }
select option, select optgroup { background-color: #1d2026; color: #f4f4f5; }
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus,
textarea:-webkit-autofill, select:-webkit-autofill {
    -webkit-text-fill-color: var(--brand-text) !important;
    box-shadow: 0 0 0 1000px var(--brand-surface-2) inset !important;
    caret-color: var(--brand-text);
}
.form-control:disabled, .form-control[readonly], .form-select:disabled {
    background-color: #12141a; color: var(--brand-text-muted); opacity: 1; border-color: var(--brand-border);
}
.input-group-text { background-color: var(--brand-surface-2); border: 1px solid var(--brand-border); color: var(--brand-text-muted); }
.form-check-input { background-color: var(--brand-surface-2); border-color: rgba(255,255,255,.3); }
.form-check-input:checked { background-color: var(--brand-primary); border-color: var(--brand-primary); }
.form-text { color: var(--brand-text-muted); }

.modal-content, .offcanvas, .popover, .toast { background-color: var(--brand-surface); color: var(--brand-text); border: 1px solid var(--brand-border); border-radius: 16px; }
.modal-header, .modal-footer { border-color: var(--brand-border); }
.btn-close { filter: invert(1) grayscale(1) brightness(2); }
.dropdown-menu { background-color: var(--brand-surface-2); border: 1px solid var(--brand-border); color: var(--brand-text); }
.dropdown-item { color: var(--brand-text); }
.dropdown-item:hover, .dropdown-item:focus { background-color: rgba(255,255,255,.08); color: #fff; }
.list-group-item { background-color: var(--brand-surface); color: var(--brand-text); border-color: var(--brand-border); }
.card-header, .card-footer { background-color: var(--brand-surface-2); border-color: var(--brand-border); color: var(--brand-text); }
.nav-tabs { border-color: var(--brand-border); }
.nav-tabs .nav-link { color: var(--brand-text-muted); }
.nav-tabs .nav-link.active { background-color: var(--brand-surface); border-color: var(--brand-border) var(--brand-border) var(--brand-surface); color: var(--brand-text); }
.pagination .page-link { background-color: var(--brand-surface); border-color: var(--brand-border); color: var(--brand-text); }
.pagination .page-item.active .page-link { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }

.alert-warning   { background-color: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.35); color: #fcd34d; }
.alert-secondary, .alert-light { background-color: rgba(255,255,255,.06); border: 1px solid var(--brand-border); color: var(--brand-text); }
.alert-primary   { background-color: rgba(79,70,229,.15); border: 1px solid rgba(129,140,248,.4); color: #c7d2fe; }
.alert a { color: inherit; text-decoration: underline; }

.table-light, .table-light > :not(caption) > * > * { background-color: var(--brand-surface-2) !important; color: var(--brand-text) !important; }
.bg-light, .bg-white { background-color: var(--brand-surface-2) !important; color: var(--brand-text) !important; }
.text-dark, .text-black { color: var(--brand-text) !important; }
.badge.bg-secondary { background-color: #4b5563 !important; color: #fff; }
.badge.bg-light { color: #111 !important; background-color: #e5e7eb !important; }

.btn-outline-light { color: var(--brand-text); border-color: rgba(255,255,255,.35); }
.btn-outline-light:hover, .btn-outline-light:focus { background-color: #fff; color: #111; border-color: #fff; }
.btn-outline-secondary { color: var(--brand-text-muted); border-color: rgba(255,255,255,.25); }
.btn-outline-secondary:hover { background-color: rgba(255,255,255,.12); color: #fff; }
.btn-light { background-color: #fff; color: #111; }
.btn-warning, .btn-success, .btn-info { color: #0b0c10; }
.btn-outline-danger { color: #fca5a5; border-color: rgba(239,68,68,.6); }
.btn-outline-danger:hover { background-color: #ef4444; color: #fff; }
.btn:disabled, .btn.disabled { opacity: .5; }
::selection { background: rgba(79,70,229,.55); color: #fff; }

/* ---------- Phone / tablet: sidebar becomes a slide-in menu ---------- */
.nav-toggle { display: none; background: none; border: 0; color: var(--brand-text); font-size: 1.6rem; line-height: 1; padding: 0 .6rem 0 0; }
.nav-backdrop { display: none; }
@media (max-width: 991.98px) {
    .nav-toggle { display: inline-block; }
    .app-sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 1040; transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto; }
    .app-shell.nav-open .app-sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.6); }
    .app-shell.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1030; }
    .app-topbar { padding: .75rem 1rem; }
    .app-topbar .text-muted.small { display: none; }
    .app-content { padding: 1rem; }
    .table-responsive-auto { overflow-x: auto; }
}

/* ---------- LIGHT THEME (toggle in the top bar; remembered in the browser) ---------- */
html[data-bs-theme="light"] {
    --brand-bg: #f3f5fa; --brand-surface: #ffffff; --brand-surface-2: #eef1f7;
    --brand-border: rgba(15,23,42,.12); --brand-text: #0f172a; --brand-text-muted: #5b6475;
    --brand-link: #4338ca;
    color-scheme: light;
}
html[data-bs-theme="light"] body { background-color: var(--brand-bg); color: var(--brand-text); }
html[data-bs-theme="light"] .app-sidebar .nav-link.active { color: #fff; }
html[data-bs-theme="light"] .form-control::placeholder { color: #94a3b8; }
html[data-bs-theme="light"] select option, html[data-bs-theme="light"] select optgroup { background-color: #fff; color: #0f172a; }
html[data-bs-theme="light"] input:-webkit-autofill, html[data-bs-theme="light"] textarea:-webkit-autofill, html[data-bs-theme="light"] select:-webkit-autofill {
    -webkit-text-fill-color: #0f172a !important; box-shadow: 0 0 0 1000px #eef1f7 inset !important; caret-color: #0f172a; }
html[data-bs-theme="light"] .form-control:disabled, html[data-bs-theme="light"] .form-control[readonly], html[data-bs-theme="light"] .form-select:disabled { background-color: #e5e9f2; color: #64748b; }
html[data-bs-theme="light"] .form-check-input { border-color: rgba(15,23,42,.35); }
html[data-bs-theme="light"] .btn-close { filter: none; }
html[data-bs-theme="light"] .btn-close-white { filter: none; }
html[data-bs-theme="light"] .dropdown-item:hover, html[data-bs-theme="light"] .dropdown-item:focus { background-color: rgba(15,23,42,.07); color: #0f172a; }
html[data-bs-theme="light"] .alert-danger  { background-color: #fee2e2; border-color: #fca5a5; color: #991b1b; }
html[data-bs-theme="light"] .alert-success { background-color: #dcfce7; border-color: #86efac; color: #166534; }
html[data-bs-theme="light"] .alert-info    { background-color: #cffafe; border-color: #67e8f9; color: #155e75; }
html[data-bs-theme="light"] .alert-warning { background-color: #fef3c7; border-color: #fcd34d; color: #92400e; }
html[data-bs-theme="light"] .alert-primary { background-color: #e0e7ff; border-color: #a5b4fc; color: #3730a3; }
html[data-bs-theme="light"] .alert-secondary, html[data-bs-theme="light"] .alert-light { background-color: #eef1f7; color: var(--brand-text); }
html[data-bs-theme="light"] .btn-outline-light { color: #1e293b; border-color: rgba(15,23,42,.3); }
html[data-bs-theme="light"] .btn-outline-light:hover, html[data-bs-theme="light"] .btn-outline-light:focus { background-color: #1e293b; color: #fff; border-color: #1e293b; }
html[data-bs-theme="light"] .btn-outline-secondary { color: #475569; border-color: rgba(15,23,42,.25); }
html[data-bs-theme="light"] .btn-outline-secondary:hover { background-color: rgba(15,23,42,.08); color: #0f172a; }
html[data-bs-theme="light"] .btn-outline-danger { color: #b91c1c; border-color: rgba(220,38,38,.6); }
html[data-bs-theme="light"] .btn-outline-danger:hover { background-color: #dc2626; color: #fff; }
html[data-bs-theme="light"] .table { --bs-table-striped-bg: rgba(15,23,42,.03); --bs-table-hover-bg: rgba(15,23,42,.04); }
html[data-bs-theme="light"] .app-sidebar { box-shadow: 1px 0 0 var(--brand-border); }
html[data-bs-theme="light"] .card, html[data-bs-theme="light"] .stat-card { box-shadow: 0 1px 2px rgba(15,23,42,.05); }
html[data-bs-theme="light"] ::selection { background: rgba(79,70,229,.25); color: #0f172a; }
html[data-bs-theme="light"] h1, html[data-bs-theme="light"] h2, html[data-bs-theme="light"] h3, html[data-bs-theme="light"] h4, html[data-bs-theme="light"] h5, html[data-bs-theme="light"] h6 { color: var(--brand-text); }
html[data-bs-theme="light"] .app-sidebar .nav-link { color: #475569; }
html[data-bs-theme="light"] .app-sidebar .nav-link:hover { color: #0f172a; }
html[data-bs-theme="light"] .callout.due { color: #991b1b; }

.theme-toggle { background: var(--brand-surface-2); border: 1px solid var(--brand-border); color: var(--brand-text); width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1.05rem; }
.theme-toggle:hover { border-color: var(--brand-primary); }
.theme-toggle .bi-sun-fill { display: none; color: #f59e0b; }
html[data-bs-theme="dark"] .theme-toggle .bi-sun-fill { display: inline; }
html[data-bs-theme="dark"] .theme-toggle .bi-moon-stars-fill { display: none; }

/* package days-left chip in the top bar */
.sub-chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 700; padding: .25rem .65rem; border-radius: 99px; text-decoration: none;
    color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); white-space: nowrap; }
.sub-chip .up { background: color-mix(in srgb, var(--c) 70%, #000); color: #fff; border-radius: 99px; padding: .05rem .5rem; font-size: .7rem; }
.sub-chip:hover { filter: brightness(1.1); }
@media (max-width: 575.98px) { .sub-chip span { display: none; } .app-topbar strong { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }

/* shop logo in sidebar + top bar */
.app-sidebar .brand-shop { gap: .65rem; font-size: 1rem; line-height: 1.15; }
.app-sidebar .brand-shop img { width: 38px; height: 38px; object-fit: contain; border-radius: 10px; background: #fff; padding: 2px; flex-shrink: 0; }
.app-sidebar .brand-shop span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.top-logo { width: 30px; height: 30px; object-fit: contain; border-radius: 8px; background: #fff; padding: 1px; margin-right: .55rem; }

/* ---------- Mobile navigation + smooth scrolling (Phase 18) ---------- */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { -webkit-overflow-scrolling: touch; overscroll-behavior-y: none; }
.app-shell { min-height: 100vh; min-height: 100dvh; }
.app-sidebar nav { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (min-width: 992px) {
    .app-sidebar { position: sticky; top: 0; height: 100vh; align-self: flex-start; }
}
/* hamburger drawn with CSS (works even when the icon font is slow/blocked) */
.nav-toggle { width: 40px; height: 40px; padding: 0; margin-right: .5rem; border-radius: 12px; background: var(--brand-surface-2); border: 1px solid var(--brand-border); flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.nav-toggle span { display: block; width: 18px; height: 2px; border-radius: 2px; background: var(--brand-text); }
.m-tabbar { display: none; }
body.nav-lock { overflow: hidden; }
@media (max-width: 991.98px) {
    .nav-toggle { display: inline-flex; }
    .app-sidebar { height: 100vh; height: 100dvh; width: 270px; max-width: 86vw; }
    .app-topbar { position: sticky; top: 0; z-index: 1020; }
    .app-content { padding-bottom: 5.5rem; }
    .card:has(> table), .card:has(> .table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .m-tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1025; background: var(--brand-surface); border-top: 1px solid var(--brand-border);
        padding: .35rem .4rem calc(.35rem + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgba(0,0,0,.18); }
    .m-tabbar a, .m-tabbar button { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .3rem 0; font-size: .68rem; font-weight: 700; color: var(--brand-text-muted); text-decoration: none; }
    .m-tabbar i { font-size: 1.3rem; line-height: 1.2; }
    .m-tabbar a.on { color: var(--brand-primary); }
    .m-tabbar a.pos i { background: var(--brand-gradient); color: #fff; width: 46px; height: 46px; border-radius: 16px; display: flex; align-items: center; justify-content: center; margin-top: -20px; box-shadow: 0 6px 16px rgba(79,70,229,.5); }
}
@media (max-width: 991.98px) {
    .app-topbar > div:first-child { min-width: 0; overflow: hidden; flex: 1 1 auto; }
    .app-topbar > div:last-child { flex: 0 0 auto; }
    .app-topbar .badge.bg-secondary { display: none; }
}
@media (max-width: 575.98px) { .app-topbar .badge-pill { display: none; } }

/* Grouped, collapsible sidebar */
.app-sidebar .nav-group { margin: .35rem .6rem; border-radius: 12px; border: 1px solid var(--brand-border); background: var(--brand-surface); overflow: hidden; }
.app-sidebar .nav-group-btn { width: 100%; display: flex; align-items: center; gap: .65rem; padding: .6rem .7rem; background: transparent; border: 0; color: var(--brand-text); font-weight: 600; font-size: .9rem; text-align: left; cursor: pointer; }
.app-sidebar .nav-group-btn:hover { background: var(--brand-surface-2); }
.app-sidebar .ng-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: #fff; background: var(--gc); box-shadow: 0 4px 10px -4px var(--gc); }
.app-sidebar .ng-name { flex: 1; }
.app-sidebar .ng-count { font-size: .68rem; color: var(--brand-text-muted); background: var(--brand-surface-2); border-radius: 20px; padding: 0 .45rem; }
.app-sidebar .ng-chev { font-size: .75rem; color: var(--brand-text-muted); transition: transform .2s; }
.app-sidebar .nav-group.open .ng-chev { transform: rotate(180deg); }
.app-sidebar .nav-group.open { border-color: var(--gc); }
.app-sidebar .nav-group-body { display: none; padding: .1rem .3rem .4rem; }
.app-sidebar .nav-group.open .nav-group-body { display: block; }
.app-sidebar .nav-group-body .nav-link { font-size: .85rem; }
