:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --sidebar-bg: #0f172a;
    --sidebar-fg: #cbd5e1;
    --sidebar-fg-active: #ffffff;
    --sidebar-active: #4f46e5;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --sidebar-w: 250px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    background: var(--body-bg);
    color: var(--text);
    font-size: 14.5px;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1.15rem 1.25rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 34px; height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), #7c3aed);
    color: #fff; font-weight: 800; font-size: .95rem;
}
.brand-mark.lg { width: 54px; height: 54px; font-size: 1.4rem; border-radius: 14px; }

.sidebar-nav { padding: .75rem .6rem; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
.sidebar-nav .nav-link { font-size: .9rem; padding: .55rem .8rem; }

.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: .75rem;
    padding: .62rem .8rem;
    color: var(--sidebar-fg);
    border-radius: 9px;
    text-decoration: none;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: var(--sidebar-fg-active); box-shadow: 0 4px 12px rgba(79, 70, 229, .4); }

.sidebar-footer { padding: 1rem 1.25rem; color: #64748b; border-top: 1px solid rgba(255, 255, 255, .06); }

.app-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar {
    height: 62px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.4rem;
    position: sticky; top: 0; z-index: 1030;
}
.topbar-title { font-size: 1.15rem; font-weight: 650; margin: 0; }
.topbar-right { margin-left: auto; }

.btn-icon { background: transparent; border: 0; font-size: 1.35rem; color: var(--text-muted); display: none; }

.btn-user { display: flex; align-items: center; gap: .6rem; background: transparent; border: 0; color: var(--text); font-weight: 500; }
.avatar {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand); font-weight: 700;
}

/* ---------- Content ---------- */
.content { padding: 1.6rem; flex: 1; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: #fff; }
.card-title { font-size: 1.02rem; font-weight: 650; margin: 0; }
.card-body { padding: 1.25rem; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1.1rem; }
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.15rem 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    color: var(--text); text-decoration: none;
    transition: transform .12s ease, box-shadow .12s ease;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15, 23, 42, .1); color: var(--text); }
.stat-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 13px; font-size: 1.4rem; }
.stat-body { display: flex; flex-direction: column; }
.stat-value { font-size: 1.7rem; font-weight: 750; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: .85rem; }

