:root {
    --brand-500: #5b4ef4;
    --brand-600: #4a3df0;
    --brand-700: #3b2fd0;
    --brand-100: #eae8fe;
    --brand-50: #f5f4ff;
    --accent: #22c55e;
    --ink: #1f2430;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f3f4fb;
    --card-radius: 1rem;
    --shadow-sm: 0 1px 2px rgba(31, 36, 48, 0.05);
    --shadow-md: 0 6px 20px rgba(31, 36, 48, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 0.95rem;
}

a { text-decoration: none; }

/* ---------- Sidebar ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex: 0 0 250px;
    background: linear-gradient(180deg, #2a2550 0%, #1e1b3f 100%);
    color: #cfcbea;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: transform 0.2s ease;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.25rem 1.25rem 1rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
}

.sidebar .brand .logo {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-500), #a855f7);
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 1.25rem;
}

.sidebar .nav-group {
    padding: 0 0.75rem 0.25rem;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8b86b5;
    font-weight: 600;
    margin-top: 0.5rem;
}

.sidebar nav { flex: 1; overflow-y: auto; padding-bottom: 1rem; }

.tenant-switch { padding: 0.5rem 0.85rem 0.9rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.tenant-switch .ts-label {
    display: block; font-size: 0.7rem; letter-spacing: 0.08em;
    text-transform: uppercase; color: #8b86b5; font-weight: 600; margin-bottom: 0.35rem;
}
.tenant-switch .ts-select {
    background: #1b1f36; color: #e7e5f5; border: 1px solid rgba(255,255,255,0.12);
}


.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.85rem;
    margin: 0 0.4rem 0.15rem;
    border-radius: 0.6rem;
    color: #cfcbea;
    font-size: 0.9rem;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link i { font-size: 1.1rem; width: 18px; text-align: center; color: #8f8ab8; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidebar .nav-link.active { background: var(--brand-500); color: #fff; }
.sidebar .nav-link.active i { color: #fff; }

.sidebar .logout-form { padding: 0.75rem; border-top: 1px solid rgba(255, 255, 255, 0.08); }

.sidebar .logout-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.85rem;
    border: 0;
    border-radius: 0.6rem;
    background: rgba(255, 255, 255, 0.06);
    color: #ef87a7;
    cursor: pointer;
    font-size: 0.9rem;
}
.sidebar .logout-btn:hover { background: rgba(239, 135, 167, 0.15); color: #ff9fbe; }

/* ---------- Main / Topbar ---------- */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    padding: 0.65rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar .menu-btn {
    border: 0;
    background: transparent;
    font-size: 1.4rem;
    color: var(--muted);
    display: none;
    cursor: pointer;
}

.topbar .crumbs { font-size: 0.85rem; color: var(--muted); }
.topbar .crumbs strong { color: var(--ink); }
.topbar .spacer { flex: 1; }

.topbar .user-chip { display: flex; align-items: center; gap: 0.6rem; }

.topbar .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-500), #a855f7);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.9rem;
}
.topbar .user-chip .u-name { font-weight: 600; font-size: 0.9rem; line-height: 1.1; }
.topbar .user-chip .u-sub { font-size: 0.75rem; color: var(--muted); }

.content { padding: 1.5rem; }

/* ---------- Cards & stat tiles ---------- */
.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-md);
}

.stat-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-md);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    flex: 0 0 auto;
}
.stat-card .stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
a.stat-link { text-decoration: none; color: inherit; display: flex; }
a.stat-link:hover { box-shadow: var(--shadow-lg, 0 8px 24px rgba(15, 23, 42, 0.12)); transform: translateY(-2px); }
a.stat-link:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

.stat-icon.brand { background: var(--brand-100); color: var(--brand-600); }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.amber { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.cyan { background: #cffafe; color: #0891b2; }
.stat-icon.indigo { background: #e0e7ff; color: #4f46e5; }

/* ---------- Buttons ---------- */
.btn { border-radius: 0.6rem; font-weight: 500; }
.btn-primary { background: var(--brand-500); border-color: var(--brand-500); }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }

/* ---------- Tables ---------- */
.table thead th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom-width: 1px;
}
.table td { vertical-align: middle; }

/* ---------- Forms ---------- */
.form-control { border-radius: 0.6rem; border-color: var(--line); }
.form-control:focus { border-color: var(--brand-500); box-shadow: 0 0 0 0.2rem rgba(91, 78, 244, 0.15); }

/* ---------- Page header ---------- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.page-head h1 { font-size: 1.4rem; font-weight: 700; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 0.85rem; }

/* ---------- Login page ---------- */
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.login-side {
    background: linear-gradient(150deg, #2a2550 0%, #4a3df0 55%, #a855f7 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}
.login-side::after {
    content: "";
    position: absolute;
    width: 420px;
    height: 420px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    right: -140px;
    bottom: -140px;
}
.login-side .brand-login {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-weight: 700;
    font-size: 1.4rem;
    margin-bottom: 2rem;
}
.login-side .brand-login .logo {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    display: grid;
    place-items: center;
    font-size: 1.4rem;
}
.login-side h2 { font-size: 2rem; font-weight: 700; }
.login-side p { color: #d7d3ff; font-size: 1rem; max-width: 34ch; }

.login-form-wrap { display: grid; place-items: center; padding: 2rem; }
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 1.25rem;
    box-shadow: var(--shadow-md);
    padding: 2.25rem;
}
.login-card h3 { font-weight: 700; font-size: 1.4rem; }
.login-card .lead { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

/* ---------- Responsive ---------- */
@media (max-width: 992px) {
    .sidebar { position: fixed; z-index: 40; transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .topbar .menu-btn { display: inline-block; }
    .login-shell { grid-template-columns: 1fr; }
    .login-side { display: none; }
}

.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 30;
    display: none;
}
.sidebar-overlay.show { display: block; }

/* ---------- Print (prescription) ---------- */
@media print {
    .sidebar, .topbar, .app-shell > main .nav-tabs { display: none !important; }
    .main { margin: 0 !important; padding: 0 !important; }
    body { background: #fff !important; }
    .card { border: 0; box-shadow: none !important; }
}


