:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --bg: #f4f5fb;
    --surface: #ffffff;
    --border: #e6e8f0;
    --text: #1f2333;
    --muted: #6b7280;
    --sidebar-bg: #171a2b;
    --sidebar-bg-active: #262b45;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 15px;
}

a { text-decoration: none; }

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

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: #cbd0e6;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.35rem 1.25rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .2px;
}

.sidebar-brand .brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #7c6cf3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

.sidebar-nav {
    flex: 1;
    padding: .5rem .75rem;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .65rem .85rem;
    border-radius: var(--radius-sm);
    color: #b6bbd6;
    font-weight: 500;
    font-size: .92rem;
    margin-bottom: .15rem;
    transition: background .15s ease, color .15s ease;
}

.sidebar-nav a i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-nav a:hover {
    background: var(--sidebar-bg-active);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-footer .user-pill {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .7rem;
    border-radius: var(--radius-sm);
    background: var(--sidebar-bg-active);
    margin-bottom: .5rem;
    font-size: .85rem;
    color: #e3e6f5;
}

.sidebar-footer .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: .8rem;
    flex-shrink: 0;
}

.sidebar-footer a.logout-link {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .7rem;
    border-radius: var(--radius-sm);
    color: #f3a6a6;
    font-size: .88rem;
    font-weight: 500;
}

.sidebar-footer a.logout-link:hover { background: rgba(220,38,38,.15); color: #fff; }

.main {
    margin-left: 250px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: .85rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar .brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.sidebar-toggle {
    border: none;
    background: var(--primary-light);
    color: var(--primary);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 1.1rem;
}

.content {
    padding: 1.75rem;
    max-width: 1180px;
    width: 100%;
    margin: 0 auto;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 24, .45);
    z-index: 1025;
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar { display: flex; }
    .sidebar-backdrop.open { display: block; }
}

/* ---------- Page header ---------- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.45rem;
    font-weight: 700;
    margin: 0 0 .2rem;
}

.page-header p {
    color: var(--muted);
    margin: 0;
    font-size: .9rem;
}

/* ---------- Cards ---------- */
.card-modern {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.4rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.stat-card .stat-label {
    font-size: .8rem;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-card .stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .35rem;
    font-size: 1.05rem;
}

.icon-indigo { background: var(--primary-light); color: var(--primary); }
.icon-green { background: var(--success-light); color: var(--success); }
.icon-amber { background: var(--warning-light); color: var(--warning); }
.icon-red { background: var(--danger-light); color: var(--danger); }

.text-profit { color: var(--success); }
.text-loss { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
    border-radius: var(--radius-sm) !important;
    font-weight: 600;
    font-size: .875rem;
    padding: .5rem 1rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-sm { padding: .32rem .7rem; font-size: .8rem; }

/* ---------- Table card ---------- */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-card .table-card-header {
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.table-card .table-card-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.table-modern {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

.table-modern thead th {
    background: #fafafe;
    color: var(--muted);
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
    padding: .8rem 1.4rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.table-modern tbody td {
    padding: .85rem 1.4rem;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
    vertical-align: middle;
}

.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr:hover { background: #fafbff; }

.badge-soft {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .28rem .65rem;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 600;
}

.badge-green { background: var(--success-light); color: #15803d; }
.badge-red { background: var(--danger-light); color: #b91c1c; }
.badge-amber { background: var(--warning-light); color: #b45309; }
.badge-gray { background: #eef0f5; color: #4b5164; }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}

.empty-state i { font-size: 2rem; color: #c8cbdb; margin-bottom: .6rem; display: block; }

/* ---------- Forms ---------- */
.form-shell {
    max-width: 560px;
}

.form-label {
    font-weight: 600;
    font-size: .85rem;
    color: var(--text);
    margin-bottom: .3rem;
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: .55rem .8rem;
    font-size: .9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ---------- Auth / login ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #171a2b 0%, #2c2f55 60%, #4f46e5 130%);
    padding: 1.5rem;
}

.auth-card {
    background: var(--surface);
    border-radius: 18px;
    box-shadow: var(--shadow-md);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 380px;
}

.auth-card .brand-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #7c6cf3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.3rem;
    margin-bottom: 1rem;
}

/* ---------- Alerts / flash ---------- */
.alert-modern {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .8rem 1rem;
    font-size: .88rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1.25rem;
}

.alert-success { background: var(--success-light); color: #15803d; border-color: #bbf0cf; }
.alert-danger { background: var(--danger-light); color: #b91c1c; border-color: #f7c6c6; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border-color: #d9dbfb; }

.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.5rem;
}
