:root {
    --ink: #0f172a;
    --muted: #64748b;
    --canvas: #f4f6fb;
    --card: #ffffff;
    --line: #e6e8f0;
    --brand: #4f46e5;
    --brand-2: #7c3aed;
    --brand-grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --accent: #f59e0b;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15,23,42,.05), 0 4px 16px rgba(15,23,42,.06);
    --shadow-lg: 0 8px 30px rgba(79,70,229,.18);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-height: 100vh;
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.92rem;
    -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4,h5,h6 { letter-spacing: -0.02em; }

#appBody { min-height: 100vh; padding-top: 68px; }

/* ---------- Navigation ---------- */
.topnav {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1040;
    min-height: 68px;
    background: linear-gradient(135deg, rgba(23,21,59,.96), rgba(30,27,75,.93));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 1px 0 rgba(255,255,255,.06);
}
.topnav .navbar-brand {
    color: #fff;
    font-weight: 700;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: .55rem;
}
.brand-mark {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: var(--brand-grad);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    overflow: hidden;
    font-size: 1.05rem;
    box-shadow: 0 4px 14px rgba(79,70,229,.45);
}
.brand-mark img { display: block; }
.topnav .nav-link {
    color: #cbd5e1;
    font-weight: 500;
    padding: .5rem .75rem;
    border-radius: 8px;
    transition: color .15s ease, background .15s ease;
}
.topnav .nav-link:hover, .topnav .nav-link:focus { color: #fff; background: rgba(255,255,255,.08); }
.topnav .nav-link.active { color: #fff; background: rgba(255,255,255,.14); font-weight: 600; }
.topnav .nav-link i { margin-right: .4rem; font-size: .95em; }
.topnav .dropdown-toggle::after { display: none; }
.topnav .dropdown-menu {
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: .4rem;
    margin-top: .5rem !important;
}
.topnav .dropdown-item { border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; }
.topnav .dropdown-item i { margin-right: .5rem; }
.topnav .dropdown-item.active { background: rgba(79,70,229,.10); color: var(--brand); font-weight: 600; }
.topnav .dropdown-item.active i { color: var(--brand); }

/* ---------- Cards / surfaces ---------- */
.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
    transition: transform .18s ease, box-shadow .18s ease;
}
.card:hover { box-shadow: 0 2px 4px rgba(15,23,42,.06), 0 12px 28px rgba(15,23,42,.1); }
a.card { color: inherit; }
a.card:hover { transform: translateY(-2px); }
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0 !important;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    font-size: .95rem;
    padding: .9rem 1.15rem;
}
.card-body { padding: 1.15rem; }

.stat-card .stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 6px 14px rgba(15,23,42,.12);
}
.stat-card .stat-icon.indigo { background: linear-gradient(135deg,#4f46e5,#6366f1); }
.stat-card .stat-icon.violet { background: linear-gradient(135deg,#7c3aed,#a855f7); }
.stat-card .stat-icon.sky    { background: linear-gradient(135deg,#0284c7,#38bdf8); }
.stat-card .stat-icon.emerald{ background: linear-gradient(135deg,#059669,#34d399); }
.stat-card .stat-icon.amber  { background: linear-gradient(135deg,#d97706,#fbbf24); }
.stat-card .stat-icon.teal   { background: linear-gradient(135deg,#0d9488,#2dd4bf); }
.stat-card .stat-icon.rose   { background: linear-gradient(135deg,#e11d48,#fb7185); }
.stat-card .stat-icon.slate  { background: linear-gradient(135deg,#334155,#64748b); }
.stat-card .stat-icon.red    { background: linear-gradient(135deg,#dc2626,#f87171); }
.stat-card .stat-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}
.stat-card .stat-value { font-weight: 800; letter-spacing: -0.03em; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .8rem; letter-spacing: .01em; }
.form-control, .form-select {
    border-radius: 10px;
    border: 1.5px solid var(--line);
    background: #fbfcfe;
    font-size: .92rem;
    padding: .55rem .8rem;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 3.5px rgba(79,70,229,.13);
}
.form-text { font-size: .78rem; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { border-radius: 10px; font-weight: 600; padding: .5rem .95rem; transition: all .16s ease; }
.btn-brand { background: var(--brand-grad); color: #fff; border: none; box-shadow: 0 4px 14px rgba(79,70,229,.35); }
.btn-brand:hover { color: #fff; filter: brightness(1.07); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,70,229,.45); }
.btn-outline-brand { background: #fff; color: var(--brand); border: 1.5px solid var(--brand); }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }
.offline-queue { max-height: 18rem; overflow: auto; }
.btn-dark { background: var(--ink); border: none; }
.btn-dark:hover { background: #1e293b; transform: translateY(-1px); }
.btn-outline-secondary { border-color: var(--line); color: var(--ink); }
.btn-outline-secondary:hover { background: #f1f3f9; color: var(--ink); border-color: var(--line); }
.btn-sm { border-radius: 8px; padding: .3rem .6rem; }
.btn-outline-primary { color: var(--brand); border-color: #c7d2fe; }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); }

/* ---------- Tables ---------- */
.table > :not(caption) > * > * { padding: .65rem .85rem; vertical-align: middle; }
.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    font-weight: 700;
    color: var(--muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--line) !important;
    white-space: nowrap;
}
.table-light th { color: var(--muted); background: #f8fafc !important; }

/* ---------- Badges ---------- */
.badge {
    font-weight: 600;
    padding: .38em .65em;
    border-radius: 8px;
    letter-spacing: .01em;
}

/* ---------- Alerts / flash ---------- */
.alert { border-radius: 12px; border: none; font-size: .9rem; font-weight: 500; }
.alert-dismissible .btn-close { top: 50%; transform: translateY(-50%); }

/* ---------- Auth screens ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    background: var(--canvas);
    position: relative;
    overflow: hidden;
}
.auth-aside {
    display: none;
    flex: 0 0 46%;
    max-width: 46%;
    background: linear-gradient(160deg, #1e1b4b 0%, #312e81 45%, #6d28d9 100%);
    color: #fff;
    position: relative;
    padding: 3.5rem;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}
.auth-aside::before, .auth-aside::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: .55;
}
.auth-aside::before { width: 340px; height: 340px; background: #8b5cf6; top: -120px; right: -80px; }
.auth-aside::after { width: 320px; height: 320px; background: #f59e0b; bottom: -140px; left: -100px; opacity: .3; }
.auth-aside > * { position: relative; z-index: 1; }
.auth-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.25rem;
}
.auth-card {
    width: 100%;
    max-width: 430px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 12px 48px rgba(15,23,42,.12);
    padding: 2.2rem;
}
.auth-card h2 { font-weight: 700; letter-spacing: -0.03em; }
.auth-card .lead { color: var(--muted); font-size: .95rem; }
.auth-brand { display: flex; align-items: center; gap: 1rem; font-weight: 700; font-size: 1.1rem; }
.brand-text-glow { text-shadow: 0 2px 30px rgba(139,92,246,.65); }
.auth-logo {
    width: 54px; height: 54px;
    border-radius: 15px;
    background: #fff;
    color: #4f46e5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    font-size: 1.25rem;
    box-shadow: 0 8px 22px rgba(0,0,0,.28), 0 0 0 6px rgba(255,255,255,.08), 0 0 34px rgba(139,92,246,.55);
    overflow: hidden;
}
.auth-logo img { display: block; }
.feature-tile {
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 14px;
    padding: .9rem 1rem;
    backdrop-filter: blur(4px);
}
.feature-tile i { color: #fde68a; opacity: .9; font-size: 1.2rem; }
.feature-tile p { font-size: .78rem; opacity: .8; margin: .2rem 0 0; }

@media (min-width: 992px) {
    .auth-aside { display: flex; }
}

/* ---------- Landing ---------- */
.landing-hero {
    background: linear-gradient(160deg, #1e1b4b 0%, #312e81 50%, #6d28d9 100%);
    color: #fff;
    border-radius: var(--radius);
    padding: 4.5rem 2rem;
    position: relative;
    overflow: hidden;
}
.landing-hero::after {
    content: '';
    position: absolute;
    width: 520px; height: 520px;
    border-radius: 50%;
    background: rgba(139,92,246,.35);
    filter: blur(90px);
    top: -160px; right: -140px;
}
.landing-hero > * { position: relative; z-index: 1; }
.landing-logo {
    width: 116px; height: 116px;
    border-radius: 30px;
    background: #fff;
    color: #4f46e5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    font-size: 2rem;
    box-shadow: 0 16px 50px rgba(0,0,0,.28), 0 0 0 8px rgba(79,70,229,.08), 0 0 70px rgba(124,58,237,.4);
    overflow: hidden;
}
.landing-logo img { display: block; }
.landing-title {
    font-size: 4.25rem;
    line-height: 1;
    letter-spacing: -.045em;
    font-weight: 800;
    background: linear-gradient(90deg, #1e1b4b 0%, #4f46e5 45%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 2px 16px rgba(79,70,229,.28));
}
.landing-tile {
    background: #fff;
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 16px;
    padding: .9rem .4rem;
    box-shadow: 0 6px 18px rgba(15,23,42,.06);
}
.landing-tile i { font-size: 1.3rem; color: #4f46e5; }
.landing-tile p { font-size: .8rem; color: var(--ink); margin: .25rem 0 0; }
.landing-stat i { font-size: 1.4rem; color: #fbbf24; }
.landing-stat p { font-size: .8rem; opacity: .8; margin: .35rem 0 0; }

/* ---------- Misc ---------- */
.progress { border-radius: 10px; background: #eef1f8; }
.page-title { font-weight: 700; letter-spacing: -0.02em; }
.page-sub { color: var(--muted); font-size: .85rem; }
.list-group-item { border-color: var(--line); }

/* ---------- Form page header ---------- */
.form-page-header {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.3rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-page-header .step-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--brand-grad);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 14px rgba(79,70,229,.32);
}

/* ---------- Icon inputs ---------- */
.input-icon-wrap { position: relative; }
.input-icon-wrap > i {
    position: absolute;
    left: .85rem; top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: .95rem;
    pointer-events: none;
    z-index: 2;
}
.input-icon-wrap .form-control,
.input-icon-wrap .form-select { padding-left: 2.5rem; }
.input-icon-wrap.currency .form-control { padding-left: 4.7rem; }
.input-currency-prefix {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    font-weight: 600;
    font-size: .82rem;
    border-right: 1.5px solid var(--line);
    background: #f8fafc;
    border-radius: 10px 0 0 10px;
    z-index: 2;
    pointer-events: none;
}

/* ---------- Field label pills ---------- */
.field-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: .35rem;
}

/* ---------- Margin preview ---------- */
.margin-banner {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border: 1px solid #bbf7d0;
    color: #166534;
    border-radius: 12px;
    padding: .9rem 1.1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
}
.margin-banner.negative { background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%); border-color: #fecaca; color: #991b1b; }
.margin-banner .value { font-weight: 800; font-size: 1.15rem; }
.margin-banner .hint { font-size: .78rem; opacity: .8; }
.margin-dot {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: #16a34a;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.margin-banner.negative .margin-dot { background: #dc2626; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 768px) {
    #appBody { padding-top: 60px; }
    .topnav { min-height: 60px; backdrop-filter: none; -webkit-backdrop-filter: none; }
    .topnav .navbar-collapse {
        max-height: calc(100vh - 60px);
        overflow-y: auto;
        padding: .5rem 0 .75rem;
    }
    .auth-card { padding: 1.6rem; }
    .landing-hero { padding: 3rem 1.25rem; }
}

/* ---------- Narrow phones: keep nav + stat cards on-screen ---------- */
@media (max-width: 575.98px) {
    .topnav { overflow: hidden; }
    .topnav .navbar-brand { min-width: 0; max-width: 72%; }
    .topnav .brand-mark { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px; }
    .topnav .navbar-brand .lh-sm { min-width: 0; }
    .topnav .navbar-brand .lh-sm small,
    .topnav .navbar-brand .lh-sm span {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .topnav .navbar-toggler { margin-left: .5rem; flex: 0 0 auto; }

    .stat-card .card-body { flex-wrap: wrap; align-content: flex-start; }
    .stat-card .stat-icon { width: 38px; height: 38px; font-size: 1.05rem; }
    .stat-card .stat-value { font-size: 1rem; }
    .stat-card .card-body > div { min-width: 0; overflow: hidden; }
}

@media print {
    .topnav, .btn, form, .no-print { display: none !important; }
    #appBody { padding-top: 0; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}