:root {
    --purple: #6C63C7;
    --orange: #E8974A;
    --orange-dark: #DE8636;
    --navy: #262A3D;
    --navy-light: #2E3348;
    --bg: #F3F4F8;
    --card-bg: #FFFFFF;
    --text-main: #3A3F51;
    --text-muted: #9098AC;
    --green: #6DBE45;
    --blue: #4E6CF0;
    --red: #E85C6B;
    --border: #EDEEF3;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text-main);
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }

.app {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--navy);
    padding: 16px 0;
    transition: margin-left .25s ease;
}

.sidebar-nav .nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 24px;
    color: #A9AFC3;
    font-size: 14.5px;
    font-weight: 500;
}

.nav-link:hover,
.nav-item.active .nav-link {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.nav-item.active .nav-link { border-left: 3px solid var(--purple); }

.nav-link svg { width: 18px; height: 18px; }

.nav-link .chevron {
    margin-left: auto;
    width: 16px;
    height: 16px;
    transition: transform .2s ease;
}

.nav-item.open .nav-link .chevron { transform: rotate(180deg); }

.submenu {
    display: none;
    background: rgba(0, 0, 0, 0.15);
}

.nav-item.open .submenu { display: block; }

.submenu li a {
    display: block;
    padding: 10px 24px 10px 54px;
    font-size: 13.5px;
    color: #8890A6;
}

.submenu li a:hover { color: #fff; }

/* ---------- Topbar ---------- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 24px;
    height: 68px;
    background: linear-gradient(90deg, var(--orange), var(--orange-dark));
    color: #fff;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    font-weight: 800;
    font-size: 20px;
    letter-spacing: .5px;
}

.topbar-center {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
}

.search-form {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 22px;
    padding: 8px 18px;
    max-width: 320px;
    width: 100%;
}

.search-form input {
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    font-size: 14px;
    width: 100%;
}

.search-form input::placeholder { color: rgba(255,255,255,.85); }
.search-form svg { width: 18px; height: 18px; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: #fff;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
}

.icon-btn svg { width: 20px; height: 20px; }

.icon-btn.has-badge .badge {
    position: absolute;
    top: 0;
    right: 0;
    background: #3F4B8C;
    color: #fff;
    font-size: 10px;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 50%;
}

.flag-btn img { width: 22px; border-radius: 3px; }

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    position: relative;
    cursor: pointer;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(30, 34, 60, .15);
    min-width: 140px;
    overflow: hidden;
    z-index: 50;
}

.user-menu.open .user-dropdown { display: block; }

.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-main);
}

.user-dropdown a:hover { background: var(--bg); }
.user-dropdown svg { width: 16px; height: 16px; }

.user-menu .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-menu svg { width: 16px; height: 16px; }

/* ---------- Content ---------- */
.content {
    padding: 28px;
}

.page-title {
    color: var(--purple);
    font-weight: 700;
    font-size: 26px;
    margin: 0 0 24px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 2px 10px rgba(30, 34, 60, .04);
}

.stat-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid currentColor;
}

.stat-icon svg { width: 20px; height: 20px; }

.icon-green  { color: var(--green); }
.icon-orange { color: var(--orange); }
.icon-blue   { color: var(--blue); }
.icon-red    { color: var(--red); }

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    text-align: right;
}

.stat-text { flex: 1; text-align: right; }

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
}

.stat-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
}

.stat-footnote { color: var(--text-muted); }

.stat-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    letter-spacing: .3px;
}

.stat-trend svg { width: 13px; height: 13px; }

.trend-up { color: var(--green); }
.trend-down { color: var(--orange); }
.trend-refresh { color: var(--red); }

.content-grid {
    display: grid;
    grid-template-columns: 2.2fr 1fr;
    gap: 20px;
    align-items: start;
}

.panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: 0 2px 10px rgba(30, 34, 60, .04);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: 340px;
}

.chart-wrap canvas {
    /* Chart.js sizes the canvas via JS based on this wrapper;
       without a fixed-height, position:relative wrapper the
       canvas and its container can grow each other indefinitely. */
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

.panel-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 18px;
    color: var(--text-main);
}

.settings-btn {
    color: #fff;
    background: var(--purple);
    border-radius: 10px;
    width: 40px;
    height: 40px;
}

.client-list { margin-top: 8px; }

.client-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.client-item:last-child { border-bottom: none; }

.client-item .avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
}

.client-name { font-weight: 600; font-size: 14.5px; }
.client-time { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
    .sidebar {
        position: fixed;
        z-index: 40;
        height: 100vh;
        margin-left: -240px;
    }
    .sidebar.open { margin-left: 0; }
    .search-form { display: none; }
    .stats-grid { grid-template-columns: 1fr; }
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: var(--purple);
    color: #fff;
}

.btn-primary:hover { filter: brightness(1.05); }

/* ---------- Page header row (title + action button) ---------- */
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header-row .page-title { margin: 0; }

/* ---------- Flash messages ---------- */
.flash {
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 14px;
    margin-bottom: 18px;
}

.flash-success {
    background: rgba(109, 190, 69, .1);
    color: #4C9A2A;
    border: 1px solid rgba(109, 190, 69, .25);
}

.flash-error {
    background: rgba(232, 92, 107, .1);
    color: var(--red);
    border: 1px solid rgba(232, 92, 107, .25);
}

/* ---------- Users table ---------- */
.empty-state {
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 30px 0;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.users-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: .3px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.users-table td {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.users-table tr:last-child td { border-bottom: none; }

.table-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.role-badge {
    display: inline-block;
    background: rgba(108, 99, 199, .1);
    color: var(--purple);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}


.red-badge {
    display: inline-block;
    background: brown;
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.text-muted { color: var(--text-muted); }

.actions-col {
    white-space: nowrap;
    text-align: right;
}

.table-btn {
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.table-btn:hover { background: var(--bg); color: var(--text-main); }
.table-btn.delete-btn:hover { color: var(--red); }

.inline-form { display: inline; }

/* ---------- Add/Edit modal ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 35, .5);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 100%;
    max-width: 420px;
    padding: 26px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.modal-header .icon-btn { color: var(--text-muted); }

.modal form {
    display: flex;
    flex-direction: column;
}

select.auth-input {
    background: #fff;
    appearance: auto;
}
