:root {
    /* Theme: deep teal + midnight navy, warm amber for attention */
    --brand: #0f766e;          /* buttons, links (white text reads well on it) */
    --brand-dark: #115e59;
    --brand-500: #0d9488;      /* chart bars, highlights (validated for charts) */
    --brand-soft: #e6f6f4;
    --navy: #0b1324;
    --navy-2: #13213d;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --ink: #0f172a;
    --muted: #64748b;
    --sidebar-bg: linear-gradient(180deg, #0b1324 0%, #0f1d36 60%, #0c2a33 100%);
    --sidebar-text: #b6c2d4;
    --page-bg: #f3f6fa;
    --border: #e6eaf0;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
    --bs-primary: #0f766e;
    --bs-primary-rgb: 15, 118, 110;
    --bs-link-color: #0f766e;
    --bs-link-hover-color: #115e59;
    --bs-link-color-rgb: 15, 118, 110;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--page-bg);
    color: #1f2937;
    font-size: 0.925rem;
    -webkit-font-smoothing: antialiased;
}
.btn { border-radius: 9px; font-weight: 500; }
.form-control, .form-select { border-radius: 9px; border-color: #dbe1ea; }

/* Buttons in brand colour */
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand);
    --bs-btn-active-border-color: var(--brand);
}
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.form-control:focus, .form-select:focus {
    border-color: #5eb3aa;
    box-shadow: 0 0 0 .2rem rgba(15, 118, 110, .15);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* Layout */
.app-sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    min-height: 100vh;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 1030;
}
.app-main { margin-left: 240px; min-height: 100vh; }
.app-brand {
    display: flex; align-items: center; gap: .6rem;
    color: #fff; font-weight: 700; font-size: 1.08rem; letter-spacing: .01em;
    padding: 1.15rem 1.25rem; text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.app-brand:hover { color: #fff; }
.app-brand .brand-logo {
    /* No box behind the logo: a transparent logo sits straight on the dark sidebar */
    width: 44px; height: 44px; object-fit: contain; flex-shrink: 0;
}

/* Image upload previews and product thumbnails */
.image-preview {
    width: 96px; height: 96px; border: 1px dashed #cbd5e1; border-radius: 10px;
    display: grid; place-items: center; overflow: hidden; background: #f8fafc;
    color: #94a3b8; font-size: 1.8rem; flex-shrink: 0;
}
.image-preview img { width: 100%; height: 100%; object-fit: contain; }
.product-thumb {
    width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
    display: grid; place-items: center; overflow: hidden; background: #f8fafc;
    color: #cbd5e1; flex-shrink: 0;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.app-nav { padding: .75rem .6rem; }
.app-nav .nav-section {
    color: #5b6b85; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
    padding: 1rem .75rem .4rem;
}
.app-nav a {
    display: flex; align-items: center; gap: .7rem;
    color: var(--sidebar-text); text-decoration: none;
    padding: .55rem .75rem; border-radius: 10px; margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.app-nav a i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.app-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.app-nav a.active {
    background: linear-gradient(135deg, #0f766e 0%, #0d9488 100%); color: #fff;
    box-shadow: 0 6px 16px rgba(13, 148, 136, .28);
}

/* The top bar (and the "viewing as" strip above it) stay together at the top while scrolling */
.app-sticky { position: sticky; top: 0; z-index: 1020; box-shadow: 0 1px 0 var(--border), 0 4px 12px rgba(15, 23, 42, .04); }
.app-topbar {
    background: #fff;
    padding: .65rem 1.5rem;
}
.app-content { padding: 1.5rem; }

/* Shown while the Head Account is viewing the system as a branch user */
.impersonation-bar {
    background: #fde68a; color: #78350f; border-bottom: 1px solid #f59e0b;
    padding: .5rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    font-size: .875rem;
}

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); transition: transform .2s; }
    .app-sidebar.show { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
    .app-main { margin-left: 0; }
    .app-content { padding: 1rem; }
    .app-topbar { padding: .6rem 1rem; }
}

/* Cards & tables */
.card { border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-sm); }
.card-header { background: #fff; border-bottom: 1px solid var(--border); font-weight: 600; color: var(--ink); padding: .9rem 1.15rem; border-radius: 14px 14px 0 0 !important; }
.table { margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .65rem .9rem; vertical-align: middle; }
.table thead th {
    background: #f8fafc; color: #64748b; font-weight: 600; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .03em; border-bottom-width: 1px; white-space: nowrap;
}
.table tfoot td, .table tfoot th { background: #f8fafc; font-weight: 700; }
.table-hover tbody tr:hover { background: #f9fafb; }

.page-title { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-subtitle { color: #6b7280; font-size: .875rem; margin: .15rem 0 0; }

.stat-card { padding: 1.1rem 1.2rem; height: 100%; }
.stat-card .label { color: #6b7280; font-size: .8rem; font-weight: 500; }
.stat-card .value { font-size: 1.35rem; font-weight: 700; margin-top: .2rem; }
.stat-card .icon {
    width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 1.2rem;
}
.icon-teal { background: #e6f4f2; color: #0f766e; }
.icon-blue { background: #e0ecff; color: #1d4ed8; }
.icon-amber { background: #fef3c7; color: #b45309; }
.icon-red { background: #fee2e2; color: #b91c1c; }
.icon-violet { background: #ede9fe; color: #6d28d9; }
.icon-slate { background: #f1f5f9; color: #334155; }

.money-in { color: #15803d; font-weight: 600; }
.money-out { color: #b91c1c; font-weight: 600; }
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-secondary { background: #f1f5f9; color: #475569; }

.form-label { font-weight: 500; font-size: .85rem; margin-bottom: .3rem; }
/* Only labels get the red star (not inputs or search boxes that carry a "required" class) */
label.required::after, .form-label.required::after { content: " *"; color: #dc2626; }

.detail-list dt { color: #6b7280; font-weight: 500; font-size: .82rem; }
.detail-list dd { margin-bottom: .75rem; }

.empty-state { text-align: center; color: #9ca3af; padding: 2.5rem 1rem; }
.empty-state i { font-size: 2rem; display: block; margin-bottom: .5rem; }

/* Product search in sale / purchase forms */
.product-search { position: relative; }
.product-results {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 50;
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,.08); max-height: 300px; overflow-y: auto; display: none;
}
.product-results .item { padding: .55rem .8rem; cursor: pointer; display: flex; justify-content: space-between; gap: 1rem; }
.product-results .item:hover, .product-results .item.active { background: var(--brand-soft); }

/* Sale / purchase product lines: inputs keep a usable width; the table scrolls sideways on small screens */
#items-table { min-width: 620px; }
#items-table > :not(caption) > * > * { padding: .55rem .5rem; }
#items-table .input-group { flex-wrap: nowrap; }
#items-table .qty { min-width: 56px; }
#items-table .price, #items-table .sale-price { min-width: 78px; }
#items-table .discount { min-width: 54px; }
.totals-box .row-line { display: flex; justify-content: space-between; padding: .35rem 0; }
.totals-box .grand { font-size: 1.15rem; font-weight: 700; border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .25rem; }

.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f766e 0%, #0f172a 100%); padding: 1rem; }
.login-card { width: 100%; max-width: 400px; border-radius: 16px; }

/* Printing invoices and reports */
.print-only { display: none; }
@media print {
    .app-sidebar, .app-topbar, .no-print, .pagination { display: none !important; }
    .app-main { margin-left: 0; }
    .app-content { padding: 0; }
    .print-only { display: block; }
    body { background: #fff; font-size: 12px; }
    .table-responsive { overflow: visible !important; }
    .table > :not(caption) > * > * { padding: .35rem .5rem; }    .card { border: none; box-shadow: none; }
    a { text-decoration: none; color: inherit; }
}

/* ===================== Dashboard ===================== */
.dash-hero {
    position: relative; overflow: hidden; border-radius: 18px; color: #fff;
    background: radial-gradient(circle at 85% 20%, rgba(45, 212, 191, .35) 0, transparent 45%),
                linear-gradient(120deg, #0b1324 0%, #10284a 45%, #0f766e 100%);
    padding: 1.6rem 1.75rem; box-shadow: var(--shadow-md);
}
.dash-hero::after {
    content: ""; position: absolute; right: -60px; bottom: -80px; width: 260px; height: 260px;
    border-radius: 50%; border: 36px solid rgba(255, 255, 255, .05);
}
.dash-hero .greet { font-size: 1.5rem; font-weight: 700; margin: 0; }
.dash-hero .sub { color: rgba(255, 255, 255, .72); margin: .2rem 0 1.1rem; }
.dash-hero .hero-actions .btn { padding: .4rem .8rem; font-size: .875rem;
    background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .22); color: #fff;
    backdrop-filter: blur(4px);
}
.dash-hero .hero-actions .btn:hover { background: rgba(255, 255, 255, .22); }
.dash-hero .hero-actions .btn.btn-light-solid { background: #fff; color: var(--brand); border-color: #fff; }
.dash-hero .hero-actions .btn.btn-light-solid:hover { background: #ecfdf8; }
.hero-figure { position: relative; z-index: 1; text-align: right; }
.hero-figure .label { color: rgba(255, 255, 255, .7); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.hero-figure .value { font-size: 2.1rem; font-weight: 800; line-height: 1.15; letter-spacing: -.01em; }
.hero-figure .meta { color: rgba(255, 255, 255, .78); font-size: .85rem; }

.trend { display: inline-flex; align-items: center; gap: .2rem; font-size: .78rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; }
.trend-up { background: #dcfce7; color: #166534; }
.trend-down { background: #fee2e2; color: #991b1b; }
.trend-flat { background: #f1f5f9; color: #475569; }
.dash-hero .trend-up { background: rgba(134, 239, 172, .2); color: #bbf7d0; }
.dash-hero .trend-down { background: rgba(252, 165, 165, .2); color: #fecaca; }
.dash-hero .trend-flat { background: rgba(255, 255, 255, .14); color: #e2e8f0; }

.kpi {
    position: relative; padding: 1.1rem 1.2rem; height: 100%; overflow: hidden;
    transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-accent, var(--brand-500)); }
.kpi .kpi-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.kpi .kpi-value { font-size: clamp(1.05rem, 1.35vw, 1.4rem); font-weight: 700; color: var(--ink); margin: .25rem 0 .15rem; letter-spacing: -.01em; white-space: nowrap; }
.kpi .kpi-body { min-width: 0; }
.kpi .kpi-meta { color: var(--muted); font-size: .78rem; }
.kpi .kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; flex-shrink: 0; }

.section-title { font-size: .95rem; font-weight: 700; color: var(--ink); margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: 1rem 1.15rem .25rem; }
.card-head .hint { color: var(--muted); font-size: .8rem; }

/* 14-day sales bars (single series, one hue) */
.bar-chart { position: relative; padding: .75rem 1.15rem 1rem 3.2rem; }
.bar-chart .plot { position: relative; height: 210px; }
.bar-chart .gridline { position: absolute; left: 0; right: 0; border-top: 1px dashed #e8edf3; }
.bar-chart .gridline span { position: absolute; left: -3.1rem; top: -.55rem; width: 2.8rem; text-align: right; font-size: .7rem; color: #94a3b8; }
.bar-chart .baseline { position: absolute; left: 0; right: 0; bottom: 0; border-top: 1px solid #cbd5e1; }
.bar-chart .bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.bar-chart .bar-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; cursor: default; }
.bar-chart .bar {
    width: 62%; min-width: 6px; max-width: 30px; background: var(--brand-500);
    border-radius: 4px 4px 0 0; transition: filter .15s;
}
.bar-chart .bar-slot.is-today .bar { background: #0f766e; }
.bar-chart .bar-slot:hover .bar, .bar-chart .bar-slot:focus .bar { filter: brightness(1.12); }
.bar-chart .bar-slot:focus { outline: none; }
.bar-chart .bar-slot:focus-visible .bar { outline: 2px solid var(--ink); outline-offset: 2px; }
.bar-chart .x-labels { display: flex; gap: 2px; margin-top: .4rem; }
.bar-chart .x-labels span { flex: 1; min-width: 0; text-align: center; font-size: .68rem; color: #94a3b8; white-space: nowrap; overflow: visible; }
.bar-chart .bar-slot { min-width: 0; }
@media (max-width: 575.98px) {
    .bar-chart { padding-left: 2.6rem; padding-right: .75rem; }
    .bar-chart .x-labels span.lbl-alt { visibility: hidden; }
    .dash-hero { padding: 1.25rem; }
    .dash-hero .greet { font-size: 1.2rem; }
    .hero-figure { text-align: left; }
    .hero-figure .value { font-size: 1.6rem; }
}
.bar-chart .x-labels span.is-today { color: var(--ink); font-weight: 600; }
.chart-tooltip {
    position: absolute; pointer-events: none; z-index: 5; background: var(--ink); color: #fff;
    font-size: .78rem; padding: .45rem .6rem; border-radius: 8px; white-space: nowrap;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .25); transform: translate(-50%, calc(-100% - 10px)); display: none;
}
.chart-tooltip strong { display: block; font-size: .9rem; }

/* Balance tiles */
.balance-tile { display: flex; align-items: center; gap: .85rem; padding: .85rem 0; border-bottom: 1px solid #eef2f6; }
.balance-tile:last-child { border-bottom: 0; }
.balance-tile .bt-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 1.1rem; flex-shrink: 0; }
.balance-tile .bt-label { color: var(--muted); font-size: .8rem; }
.balance-tile .bt-value { font-weight: 700; font-size: clamp(.95rem, 1.2vw, 1.1rem); color: var(--ink); white-space: nowrap; }
.balance-tile > .flex-grow-1 { min-width: 0; }
.flow-bar { height: 8px; border-radius: 999px; background: #eef2f6; overflow: hidden; display: flex; gap: 2px; }
.flow-bar span { display: block; height: 100%; }
.flow-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem .75rem; }

/* Lists */
.rank-item { display: flex; align-items: center; gap: .75rem; padding: .65rem 1.15rem; min-width: 0; }
.min-w-0 { min-width: 0; }
/* Long product names shorten with ... so the amount always stays inside the card */
.rank-item .rank-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-item .rank-amount { flex-shrink: 0; white-space: nowrap; }
.rank-item + .rank-item { border-top: 1px solid #f1f4f8; }
.rank-no { width: 26px; height: 26px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .8rem; display: grid; place-items: center; flex-shrink: 0; }
.rank-bar { height: 4px; border-radius: 999px; background: #eef2f6; margin-top: .3rem; }
.rank-bar span { display: block; height: 100%; border-radius: 999px; background: var(--brand-500); }
.avatar-chip { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: .8rem; background: #eef2ff; color: #3730a3; flex-shrink: 0; }
.acct-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 1.15rem; }
.acct-row + .acct-row { border-top: 1px solid #f1f4f8; }
.acct-icon { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem; line-height: 1; flex-shrink: 0; }
.acct-icon i { display: block; line-height: 1; }
/* Full-width card: accounts side by side */
.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); column-gap: 1rem; padding: 0 .25rem; }
.acct-grid .acct-row { border-top: 1px solid #f1f4f8; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* Eye prescription table (R. Eye / L. Eye x SPH CYL AXIS, Distance / Near) */
.rx-table { min-width: 560px; }
.rx-table > :not(caption) > * > * { padding: .35rem .4rem; vertical-align: middle; }
.rx-table thead th { background: var(--brand-soft); color: var(--brand-dark); font-size: .75rem; letter-spacing: .02em; }
.rx-table tbody th { background: #f8fafc; font-size: .8rem; color: var(--ink); }
.rx-table input { min-width: 62px; }

/* Bottom of lists: count, page numbers, rows per page */
.list-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.list-footer .pagination { --bs-pagination-color: var(--brand); --bs-pagination-hover-color: var(--brand-dark); --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(15, 118, 110, .15); }
.list-footer .page-link { border-radius: 8px !important; margin: 0 2px; }

/* Categories page */
.cat-block + .cat-block { border-top: 1px solid var(--border); }
.cat-row { display: flex; align-items: center; gap: .6rem; padding: .55rem 1rem; }
.cat-row.cat-main { background: #f8fafc; }
.cat-row.cat-sub { padding-left: 2.2rem; }
.cat-edit { display: flex; align-items: center; gap: .4rem; flex: 1; min-width: 0; }
.cat-edit .form-control { max-width: 280px; border-color: transparent; background: transparent; }
.cat-edit .form-control:hover, .cat-edit .form-control:focus { border-color: #dbe1ea; background: #fff; }
/* Product colors */
.color-row .input-group-text { min-width: 0; }
.color-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); vertical-align: middle; }

.cat-row.cat-add { background: var(--brand-soft); }
.cat-add .form-control { max-width: 340px; }

/* System popup (replaces browser alert / confirm) */
.app-dialog { border: 0; border-radius: 16px; box-shadow: 0 20px 50px rgba(15, 23, 42, .25); }
.app-dialog .dialog-icon { font-size: 2.6rem; line-height: 1; display: inline-block; }
.app-dialog .dialog-message { white-space: pre-line; font-size: .95rem; }
#app-dialog + .modal-backdrop, .modal-backdrop.show { opacity: .45; }