@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Reset & Base ──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f0f2f5;
    --bg2: #ffffff;
    --bg3: #f7f8fa;
    --surface: rgba(0, 0, 0, 0.04);
    --surface2: rgba(0, 0, 0, 0.07);
    --border: rgba(0, 0, 0, 0.10);
    --border2: rgba(0, 0, 0, 0.16);
    --text: #111b21;
    --text2: #54656f;
    --text3: #8696a0;
    --primary: #25d366;
    --primary2: #128c7e;
    --accent: #34b7f1;
    --accent2: #00a884;
    --danger: #e53935;
    --warning: #f59e0b;
    --green: #25d366;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.10);
    --shadow2: 0 8px 40px rgba(0, 0, 0, 0.14);
    --glow: 0 0 30px rgba(37, 211, 102, 0.20);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg2);
}

::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width .3s;
}

.sidebar-logo {
    padding: 24px 20px 20px;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: var(--glow);
}

.sidebar-logo span.brand {
    color: var(--text);
}

.sidebar-logo span.brand b {
    color: var(--primary2);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text2);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all .2s;
    margin-bottom: 2px;
}

.sidebar-nav a:hover {
    background: var(--surface2);
    color: var(--text);
}

.sidebar-nav a.active {
    background: linear-gradient(90deg, rgba(108, 99, 255, 0.2), rgba(108, 99, 255, 0.05));
    color: var(--primary2);
    border-left: 3px solid var(--primary);
    padding-left: 9px;
}

.sidebar-nav a .icon {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
}

.nav-section {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text3);
    padding: 12px 12px 6px;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.72rem;
    color: var(--text3);
}

.btn-logout {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text3);
    transition: color .2s;
    padding: 4px;
}

.btn-logout:hover {
    color: var(--danger);
}

/* ── Main Content ──────────────────────────────────────── */
.main {
    margin-left: 240px;
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 90;
    background: rgba(255, 255, 255, 0.90);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.topbar-sub {
    font-size: 0.8rem;
    color: var(--text3);
    margin-top: 1px;
}

.page-content {
    padding: 28px;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color .2s, box-shadow .2s;
}

.card:hover {
    border-color: var(--border2);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text2);
}

/* ── KPI Cards ─────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: all .3s;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
}

.kpi-card.kpi-purple::before {
    background: linear-gradient(90deg, var(--primary), transparent);
}

.kpi-card.kpi-green::before {
    background: linear-gradient(90deg, var(--accent), transparent);
}

.kpi-card.kpi-blue::before {
    background: linear-gradient(90deg, #4dabf7, transparent);
}

.kpi-card.kpi-orange::before {
    background: linear-gradient(90deg, var(--warning), transparent);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--border2);
}

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.kpi-purple .kpi-icon {
    background: rgba(108, 99, 255, 0.15);
    color: var(--primary2);
}

.kpi-green .kpi-icon {
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
}

.kpi-blue .kpi-icon {
    background: rgba(77, 171, 247, 0.15);
    color: #4dabf7;
}

.kpi-orange .kpi-icon {
    background: rgba(255, 179, 71, 0.15);
    color: var(--warning);
}

.kpi-value {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -1px;
}

.kpi-label {
    font-size: 0.78rem;
    color: var(--text2);
    margin-top: 2px;
}

.kpi-change {
    font-size: 0.75rem;
    color: var(--accent);
    margin-top: 6px;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.45);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), #00b894);
    color: #fff;
    font-weight: 700;
}

.btn-accent:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 212, 170, 0.3);
}

.btn-ghost {
    background: var(--surface);
    color: var(--text2);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--border2);
}

.btn-danger {
    background: rgba(255, 77, 106, 0.15);
    color: var(--danger);
    border: 1px solid rgba(255, 77, 106, 0.25);
}

.btn-danger:hover {
    background: rgba(255, 77, 106, 0.25);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 0.95rem;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none !important;
}

/* ── Forms ──────────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 0.88rem;
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}

.form-control::placeholder {
    color: var(--text3);
}

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b95a8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

textarea.form-control {
    resize: vertical;
    min-height: 90px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ── Table ──────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: var(--bg3);
    padding: 11px 14px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text3);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 13px 14px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--text2);
    vertical-align: middle;
}

tbody tr:hover td {
    background: var(--surface);
    color: var(--text);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ── Badges ─────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-green {
    background: rgba(46, 204, 113, 0.15);
    color: var(--green);
}

.badge-purple {
    background: rgba(108, 99, 255, 0.15);
    color: var(--primary2);
}

.badge-red {
    background: rgba(255, 77, 106, 0.15);
    color: var(--danger);
}

.badge-yellow {
    background: rgba(255, 179, 71, 0.15);
    color: var(--warning);
}

.badge-gray {
    background: var(--surface2);
    color: var(--text3);
}

.badge-teal {
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn .2s;
}

.modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow2);
    animation: slideUp .3s cubic-bezier(.4, 0, .2, 1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text3);
    cursor: pointer;
    font-size: 1.2rem;
    transition: color .2s;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Search bar ─────────────────────────────────────────── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    transition: border-color .2s;
}

.search-bar:focus-within {
    border-color: var(--primary);
}

.search-bar input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 0.88rem;
    flex: 1;
}

.search-bar .icon {
    color: var(--text3);
    font-size: 0.9rem;
}

/* ── Toast ──────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    min-width: 280px;
    animation: slideInRight .3s cubic-bezier(.4, 0, .2, 1);
    font-size: 0.85rem;
}

.toast.success {
    border-left: 3px solid var(--accent);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.info {
    border-left: 3px solid var(--primary);
}

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text3);
}

.empty-state .icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--text2);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 0.85rem;
}

/* ── Animations ─────────────────────────────────────────── */
@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0
    }

    to {
        transform: translateY(0);
        opacity: 1
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(40px);
        opacity: 0
    }

    to {
        transform: translateX(0);
        opacity: 1
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

.spin {
    animation: spin 1s linear infinite;
}

/* ── Loading ────────────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    animation: spin .8s linear infinite;
}

/* ── Utility ────────────────────────────────────────────── */
.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 8px;
}

.gap-3 {
    gap: 12px;
}

.gap-4 {
    gap: 16px;
}

.text-sm {
    font-size: 0.82rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-muted {
    color: var(--text3);
}

.text-primary {
    color: var(--primary2);
}

.text-accent {
    color: var(--accent);
}

.text-danger {
    color: var(--danger);
}

.fw-600 {
    font-weight: 600;
}

.fw-700 {
    font-weight: 700;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-3 {
    margin-bottom: 12px;
}

.mb-4 {
    margin-bottom: 16px;
}

.mb-6 {
    margin-bottom: 24px;
}

.mt-3 {
    margin-top: 12px;
}

.w-full {
    width: 100%;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .sidebar-logo span.brand,
    .sidebar-nav a span:not(.icon),
    .nav-section,
    .user-details {
        display: none;
    }

    .main {
        margin-left: 60px;
    }

    .sidebar-nav a {
        justify-content: center;
        padding: 12px;
    }

    .form-row,
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }

    .page-content {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
}