.bg-primary-soft { background: #eef2ff; color: #4f46e5; }
.bg-success-soft { background: #dcfce7; color: #16a34a; }
.bg-warning-soft { background: #fef3c7; color: #d97706; }
.bg-info-soft { background: #cffafe; color: #0891b2; }

/* ---------- Tables ---------- */
.table { color: var(--text); }
.table > thead > tr > th {
    font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); font-weight: 650; border-bottom: 1px solid var(--border);
    background: #f8fafc; padding: .7rem 1rem;
}
.table > tbody > tr > td { padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.table-hover > tbody > tr:hover { background: #f8fafc; }

.table-search { position: relative; max-width: 320px; flex: 1; min-width: 180px; }
.table-search i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.table-search input { padding-left: 2.2rem; border-radius: 9px; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; padding: .35em .7em; border-radius: 6px; font-size: .74rem; }
.badge-active { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #fee2e2; color: #b91c1c; }

/* ---------- Buttons ---------- */
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-primary { color: var(--brand); border-color: var(--brand); }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); }
.btn { border-radius: 8px; font-weight: 500; }

.form-control, .form-select { border-radius: 8px; border-color: var(--border); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }
.form-label { font-weight: 550; font-size: .85rem; margin-bottom: .3rem; color: #334155; }

/* ---------- Auth / login ---------- */
.auth-body { background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
    background: #fff; width: 100%; max-width: 400px;
    border-radius: 18px; padding: 2.4rem 2.2rem;
    box-shadow: 0 20px 45px rgba(15, 23, 42, .25);
}
.auth-brand { text-align: center; margin-bottom: 1.8rem; }
.auth-brand .brand-mark { margin: 0 auto .8rem; }
.auth-brand h1 { font-size: 1.5rem; font-weight: 750; margin: 0; }
.auth-brand p { color: var(--text-muted); margin: .15rem 0 0; font-size: .9rem; }
.form-floating > label { color: var(--text-muted); }

/* ---------- Dashboard ---------- */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .75rem; margin-bottom: 1.4rem;
}
.page-head .greeting { font-size: 1.4rem; font-weight: 750; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--text-muted); font-size: .9rem; margin: .15rem 0 0; }
.page-head .today {
    display: inline-flex; align-items: center; gap: .5rem;
    background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
    padding: .55rem .9rem; font-weight: 550; color: var(--text-muted); box-shadow: var(--shadow);
}
.page-head .today i { color: var(--brand); }

/* Accent stat cards */
.stat-card { position: relative; overflow: hidden; }
.stat-card::before {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; border-radius: 4px 0 0 4px;
    background: var(--accent, var(--brand));
}
.stat-card .stat-icon { box-shadow: inset 0 0 0 1px rgba(15,23,42,.04); }
.stat-accent-blue { --accent: #0284c7; }
.stat-accent-green { --accent: #16a34a; }
.stat-accent-red { --accent: #dc2626; }
.stat-accent-amber { --accent: #d97706; }
.stat-card .stat-go { margin-left: auto; color: var(--text-muted); opacity: 0; transition: opacity .12s, transform .12s; }
a.stat-card:hover .stat-go { opacity: 1; transform: translateX(2px); }

/* Section header with icon */
.section-head { display: flex; align-items: center; gap: .6rem; }
.section-head .sec-ico {
    display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
    background: var(--brand-soft); color: var(--brand); font-size: .95rem; flex: none;
}

/* Numeric emphasis in tables */
.num-pos { color: #15803d; font-weight: 650; }
.num-neg { color: #b91c1c; font-weight: 650; }
.net-badge {
    display: inline-block; padding: .2em .6em; border-radius: 6px; font-weight: 650; font-size: .8rem;
}
.net-badge.pos { background: #dcfce7; color: #15803d; }
.net-badge.neg { background: #fee2e2; color: #b91c1c; }

.accordion-button:not(.collapsed) { background: var(--brand-soft); color: var(--brand-dark); box-shadow: none; }
.accordion-button:focus { box-shadow: none; border-color: var(--border); }
.accordion-item { border-color: var(--border); }

/* ---------- Color-coded DataTables (dashboard) ---------- */
.color-table { border-collapse: separate; }
.color-table thead th {
    background: #0f172a !important; color: #fff !important;
    font-weight: 700 !important; text-transform: uppercase; letter-spacing: .03em;
    border: none !important; padding: 10px 12px !important; vertical-align: middle;
}
.color-table tbody td {
    padding: 10px 12px !important; vertical-align: middle;
    border: 1px solid rgba(255, 255, 255, .18) !important;
}
.color-table tbody tr:hover td { filter: brightness(1.04); }

.dt-blue, .dt-blue a { background: linear-gradient(135deg, #0284c7, #0369a1) !important; color: #fff !important; font-weight: 700 !important; text-align: right; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.dt-red, .dt-red a { background: linear-gradient(135deg, #ef4444, #b91c1c) !important; color: #fff !important; font-weight: 700 !important; text-align: right; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.dt-amber, .dt-amber a { background: linear-gradient(135deg, #f59e0b, #d97706) !important; color: #fff !important; font-weight: 700 !important; text-align: right; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.dt-gray { background: #f1f5f9 !important; color: #0f172a !important; font-weight: 600 !important; }
.dt-gray a { color: #0f172a !important; font-weight: 700 !important; text-decoration: none; }
.dt-gray a:hover { text-decoration: underline; }
.dt-lightblue { background: #e0f2fe !important; color: #0369a1 !important; font-weight: 700 !important; }
.dt-lightblue a { color: #0369a1 !important; font-weight: 700 !important; text-decoration: none; }

.color-table tfoot th {
    background: #0f172a !important; color: #fff !important;
    font-weight: 700 !important; font-size: .95rem; padding: 12px !important; border: none !important;
}

/* code pill for script names */
.code-pill {
    display: inline-block; padding: .2em .6em; border-radius: 6px;
    background: #e2e8f0; color: #0f172a; font-weight: 650; font-size: .78rem;
}

/* Customer Report expand control + child table */
td.details-control { cursor: pointer; text-align: center; }
td.details-control i { transition: transform .15s; }
tr.shown td.details-control i { transform: rotate(45deg); }
.child-detail-table { width: 100%; margin: 0; }
.child-detail-table th { background: #0f172a !important; color: #fff !important; font-size: .72rem; padding: 6px 10px !important; text-transform: uppercase; }
.child-detail-table td { background: linear-gradient(135deg, #0284c7, #0369a1) !important; color: #fff !important; font-weight: 600 !important; padding: 6px 10px !important; border: 1px solid rgba(255,255,255,.2) !important; text-align: right; }
.child-detail-table td.txt { text-align: left; }

/* ---------- Client (customer) area ---------- */
.client-body { background: #f1f5f9; min-height: 100vh; }
.client-topbar {
    background: linear-gradient(90deg, #5b9bd5, #4a90d9); color: #fff;
    height: 66px; display: flex; align-items: center; padding: 0 1.5rem;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .12); position: sticky; top: 0; z-index: 1030;
}
.client-logo { display: inline-flex; text-decoration: none; }
.client-logo .brand-mark { width: 44px; height: 44px; font-size: 1.05rem; }
.client-user { color: #fff !important; background: transparent; border: 0; font-weight: 600; font-size: 1rem; }
.client-content { max-width: 1400px; margin: 0 auto; padding: 1.6rem; }
.client-title { font-size: 1.9rem; font-weight: 700; color: #334155; margin: 0; }
.client-crumbs { color: #64748b; font-size: .92rem; }
.client-crumbs .active { color: #334155; font-weight: 600; }
.client-crumbs .sep { margin: 0 .4rem; }
.client-table thead th {
    background: linear-gradient(90deg, #5b9bd5, #4a90d9) !important; color: #fff !important;
    border: none !important; font-weight: 700 !important; padding: 12px !important; white-space: nowrap;
}
.client-table tbody td { padding: 11px 12px !important; vertical-align: middle; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .btn-icon { display: inline-block; }
}
